summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Moore <hello@jacklmoore.com>2015-09-26 17:52:27 -0400
committerJack Moore <hello@jacklmoore.com>2015-09-26 17:52:27 -0400
commit7b64e33d97d76722b328ec1a9c08d86249479312 (patch)
treebeac0fda369c88bded9d42441c82d412df180240
parentfb23c56895829c604a41a17d2c2cdabe5bbe458f (diff)
downloadautosize-7b64e33d97d76722b328ec1a9c08d86249479312.zip
autosize-7b64e33d97d76722b328ec1a9c08d86249479312.tar.gz
autosize-7b64e33d97d76722b328ec1a9c08d86249479312.tar.bz2
check the width of the textarea element on window.resize, rather than document.
-rw-r--r--src/autosize.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/autosize.js b/src/autosize.js
index 65c5abe..41ce6db 100644
--- a/src/autosize.js
+++ b/src/autosize.js
@@ -19,6 +19,7 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) {
let heightOffset = null;
let overflowY = 'hidden';
+ let clientWidth = ta.clientWidth;
function init() {
const style = window.getComputedStyle(ta, null);
@@ -82,6 +83,9 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) {
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;
@@ -89,7 +93,7 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) {
function update() {
const startHeight = ta.style.height;
-
+
resize();
const style = window.getComputedStyle(ta, null);
@@ -110,14 +114,12 @@ function assign(ta, {setOverflowX = true, setOverflowY = true} = {}) {
ta.dispatchEvent(evt);
}
}
-
- var lastPageWidth = document.documentElement.clientWidth;
- function pageResize() {
- if (document.documentElement.clientWidth != lastPageWidth) {
- lastPageWidth = document.documentElement.clientWidth;
+
+ const pageResize = () => {
+ if (ta.clientWidth !== clientWidth) {
update();
}
- }
+ };
const destroy = style => {
window.removeEventListener('resize', pageResize);