Skip to content

Commit

Permalink
Used newer Event constructor when available. Fixes jackmoore#280.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmoore committed Jan 26, 2016
1 parent e3534db commit 1e94f8a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 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.3.0.15 - 2016-1-26
* Used newer Event constructor, when available. Fixes #280.

##### v.3.0.14 - 2015-11-11
* Fixed memory leak on destroy. Merged #271, fixes #270.
* Fixed bug in old versions of Firefox (1-5), fixes #246.
Expand Down
25 changes: 18 additions & 7 deletions dist/autosize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Autosize 3.0.14
Autosize 3.0.15
license: MIT
http://www.jacklmoore.com/autosize
*/
Expand Down Expand Up @@ -33,6 +33,20 @@
} };
})();

var createEvent = function createEvent(name) {
return new Event(name);
};
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;
};
}

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

Expand Down Expand Up @@ -137,8 +151,7 @@
}

if (startHeight !== ta.style.height) {
var evt = document.createEvent('Event');
evt.initEvent('autosize:resized', true, false);
var evt = createEvent('autosize:resized');
ta.dispatchEvent(evt);
}
}
Expand Down Expand Up @@ -191,15 +204,13 @@

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

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

Expand Down
4 changes: 2 additions & 2 deletions 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": "3.0.14",
"version": "3.0.15",
"keywords": [
"textarea",
"form",
Expand Down
21 changes: 15 additions & 6 deletions src/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ const set = (typeof Set === "function") ? new Set() : (function () {
}
})();

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

function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) {
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || set.has(ta)) return;

Expand Down Expand Up @@ -111,8 +123,7 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) {
}

if (startHeight !== ta.style.height) {
const evt = document.createEvent('Event');
evt.initEvent('autosize:resized', true, false);
const evt = createEvent('autosize:resized');
ta.dispatchEvent(evt);
}
}
Expand Down Expand Up @@ -166,15 +177,13 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) {

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

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

Expand Down

0 comments on commit 1e94f8a

Please sign in to comment.