/*
 * Shorten, a jQuery plugin to automatically shorten text to fit in a block or a pre-set width and configure how the text ends.
 * Copyright (C) 2009-2010  Marc Diethelm
 * License: (GPL 3, http://www.gnu.org/licenses/gpl-3.0.txt) see license.txt
 */

(function(a){a.fn.shorten=function(){var b={},c=arguments,e=c.callee;if(c.length)if(c[0].constructor==Object)b=c[0];else if(c[0]=="options")return a(this).eq(0).data("options-truncate");else b={width:parseInt(c[0]),tail:c[1]};this.css("visibility","hidden");var f=a.extend({},e.defaults,b);return this.each(function(){var g=a(this),d=g.text(),n=d.length,h=f.width||g.parent().width(),i,j,k=a("<span/>").html(f.tail).text();if(h<0)return true;g.data("options-truncate",f);if(e._supportsCanvas){i=e.measureText_initCanvas.call(this); j=e.measureText_canvas}else{i=e.measureText_initTable.call(this);j=e.measureText_table}var l=j.call(this,d,i);if(l<h){g.text(d);this.style.visibility="visible";return true}f.tooltip&&this.setAttribute("title",d);if(e._native){var q=a("<span>"+f.tail+"</span>").text();if(q.length==1&&q.charCodeAt(0)==8230){g.text(d);this.style[e._native]="ellipsis";this.style.visibility="visible";return true}}k=j.call(this,k,i);h-=k;k=h*1.15;if(l-k>0){l=d.substring(0,Math.ceil(n*(k/l)));if(j.call(this,l,i)>h){d=l; n=d.length}}do{n--;d=d.substring(0,n)}while(j.call(this,d,i)>=h);g.html(a.trim(a("<span/>").text(d).html())+f.tail);this.style.visibility="visible";return true})};var m=document.documentElement.style,p=false;if("textOverflow"in m)p="textOverflow";else if("OTextOverflow"in m)p="OTextOverflow";else{m=document.createElement("canvas");var o=m.getContext("2d");a.fn.shorten._supportsCanvas=o?true:false;delete m}a.fn.shorten._native=p;a.fn.shorten.measureText_initCanvas=function(){var b=a(this),c=document.createElement("canvas"); o=c.getContext("2d");b.html(c);o.font=b.css("font-style")+" "+b.css("font-variant")+" "+b.css("font-weight")+" "+Math.ceil(parseFloat(b.css("font-size")))+"px "+b.css("font-family");return o};a.fn.shorten.measureText_canvas=function(b,c){return c.measureText(b).width};a.fn.shorten.measureText_initTable=function(){var b=a('<table style="padding:0; margin:0; border:none; font:inherit;width:auto;zoom:1;position:absolute;"><tr style="padding:0; margin:0; border:none; font:inherit;"><td style="padding:0; margin:0; border:none; font:inherit;white-space:nowrap;"></td></tr></table>'); $td=a("td",b);a(this).html(b);return $td};a.fn.shorten.measureText_table=function(b,c){c.text(b);return c.width()};a.fn.shorten.defaults={tail:"&hellip;",tooltip:true}})(jQuery);
