Skip to content

Commit

Permalink
Fixes some situations where element is 'offscreen'
Browse files Browse the repository at this point in the history
  • Loading branch information
neilb committed Jan 8, 2014
1 parent c7e48eb commit fd428ff
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions jquery.autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@
$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseInt(style[val],10);
});

mirror.style.width = width + 'px';
}
else {
if (!style || width == 0) {
// window.getComputedStyle, getBoundingClientRect returning a width are unsupported and unneeded in IE8 and lower.
mirror.style.width = Math.max($ta.width(), 0) + 'px';
// In some situations, if the element is offscreen, then the above approach will result in 0 width,
// but the approach below works.
mirror.style.width = Math.max($ta.width(), 0);
}
mirror.style.width = width + 'px';
}

function initMirror() {
Expand Down Expand Up @@ -247,4 +248,4 @@
adjust();
});
};
}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto
}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto

0 comments on commit fd428ff

Please sign in to comment.