Skip to content

Commit

Permalink
dropped support for Internet Explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmoore committed Feb 11, 2023
1 parent 31543e1 commit 1b9c109
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 154 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

##### v.6.0.0 - 2023-02-10
* Dropped support for Internet Explorer

##### v.5.0.2 - 2022-11-20
* Avoid issue caused by using 'smooth' scroll-behavior

Expand Down
2 changes: 1 addition & 1 deletion dist/autosize.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 25 additions & 78 deletions dist/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,16 @@
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.autosize = factory());
}(this, (function () {
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 createEvent(name) {
var evt = document.createEvent('Event');
evt.initEvent(name, true, false);
return evt;
};
}
var assignedElements = new Map();

function assign(ta) {
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return;
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || assignedElements.has(ta)) return;
var heightOffset = null;
var clientWidth = null;
var cachedHeight = null;

function init() {
var style = window.getComputedStyle(ta, null);
var style = window.getComputedStyle(ta);

if (style.resize === 'vertical') {
ta.style.resize = 'none';
Expand Down Expand Up @@ -90,12 +48,11 @@
ta.style.overflowY = value;
}

function bookmarkOverflows(el) {
function cacheScrollTops(el) {
var arr = [];

while (el && el.parentNode && el.parentNode instanceof Element) {
if (el.parentNode.scrollTop) {
el.parentNode.style.scrollBehavior = 'auto';
arr.push([el.parentNode, el.parentNode.scrollTop]);
}

Expand All @@ -106,6 +63,7 @@
return arr.forEach(function (_ref) {
var node = _ref[0],
scrollTop = _ref[1];
node.style.scrollBehavior = 'auto';
node.scrollTop = scrollTop;
node.style.scrollBehavior = null;
});
Expand All @@ -116,49 +74,45 @@
if (ta.scrollHeight === 0) {
// If the scrollHeight is 0, then the element probably has display:none or is detached from the DOM.
return;
} // remove smooth scroll & prevent scroll-position jumping by restoring original scroll position
} // ensure the scrollTop values of parent elements are not modified as a consequence of calculating the textarea height


var restoreScrollTops = cacheScrollTops(ta);
ta.style.height = ''; // this is necessary for getting an accurate scrollHeight on the next line

var restoreOverflows = bookmarkOverflows(ta);
ta.style.height = '';
ta.style.height = ta.scrollHeight + heightOffset + 'px'; // used to check if an update is actually necessary on window.resize

clientWidth = ta.clientWidth;
restoreOverflows();
restoreScrollTops();
}

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

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
}
ta.dispatchEvent(new Event('autosize:resized', {
bubbles: true
}));
}
}

Expand All @@ -177,7 +131,7 @@
Object.keys(style).forEach(function (key) {
ta.style[key] = style[key];
});
map["delete"](ta);
assignedElements["delete"](ta);
}.bind(ta, {
height: ta.style.height,
resize: ta.style.resize,
Expand All @@ -186,45 +140,38 @@
wordWrap: ta.style.wordWrap
});

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, false);
}

ta.addEventListener('autosize:destroy', destroy, false);
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';
map.set(ta, {
assignedElements.set(ta, {
destroy: destroy,
update: update
});
init();
}

function destroy(ta) {
var methods = map.get(ta);
var methods = assignedElements.get(ta);

if (methods) {
methods.destroy();
}
}

function update(ta) {
var methods = map.get(ta);
var methods = assignedElements.get(ta);

if (methods) {
methods.update();
}
}

var autosize = null; // Do nothing in Node.js environment and IE8 (or lower)
var autosize = null; // Do nothing in Node.js environment

if (typeof window === 'undefined' || typeof window.getComputedStyle !== 'function') {
if (typeof window === 'undefined') {
autosize = function autosize(el) {
return el;
};
Expand Down
2 changes: 1 addition & 1 deletion dist/autosize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "autosize",
"description": "Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.",
"version": "5.0.2",
"version": "6.0.0",
"keywords": [
"textarea",
"form",
Expand Down
6 changes: 0 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ Full documentation and a demo can be found at [jacklmoore.com/autosize](http://j
npm install autosize
```

#### Browser compatibility

Chrome | Firefox | IE | Safari | iOS Safari | Android
------ | --------|----|--------|------------|---------
yes | yes | 9 | yes | yes | 4

#### Usage

The autosize function accepts a single textarea element, or an array or array-like object (such as a NodeList or jQuery collection) of textarea elements.
Expand Down
Loading

0 comments on commit 1b9c109

Please sign in to comment.