Skip to content

Commit

Permalink
Update autosize, which should fix stack overflow error (signalapp#1560)
Browse files Browse the repository at this point in the history
* Update to the latest version of autosize.js

* gitignore: Restrict 'dist' matches to the root dist folder

The global search for 'dist' caused problems when updateing bower
components.

* A couple minor version updates: ByteBuffer, filesize, intlTel

moment-with-localse, ProtoBuf
  • Loading branch information
scottnonnenberg authored Oct 13, 2017
1 parent 3dc3667 commit fb77015
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node_modules
build/curve25519_compiled.js
build/icons/*
stylesheets/*.css.map
dist
/dist
.DS_Store
config/local.json
config/local-*.json
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"intl-tel-input": "~4.0.1",
"blueimp-load-image": "~1.13.0",
"blueimp-canvas-to-blob": "~2.1.1",
"autosize": "~3.0.6",
"autosize": "~4.0.0",
"webaudiorecorder": "https://github.com/higuma/web-audio-recorder-js.git",
"mp3lameencoder": "https://github.com/higuma/mp3-lame-encoder-js.git",
"filesize": "https://github.com/avoidwork/filesize.js.git"
Expand Down
199 changes: 140 additions & 59 deletions components/autosize/dist/autosize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Autosize 3.0.5
Autosize 4.0.0
license: MIT
http://www.jacklmoore.com/autosize
*/
Expand All @@ -18,18 +18,53 @@
})(this, function (exports, module) {
'use strict';

function assign(ta) {
var _ref = arguments[1] === undefined ? {} : arguments[1];

var _ref$setOverflowX = _ref.setOverflowX;
var setOverflowX = _ref$setOverflowX === undefined ? true : _ref$setOverflowX;
var _ref$setOverflowY = _ref.setOverflowY;
var setOverflowY = _ref$setOverflowY === undefined ? true : _ref$setOverflowY;
var map = typeof Map === "function" ? new Map() : (function () {
var keys = [];
var values = [];

return {
has: function has(key) {
return keys.indexOf(key) > -1;
},
get: function get(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) {
var index = keys.indexOf(key);
if (index > -1) {
keys.splice(index, 1);
values.splice(index, 1);
}
}
};
})();

var createEvent = function createEvent(name) {
return new Event(name, { bubbles: true });
};
try {
new Event('test');
} catch (e) {
// IE does not support `new Event()`
createEvent = function (name) {
var evt = document.createEvent('Event');
evt.initEvent(name, true, false);
return evt;
};
}

if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || ta.hasAttribute('data-autosize-on')) return;
function assign(ta) {
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return;

var heightOffset = null;
var overflowY = 'hidden';
var clientWidth = ta.clientWidth;
var cachedHeight = null;

function init() {
var style = window.getComputedStyle(ta, null);
Expand All @@ -45,6 +80,10 @@
} else {
heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
}
// Fix when a textarea is not on document body and heightOffset is Not a Number
if (isNaN(heightOffset)) {
heightOffset = 0;
}

update();
}
Expand All @@ -63,22 +102,31 @@
ta.style.width = width;
}

overflowY = value;
ta.style.overflowY = value;
}

