This repository was archived by the owner on Oct 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-autoexpand.min.js
3 lines (3 loc) · 2.18 KB
/
jquery-autoexpand.min.js
1
2
3
/*! jquery-autoexpand - v0.1.1 - 2013-10-22 */
!function($){"use strict";var pub={init:function(options){return this.each(function(){var $this=$(this);$this.data("autoexpand")||($this.data("autoexpand",$.extend({},$.fn.autoexpand.defaults,options)),void 0!==$this.attr("data-autoexpand-options")&&(options=$this.attr("data-autoexpand-options").split(";"),$.each(options,function(index,value){var p=value.split(":");/true/i.test(p[1])&&(p[1]=!0),/false/i.test(p[1])&&(p[1]=!1),isNaN(p[1]-0)||null===p[1]||""===p[1]||p[1]===!1||p[1]===!0||(p[1]=parseInt(p[1],10)),2===p.length&&p[0].length>0&&(p[0]=$.trim(p[0]),p[1]=$.trim(p[1]),$this.data("autoexpand")[p[0]]=p[1])}),$this.data("autoexpand"))),$this.data("autoexpand").originalHeight=$this.outerHeight(),$this.data("autoexpand").resizeOnInit&&pub.resize.apply($this),$this.on("keyup focus",function(){pub.resize.apply($this)}),$this.data("autoexpand").actAsInput&&($this.on("keypress",function(e){return 13==(e.keyCode||e.which)?!1:void 0}),$this.on("keyup",function(e){13==(e.keyCode||e.which)&&$this.parents("form").submit()}),$this.on("paste",function(){setTimeout(function(){$this.val($this.val().replace(/(\r\n|\n|\r)/gm," ")),pub.resize.apply($this)},20)}))})},resize:function(){return this.each(function(){var $this=$(this),data=$this.data("autoexpand");$this.css({height:0});var height=$this[0].scrollHeight+(parseFloat($this.css("border-top-width"))+parseFloat($this.css("border-bottom-width")));0!==data.min&&height<data.min&&(height=data.min),0!==data.max&&height>data.max&&(height=data.max,$this.css({overflow:"auto"})),$this.css({height:height})})},destroy:function(){return this.each(function(){var $this=$(this);$this.unbind("keyup focus"),$this.css({height:$this.data("autoexpand").originalHeight}),$this.removeData("autoexpand")})}};$.fn.autoexpand=function(method){return pub[method]?pub[method].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof method&&method?($.error("Method "+method+" does not exist on jQuery.autoexpand"),void 0):pub.init.apply(this,arguments)},$.fn.autoexpand.defaults={resizeOnInit:!1,actAsInput:!1,min:0,max:0},$("textarea[data-autoexpand]").autoexpand()}(jQuery);
//# sourceMappingURL=jquery-autoexpand.sourcemap.js