Bump autosize.js

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-04-03 13:40:34 +02:00
parent 455542d306
commit 497fe1682f
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 62 additions and 35 deletions

View File

@ -26,15 +26,14 @@
"amd", "amd",
"node" "node"
], ],
"version": "3.0.17", "version": "3.0.20",
"_release": "3.0.17", "_release": "3.0.20",
"_resolution": { "_resolution": {
"type": "version", "type": "version",
"tag": "3.0.17", "tag": "3.0.20",
"commit": "144040e4f545fbea9b304706a5200eba9961ee3f" "commit": "2277ca66ae8e466c5159faf81069b94575db87aa"
}, },
"_source": "https://github.com/jackmoore/autosize.git", "_source": "https://github.com/jackmoore/autosize.git",
"_target": "^3.0.17", "_target": "^3.0.17",
"_originalSource": "autosize", "_originalSource": "autosize"
"_direct": true
} }

View File

@ -1,5 +1,5 @@
/*! /*!
Autosize 3.0.17 Autosize 3.0.20
license: MIT license: MIT
http://www.jacklmoore.com/autosize http://www.jacklmoore.com/autosize
*/ */
@ -18,23 +18,35 @@
})(this, function (exports, module) { })(this, function (exports, module) {
'use strict'; 'use strict';
var set = typeof Set === 'function' ? new Set() : (function () { var map = typeof Map === "function" ? new Map() : (function () {
var list = []; var keys = [];
var values = [];
return { return {
has: function has(key) { has: function has(key) {
return Boolean(list.indexOf(key) > -1); return keys.indexOf(key) > -1;
}, },
add: function add(key) { get: function get(key) {
list.push(key); return values[keys.indexOf(key)];
},
set: function set(key, value) {
if (keys.indexOf(key) === -1) {
keys.push(key);
values.push(value);
}
}, },
'delete': function _delete(key) { 'delete': function _delete(key) {
list.splice(list.indexOf(key), 1); var index = keys.indexOf(key);
} }; if (index > -1) {
keys.splice(index, 1);
values.splice(index, 1);
}
}
};
})(); })();
var createEvent = function createEvent(name) { var createEvent = function createEvent(name) {
return new Event(name); return new Event(name, { bubbles: true });
}; };
try { try {
new Event('test'); new Event('test');
@ -48,7 +60,7 @@
} }
function assign(ta) { function assign(ta) {
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || set.has(ta)) return; if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return;
var heightOffset = null; var heightOffset = null;
var clientWidth = ta.clientWidth; var clientWidth = ta.clientWidth;
@ -91,8 +103,6 @@
} }
ta.style.overflowY = value; ta.style.overflowY = value;
resize();
} }
function getParentOverflows(el) { function getParentOverflows(el) {
@ -102,7 +112,8 @@
if (el.parentNode.scrollTop) { if (el.parentNode.scrollTop) {
arr.push({ arr.push({
node: el.parentNode, node: el.parentNode,
scrollTop: el.parentNode.scrollTop }); scrollTop: el.parentNode.scrollTop
});
} }
el = el.parentNode; el = el.parentNode;
} }
@ -143,27 +154,36 @@
function update() { function update() {
resize(); resize();
var computed = window.getComputedStyle(ta, null);
var computedHeight = Math.round(parseFloat(computed.height));
var styleHeight = Math.round(parseFloat(ta.style.height)); var styleHeight = Math.round(parseFloat(ta.style.height));
var computed = window.getComputedStyle(ta, null);
var actualHeight = Math.round(parseFloat(computed.height));
// The computed height not matching the height set via resize indicates that // The actual height not matching the style height (set via the resize method) indicates that
// the max-height has been exceeded, in which case the overflow should be set to visible. // the max-height has been exceeded, in which case the overflow should be set to visible.
if (computedHeight !== styleHeight) { if (actualHeight !== styleHeight) {
if (computed.overflowY !== 'visible') { if (computed.overflowY !== 'visible') {
changeOverflow('visible'); changeOverflow('visible');
resize();
actualHeight = Math.round(parseFloat(window.getComputedStyle(ta, null).height));
} }
} else { } else {
// Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands. // Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands.
if (computed.overflowY !== 'hidden') { if (computed.overflowY !== 'hidden') {
changeOverflow('hidden'); changeOverflow('hidden');
resize();
actualHeight = Math.round(parseFloat(window.getComputedStyle(ta, null).height));
} }
} }
if (cachedHeight !== computedHeight) { if (cachedHeight !== actualHeight) {
cachedHeight = computedHeight; cachedHeight = actualHeight;
var evt = createEvent('autosize:resized'); var evt = createEvent('autosize:resized');
ta.dispatchEvent(evt); try {
ta.dispatchEvent(evt);
} catch (err) {
// Firefox will throw an error on dispatchEvent for a detached element
// https://bugzilla.mozilla.org/show_bug.cgi?id=889376
}
} }
} }
@ -179,17 +199,19 @@
ta.removeEventListener('keyup', update, false); ta.removeEventListener('keyup', update, false);
ta.removeEventListener('autosize:destroy', destroy, false); ta.removeEventListener('autosize:destroy', destroy, false);
ta.removeEventListener('autosize:update', update, false); ta.removeEventListener('autosize:update', update, false);
set['delete'](ta);
Object.keys(style).forEach(function (key) { Object.keys(style).forEach(function (key) {
ta.style[key] = style[key]; ta.style[key] = style[key];
}); });
map['delete'](ta);
}).bind(ta, { }).bind(ta, {
height: ta.style.height, height: ta.style.height,
resize: ta.style.resize, resize: ta.style.resize,
overflowY: ta.style.overflowY, overflowY: ta.style.overflowY,
overflowX: ta.style.overflowX, overflowX: ta.style.overflowX,
wordWrap: ta.style.wordWrap }); wordWrap: ta.style.wordWrap
});
ta.addEventListener('autosize:destroy', destroy, false); ta.addEventListener('autosize:destroy', destroy, false);
@ -203,23 +225,29 @@
window.addEventListener('resize', pageResize, false); window.addEventListener('resize', pageResize, false);
ta.addEventListener('input', update, false); ta.addEventListener('input', update, false);
ta.addEventListener('autosize:update', update, false); ta.addEventListener('autosize:update', update, false);
set.add(ta);
ta.style.overflowX = 'hidden'; ta.style.overflowX = 'hidden';
ta.style.wordWrap = 'break-word'; ta.style.wordWrap = 'break-word';
map.set(ta, {
destroy: destroy,
update: update
});
init(); init();
} }
function destroy(ta) { function destroy(ta) {
if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; var methods = map.get(ta);
var evt = createEvent('autosize:destroy'); if (methods) {
ta.dispatchEvent(evt); methods.destroy();
}
} }
function update(ta) { function update(ta) {
if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; var methods = map.get(ta);
var evt = createEvent('autosize:update'); if (methods) {
ta.dispatchEvent(evt); methods.update();
}
} }
var autosize = null; var autosize = null;