diff --git a/build.js b/build.js index 1048775..bab0cd6 100644 --- a/build.js +++ b/build.js @@ -32,7 +32,7 @@ function lint(full) { eqeqeq: true, eqnull: true, noarg: true, - predef: ['define', 'module', 'exports'] + predef: ['define', 'module', 'exports', 'Set'] }); if (jshint.errors.length) { diff --git a/changelog.md b/changelog.md index 26f3631..c6cf2a1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ ## Changelog +##### v.3.0.10 - 2015-09-10 +* Removed data attribute as a way of tracking which elements autosize has been assigned to. fixes #254, fixes #200. + ##### v.3.0.9 - 2015-09-02 * Fixed issue with assigning autosize to detached nodes. Merged #253, Fixes #234. diff --git a/dist/autosize.js b/dist/autosize.js index c0c350e..de3af2c 100644 --- a/dist/autosize.js +++ b/dist/autosize.js @@ -1,5 +1,5 @@ /*! - Autosize 3.0.9 + Autosize 3.0.10 license: MIT http://www.jacklmoore.com/autosize */ @@ -18,6 +18,21 @@ })(this, function (exports, module) { 'use strict'; + var set = Set ? new Set() : (function () { + var list = []; + + return { + has: function has(key) { + return Boolean(list.indexOf(key) > -1); + }, + add: function add(key) { + list.push(key); + }, + 'delete': function _delete(key) { + list.splice(list.indexOf(key), 1); + } }; + })(); + function assign(ta) { var _ref = arguments[1] === undefined ? {} : arguments[1]; @@ -26,7 +41,7 @@ var _ref$setOverflowY = _ref.setOverflowY; var setOverflowY = _ref$setOverflowY === undefined ? true : _ref$setOverflowY; - if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || ta.hasAttribute('data-autosize-on')) return; + if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || set.has(ta)) return; var heightOffset = null; var overflowY = 'hidden'; @@ -126,8 +141,8 @@ window.removeEventListener('resize', update); ta.removeEventListener('input', update); ta.removeEventListener('keyup', update); - ta.removeAttribute('data-autosize-on'); ta.removeEventListener('autosize:destroy', destroy); + set['delete'](ta); Object.keys(style).forEach(function (key) { ta.style[key] = style[key]; @@ -151,7 +166,7 @@ window.addEventListener('resize', update); ta.addEventListener('input', update); ta.addEventListener('autosize:update', update); - ta.setAttribute('data-autosize-on', true); + set.add(ta); if (setOverflowY) { ta.style.overflowY = 'hidden'; diff --git a/dist/autosize.min.js b/dist/autosize.min.js index 1c9a87e..7697e35 100644 --- a/dist/autosize.min.js +++ b/dist/autosize.min.js @@ -1,6 +1,6 @@ /*! - Autosize 3.0.9 + Autosize 3.0.10 license: MIT http://www.jacklmoore.com/autosize */ -!function(e,t){if("function"==typeof define&&define.amd)define(["exports","module"],t);else if("undefined"!=typeof exports&&"undefined"!=typeof module)t(exports,module);else{var o={exports:{}};t(o.exports,o),e.autosize=o.exports}}(this,function(e,t){"use strict";function o(e){function t(){var t=window.getComputedStyle(e,null);"vertical"===t.resize?e.style.resize="none":"both"===t.resize&&(e.style.resize="horizontal"),u="content-box"===t.boxSizing?-(parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)):parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth),isNaN(u)&&(u=0),i()}function o(t){var o=e.style.width;e.style.width="0px",e.offsetWidth,e.style.width=o,v=t,l&&(e.style.overflowY=t),n()}function n(){var t=window.pageYOffset,o=document.body.scrollTop,n=e.style.height;e.style.height="auto";var i=e.scrollHeight+u;return 0===e.scrollHeight?void(e.style.height=n):(e.style.height=i+"px",document.documentElement.scrollTop=t,void(document.body.scrollTop=o))}function i(){var t=e.style.height;n();var i=window.getComputedStyle(e,null);if(i.height!==e.style.height?"visible"!==v&&o("visible"):"hidden"!==v&&o("hidden"),t!==e.style.height){var r=document.createEvent("Event");r.initEvent("autosize:resized",!0,!1),e.dispatchEvent(r)}}var r=void 0===arguments[1]?{}:arguments[1],d=r.setOverflowX,s=void 0===d?!0:d,a=r.setOverflowY,l=void 0===a?!0:a;if(e&&e.nodeName&&"TEXTAREA"===e.nodeName&&!e.hasAttribute("data-autosize-on")){var u=null,v="hidden",f=function(t){window.removeEventListener("resize",i),e.removeEventListener("input",i),e.removeEventListener("keyup",i),e.removeAttribute("data-autosize-on"),e.removeEventListener("autosize:destroy",f),Object.keys(t).forEach(function(o){e.style[o]=t[o]})}.bind(e,{height:e.style.height,resize:e.style.resize,overflowY:e.style.overflowY,overflowX:e.style.overflowX,wordWrap:e.style.wordWrap});e.addEventListener("autosize:destroy",f),"onpropertychange"in e&&"oninput"in e&&e.addEventListener("keyup",i),window.addEventListener("resize",i),e.addEventListener("input",i),e.addEventListener("autosize:update",i),e.setAttribute("data-autosize-on",!0),l&&(e.style.overflowY="hidden"),s&&(e.style.overflowX="hidden",e.style.wordWrap="break-word"),t()}}function n(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName){var t=document.createEvent("Event");t.initEvent("autosize:destroy",!0,!1),e.dispatchEvent(t)}}function i(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName){var t=document.createEvent("Event");t.initEvent("autosize:update",!0,!1),e.dispatchEvent(t)}}var r=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?(r=function(e){return e},r.destroy=function(e){return e},r.update=function(e){return e}):(r=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return o(e,t)}),e},r.destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],n),e},r.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e}),t.exports=r}); \ No newline at end of file +!function(e,t){if("function"==typeof define&&define.amd)define(["exports","module"],t);else if("undefined"!=typeof exports&&"undefined"!=typeof module)t(exports,module);else{var n={exports:{}};t(n.exports,n),e.autosize=n.exports}}(this,function(e,t){"use strict";function n(e){function t(){var t=window.getComputedStyle(e,null);"vertical"===t.resize?e.style.resize="none":"both"===t.resize&&(e.style.resize="horizontal"),f="content-box"===t.boxSizing?-(parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)):parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth),isNaN(f)&&(f=0),i()}function n(t){var n=e.style.width;e.style.width="0px",e.offsetWidth,e.style.width=n,v=t,u&&(e.style.overflowY=t),o()}function o(){var t=window.pageYOffset,n=document.body.scrollTop,o=e.style.height;e.style.height="auto";var i=e.scrollHeight+f;return 0===e.scrollHeight?void(e.style.height=o):(e.style.height=i+"px",document.documentElement.scrollTop=t,void(document.body.scrollTop=n))}function i(){var t=e.style.height;o();var i=window.getComputedStyle(e,null);if(i.height!==e.style.height?"visible"!==v&&n("visible"):"hidden"!==v&&n("hidden"),t!==e.style.height){var r=document.createEvent("Event");r.initEvent("autosize:resized",!0,!1),e.dispatchEvent(r)}}var d=void 0===arguments[1]?{}:arguments[1],s=d.setOverflowX,a=void 0===s?!0:s,l=d.setOverflowY,u=void 0===l?!0:l;if(e&&e.nodeName&&"TEXTAREA"===e.nodeName&&!r.has(e)){var f=null,v="hidden",c=function(t){window.removeEventListener("resize",i),e.removeEventListener("input",i),e.removeEventListener("keyup",i),e.removeEventListener("autosize:destroy",c),r["delete"](e),Object.keys(t).forEach(function(n){e.style[n]=t[n]})}.bind(e,{height:e.style.height,resize:e.style.resize,overflowY:e.style.overflowY,overflowX:e.style.overflowX,wordWrap:e.style.wordWrap});e.addEventListener("autosize:destroy",c),"onpropertychange"in e&&"oninput"in e&&e.addEventListener("keyup",i),window.addEventListener("resize",i),e.addEventListener("input",i),e.addEventListener("autosize:update",i),r.add(e),u&&(e.style.overflowY="hidden"),a&&(e.style.overflowX="hidden",e.style.wordWrap="break-word"),t()}}function o(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName){var t=document.createEvent("Event");t.initEvent("autosize:destroy",!0,!1),e.dispatchEvent(t)}}function i(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName){var t=document.createEvent("Event");t.initEvent("autosize:update",!0,!1),e.dispatchEvent(t)}}var r=Set?new Set:function(){var e=[];return{has:function(t){return Boolean(e.indexOf(t)>-1)},add:function(t){e.push(t)},"delete":function(t){e.splice(e.indexOf(t),1)}}}(),d=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?(d=function(e){return e},d.destroy=function(e){return e},d.update=function(e){return e}):(d=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return n(e,t)}),e},d.destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],o),e},d.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e}),t.exports=d}); \ No newline at end of file diff --git a/package.json b/package.json index 0fb0ecd..29db783 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "autosize", "description": "Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.", - "version": "3.0.9", + "version": "3.0.10", "keywords": [ "textarea", "form", diff --git a/src/autosize.js b/src/autosize.js index cc2e697..e7575e1 100644 --- a/src/autosize.js +++ b/src/autosize.js @@ -1,5 +1,21 @@ +var set = Set ? new Set() : (()=>{ + const list = []; + + return { + has(key) { + return Boolean(list.indexOf(key) > -1); + }, + add(key) { + list.push(key); + }, + delete(key) { + list.splice(list.indexOf(key), 1); + }, + } +})(); + function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) { - if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || ta.hasAttribute('data-autosize-on')) return; + if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || set.has(ta)) return; let heightOffset = null; let overflowY = 'hidden'; @@ -99,8 +115,8 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) { window.removeEventListener('resize', update); ta.removeEventListener('input', update); ta.removeEventListener('keyup', update); - ta.removeAttribute('data-autosize-on'); ta.removeEventListener('autosize:destroy', destroy); + set.delete(ta); Object.keys(style).forEach(key => { ta.style[key] = style[key]; @@ -125,7 +141,7 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) { window.addEventListener('resize', update); ta.addEventListener('input', update); ta.addEventListener('autosize:update', update); - ta.setAttribute('data-autosize-on', true); + set.add(ta); if (setOverflowY) { ta.style.overflowY = 'hidden';