function getParentOverflows(el) {
var arr = [];

if (setOverflowY) {
ta.style.overflowY = value;
while (el && el.parentNode && el.parentNode instanceof Element) {
if (el.parentNode.scrollTop) {
arr.push({
node: el.parentNode,
scrollTop: el.parentNode.scrollTop
});
}
el = el.parentNode;
}

update();
return arr;
}

function update() {
var startHeight = ta.style.height;
var htmlTop = document.documentElement.scrollTop;
var bodyTop = document.body.scrollTop;
function resize() {
var originalHeight = ta.style.height;
var overflows = getParentOverflows(ta);
var docTop = document.documentElement && document.documentElement.scrollTop; // Needed for Mobile IE (ticket #240)

ta.style.height = 'auto';
ta.style.height = '';

var endHeight = ta.scrollHeight + heightOffset;

Expand All @@ -90,85 +138,118 @@

ta.style.height = endHeight + 'px';

// used to check if an update is actually necessary on window.resize
clientWidth = ta.clientWidth;

// prevents scroll-position jumping
document.documentElement.scrollTop = htmlTop;
document.body.scrollTop = bodyTop;
overflows.forEach(function (el) {
el.node.scrollTop = el.scrollTop;
});

var style = window.getComputedStyle(ta, null);
if (docTop) {
document.documentElement.scrollTop = docTop;
}
}

function update() {
resize();

var styleHeight = Math.round(parseFloat(ta.style.height));
var computed = window.getComputedStyle(ta, null);

if (style.height !== ta.style.height) {
if (overflowY !== 'visible') {
changeOverflow('visible');
return;
// Using offsetHeight as a replacement for computed.height in IE, because IE does not account use of border-box
var actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(computed.height)) : ta.offsetHeight;

// 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 allowed.
if (actualHeight !== styleHeight) {
if (computed.overflowY === 'hidden') {
changeOverflow('scroll');
resize();
actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight;
}
} else {
if (overflowY !== 'hidden') {
// Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands.
if (computed.overflowY !== 'hidden') {
changeOverflow('hidden');
return;
resize();
actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight;
}
}

if (startHeight !== ta.style.height) {
var evt = document.createEvent('Event');
evt.initEvent('autosize:resized', true, false);
ta.dispatchEvent(evt);
if (cachedHeight !== actualHeight) {
cachedHeight = actualHeight;
var evt = createEvent('autosize:resized');
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
}
}
}

var pageResize = function pageResize() {
if (ta.clientWidth !== clientWidth) {
update();
}
};

var destroy = (function (style) {
window.removeEventListener('resize', update);
ta.removeEventListener('input', update);
ta.removeEventListener('keyup', update);
ta.removeAttribute('data-autosize-on');
ta.removeEventListener('autosize:destroy', destroy);
window.removeEventListener('resize', pageResize, false);
ta.removeEventListener('input', update, false);
ta.removeEventListener('keyup', update, false);
ta.removeEventListener('autosize:destroy', destroy, false);
ta.removeEventListener('autosize:update', update, false);

Object.keys(style).forEach(function (key) {
ta.style[key] = style[key];
});

map['delete'](ta);
}).bind(ta, {
height: ta.style.height,
resize: ta.style.resize,
overflowY: ta.style.overflowY,
overflowX: ta.style.overflowX,
wordWrap: ta.style.wordWrap });
wordWrap: ta.style.wordWrap
});

ta.addEventListener('autosize:destroy', destroy);
ta.addEventListener('autosize:destroy', destroy, false);

// IE9 does not fire onpropertychange or oninput for deletions,
// so binding to onkeyup to catch most of those events.
// There is no way that I know of to detect something like 'cut' in IE9.
if ('onpropertychange' in ta && 'oninput' in ta) {
ta.addEventListener('keyup', update);
ta.addEventListener('keyup', update, false);
}

window.addEventListener('resize', update);
ta.addEventListener('input', update);
ta.addEventListener('autosize:update', update);
ta.setAttribute('data-autosize-on', true);
window.addEventListener('resize', pageResize, false);
ta.addEventListener('input', update, false);
ta.addEventListener('autosize:update', update, false);
ta.style.overflowX = 'hidden';
ta.style.wordWrap = 'break-word';

if (setOverflowY) {
ta.style.overflowY = 'hidden';
}
if (setOverflowX) {
ta.style.overflowX = 'hidden';
ta.style.wordWrap = 'break-word';
}
map.set(ta, {
destroy: destroy,
update: update
});

init();
}

function destroy(ta) {
if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return;
var evt = document.createEvent('Event');
evt.initEvent('autosize:destroy', true, false);
ta.dispatchEvent(evt);
var methods = map.get(ta);
if (methods) {
methods.destroy();
}
}

function update(ta) {
if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return;
var evt = document.createEvent('Event');
evt.initEvent('autosize:update', true, false);
ta.dispatchEvent(evt);
var methods = map.get(ta);
if (methods) {
methods.update();
}
}

var autosize = null;
Expand Down
Loading

0 comments on commit fb77015

Please sign in to comment.