Permalink
Browse files

Merge pull request #12 from AlexaWebhead/patch-1

Fixed minified version of truncate script
  • Loading branch information...
2 parents cff14b1 + b8b75b2 commit 71b8e33c0910ab201cd1b0502bc736b8945a6cf6 @tbasse committed Mar 10, 2013
Showing with 8 additions and 1 deletion.
  1. +8 −1 jquery.truncate.min.js
View
9 jquery.truncate.min.js
@@ -1 +1,8 @@
-(function(e){function t(e){return!isNaN(parseFloat(e))&&isFinite(e)}function n(e,t,r,i,s,o,u,a){var f=function(e){return(a?u:"")+e+(a?"":u)};var l,c,h;if(a){l=i===0?"":r.slice(-i);c=r.slice(-s)}else{l=r.slice(0,i);c=r.slice(0,s)}if(t<o.html(u)[e]()){return 0}if(o.html(f(c))[e]()<o.html(f(l))[e]()){return s}h=parseInt((i+s)/2,10);l=a?r.slice(-h):r.slice(0,h);o.html(f(l));if(o[e]()===t){return h}if(o[e]()>t){s=h-1}else{i=h+1}return n(e,t,r,i,s,o,u,a)}e.fn.truncate=function(r){if(typeof r.center!="undefined"&&typeof r.side=="undefined"){r.side="center";delete r.center}if(typeof r.side!="undefined")switch(r.side){case"left":case"center":case"right":break;default:delete r.side}var i={width:"auto",token:"É",side:"right",addclass:false,addtitle:false,multiline:false};r=e.extend(i,r);return this.each(function(){var i=e(this),s={fontFamily:i.css("fontFamily"),fontSize:i.css("fontSize"),fontStyle:i.css("fontStyle"),fontWeight:i.css("fontWeight"),"font-variant":i.css("font-variant"),"text-indent":i.css("text-indent"),"text-transform":i.css("text-transform"),"letter-spacing":i.css("letter-spacing"),"word-spacing":i.css("word-spacing"),display:"none"},o=i.text(),u=e("<span/>").css(s).html(o).appendTo("body"),a=u.width(),f=t(r.width)?r.width:i.width(),l="width",c,h,p;if(r.multiline){u.width(i.width());l="height";h=u.height();p=i.height()+1}else{h=a;p=f}if(h>p){u.text("");switch(r.side){case"left":c=r.token+o.slice(-1*n(l,p,o,0,o.length,u,r.token,true));break;case"center":p=parseInt(p/2,10)-1;c=o.slice(0,n(l,p,o,0,o.length,u,r.token,false))+r.token+o.slice(-1*n(l,p,o,0,o.length,u,"",true));break;case"right":c=o.slice(0,n(l,p,o,0,o.length,u,r.token,false))+r.token;break}if(r.addclass){i.addClass(r.addclass)}if(r.addtitle){i.attr("title",o)}i.empty().append(c)}u.remove()})}})(jQuery)
+(function(c){function a(d){return !isNaN(parseFloat(d))&&isFinite(d);}function b(g,i,o,d,f,j,e,h){var l=function(p){return(h?e:"")+p+(h?"":e);};var n,m,k;
+if(h){n=d===0?"":o.slice(-d);m=o.slice(-f);}else{n=o.slice(0,d);m=o.slice(0,f);}if(i<j.html(e)[g]()){return 0;}if(j.html(l(m))[g]()<j.html(l(n))[g]()){return f;
+}k=parseInt((d+f)/2,10);n=h?o.slice(-k):o.slice(0,k);j.html(l(n));if(j[g]()===i){return k;}if(j[g]()>i){f=k-1;}else{d=k+1;}return b(g,i,o,d,f,j,e,h);}c.fn.truncate=function(d){if(typeof d.center!="undefined"&&typeof d.side=="undefined"){d.side="center";
+delete d.center;}if(typeof d.side!="undefined"){switch(d.side){case"left":case"center":case"right":break;default:delete d.side;}}var e={width:"auto",token:"&hellip;",side:"right",addclass:false,addtitle:false,multiline:false};
+d=c.extend(e,d);return this.each(function(){var n=c(this),i={fontFamily:n.css("fontFamily"),fontSize:n.css("fontSize"),fontStyle:n.css("fontStyle"),fontWeight:n.css("fontWeight"),"font-variant":n.css("font-variant"),"text-indent":n.css("text-indent"),"text-transform":n.css("text-transform"),"letter-spacing":n.css("letter-spacing"),"word-spacing":n.css("word-spacing"),display:"none"},l=n.text(),k=c("<span/>").css(i).html(l).appendTo("body"),f=k.width(),o=a(d.width)?d.width:n.width(),h="width",j,g,m;
+if(d.multiline){k.width(n.width());h="height";g=k.height();m=n.height()+1;}else{g=f;m=o;}if(g>m){k.text("");switch(d.side){case"left":j=d.token+l.slice(-1*b(h,m,l,0,l.length,k,d.token,true));
+break;case"center":m=parseInt(m/2,10)-1;j=l.slice(0,b(h,m,l,0,l.length,k,d.token,false))+d.token+l.slice(-1*b(h,m,l,0,l.length,k,"",true));break;case"right":j=l.slice(0,b(h,m,l,0,l.length,k,d.token,false))+d.token;
+break;}if(d.addclass){n.addClass(d.addclass);}if(d.addtitle){n.attr("title",l);}n.empty().append(j);}k.remove();});};})(jQuery);

0 comments on commit 71b8e33

Please sign in to comment.