This repository has been archived on 2025-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
reprapfirmware-dc42/SD-image/www/js/jquery.textarea_autosize.js
David Crocker 8d99d640b8 Version 1.09x-beta3
Merged in chrishamm's changes to Network, PrintMonitor, and his support
for firmware updates from SD card
Fixed print monitor issue that threw out the layer count and time
estimates when there was an initial extruder priming move in the start
gcode
2016-03-11 18:03:41 +00:00

54 lines
1.4 KiB
JavaScript

/*!
* jQuery Textarea AutoSize plugin
* Author: Javier Julio
* Licensed under the MIT license
*/
;(function ($, window, document, undefined) {
var pluginName = "textareaAutoSize";
var pluginDataName = "plugin_" + pluginName;
var containsText = function (value) {
return (value.replace(/\s/g, '').length > 0);
};
function Plugin(element, options) {
this.element = element;
this.$element = $(element);
this.init();
}
Plugin.prototype = {
init: function() {
var height = this.$element.outerHeight();
var diff = parseInt(this.$element.css('paddingBottom')) +
parseInt(this.$element.css('paddingTop')) || 0;
if (containsText(this.element.value)) {
this.$element.height(this.element.scrollHeight - diff);
}
// keyup is required for IE to properly reset height when deleting text
this.$element.on('input keyup', function(event) {
var $window = $(window);
var currentScrollPosition = $window.scrollTop();
$(this)
.height(0)
.height(this.scrollHeight - diff);
$window.scrollTop(currentScrollPosition);
});
}
};
$.fn[pluginName] = function (options) {
this.each(function() {
if (!$.data(this, pluginDataName)) {
$.data(this, pluginDataName, new Plugin(this, options));
}
});
return this;
};
})(jQuery, window, document);