vendor/assets/javascripts/jquery.autosize.js in autosize-rails-1.18.8 vs vendor/assets/javascripts/jquery.autosize.js in autosize-rails-1.18.15

- old
+ new

@@ -1,10 +1,9 @@ /*! - Autosize v1.18.8 - 2014-05-20 - Automatically adjust textarea height based on user input. - (c) 2014 Jack Moore - http://www.jacklmoore.com/autosize - license: http://www.opensource.org/licenses/mit-license.php + Autosize 1.18.15 + license: MIT + http://www.jacklmoore.com/autosize */ (function ($) { var defaults = { className: 'autosizejs', @@ -25,11 +24,12 @@ 'fontWeight', 'fontStyle', 'letterSpacing', 'textTransform', 'wordSpacing', - 'textIndent' + 'textIndent', + 'whiteSpace' ], // to keep track which textarea is being mirrored when adjust() is called. mirrored, @@ -82,11 +82,11 @@ if ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){ boxOffset = $ta.outerHeight() - $ta.height(); } // IE8 and lower return 'auto', which parses to NaN, if no min-height is set. - minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height()); + minHeight = Math.max(parseFloat($ta.css('minHeight')) - boxOffset || 0, $ta.height()); $ta.css({ overflow: 'hidden', overflowY: 'hidden', wordWrap: 'break-word' // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width @@ -101,46 +101,46 @@ // The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value. // window.getComputedStyle, getBoundingClientRect returning a width are unsupported, but also unneeded in IE8 and lower. function setWidth() { var width; var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false; - + if (style) { width = ta.getBoundingClientRect().width; if (width === 0 || typeof width !== 'number') { - width = parseInt(style.width,10); + width = parseFloat(style.width); } $.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){ - width -= parseInt(style[val],10); + width -= parseFloat(style[val]); }); } else { - width = Math.max($ta.width(), 0); + width = $ta.width(); } - mirror.style.width = width + 'px'; + mirror.style.width = Math.max(width,0) + 'px'; } function initMirror() { var styles = {}; mirrored = ta; mirror.className = options.className; mirror.id = options.id; - maxHeight = parseInt($ta.css('maxHeight'), 10); + maxHeight = parseFloat($ta.css('maxHeight')); // mirror is a duplicate textarea located off-screen that // is automatically updated to contain the same text as the // original textarea. mirror always has a height of 0. // This gives a cross-browser supported way getting the actual // height of the text, through the scrollTop property. $.each(typographyStyles, function(i,val){ styles[val] = $ta.css(val); }); - + $(mirror).css(styles).attr('wrap', $ta.attr('wrap')); setWidth(); // Chrome-specific fix: @@ -164,20 +164,21 @@ } else { setWidth(); } if (!ta.value && options.placeholder) { - // If the textarea is empty, copy the placeholder text into - // the mirror control and use that for sizing so that we + // If the textarea is empty, copy the placeholder text into + // the mirror control and use that for sizing so that we // don't end up with placeholder getting trimmed. - mirror.value = ($ta.attr("placeholder") || '') + options.append; + mirror.value = ($ta.attr("placeholder") || ''); } else { - mirror.value = ta.value + options.append; + mirror.value = ta.value; } + mirror.value += options.append || ''; mirror.style.overflowY = ta.style.overflowY; - original = parseInt(ta.style.height,10); + original = parseFloat(ta.style.height); // Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied mirror.scrollTop = 0; mirror.scrollTop = 9e4; @@ -197,13 +198,18 @@ height += boxOffset; if (original !== height) { ta.style.height = height + 'px'; + + // Trigger a repaint for IE8 for when ta is nested 2 or more levels inside an inline-block + mirror.className = mirror.className; + if (callback) { options.callback.call(ta,ta); } + $ta.trigger('autosize.resized'); } } function resize () { clearTimeout(timeout); @@ -267,6 +273,6 @@ // Call adjust in case the textarea already contains text. adjust(); }); }; -}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto +}(jQuery || $)); // jQuery or jQuery-like library, such as Zepto