!function(n,t){"use strict";function i(t,i){this.el=t;this.options=n.extend({},r,i);this.init()}var r={minFont:1,maxFont:9999,preWrapText:!1,lineHeight:1.45,resizable:!0,debounce:!1,fit:!0,ellipsis:!0,center:!1,justify:!1};i.prototype={init:function(){var r=this.options.minFont>this.options.maxFont,u,i;n(this.el);(r&&t.console&&console.log("TextTailor error: minFont needs to be smaller than maxFont!"),this.HTML=this.el.innerHTML,r)||(i=this,this.options.resizable&&n(t).on("resize",function(){i.options.debounce?(clearTimeout(u),u=setTimeout(function(){i.start()},200)):i.start()}),this.start())},start:function(){var t=n(this.el);this.el.innerHTML=this.HTML;t.wrapInner("<div/>");this.wraped=n(this.el.firstChild);this.wraped.css({"line-height":this.options.lineHeight,tranform:"translateZ(0)",height:"auto"});this.options.preWrapText&&this.wraped.css("white-space","pre-line");this.maxHeight=t.height();this.maxWidth=t.width();this.fit().ellipsis().center().justify()},fit:function(){var u;if(this.options.fit){var t=this,n=this.wraped,f=30,e=0,i=function i(r,u,o){return++e===f?r:r<=t.options.minFont?t.options.minFont:r>=t.options.maxFont?t.options.maxFont:u===o?u:(n.css("fontSize",r),n[0].scrollHeight<t.maxHeight?(n.css("fontSize",r+1),n[0].scrollHeight>=t.maxHeight?r:i(Math.round((o+r)/2),r,o)):(n.css("fontSize",r-1),i(Math.round((u+r)/2),u,r)))},r=Math.round((this.options.maxFont+this.options.minFont)/2);n.css("fontSize",r);u=i(r,this.options.minFont,this.options.maxFont);n.css("fontSize",u)}return this},ellipsis:function(){var n,i,t,r,u;if(this.options.ellipsis&&(n=this.wraped,n.css({overflow:"hidden","text-overflow":"ellipsis"}),n.height()>this.maxHeight)){for(i=n.html(),n.html("O"),t=(n.height(),1),r=i.length;t<r;)u=Math.ceil((t+r)/2),n.html(i.slice(0,u)+"..."),n.height()<=this.maxHeight?t=u:r=u-1;n.html(i.slice(0,t)+"...")}return this},center:function(){if(this.options.center){var t=n(this.el).css("position");"relative"!==t&&"absolute"!==t&&n(this.el).css("position","relative");this.wraped.css({position:"absolute",width:this.wraped.width()+"px",left:"0",right:"0",top:"0",bottom:"0",height:this.wraped.height()+"px",margin:"auto"})}return this},justify:function(){return this.options.justify&&this.wraped.css({"text-align":"justify"}),this}};n.fn.textTailor=function(t){return this.each(function(){n.data(this,"TextTailor")||n.data(this,"TextTailor",new i(this,t))})}}(jQuery,window)