/* http://keith-wood.name/more.html
   Text truncation and show more for jQuery v2.0.1.
   Written by Keith Wood (kwood{at}iinet.com.au) May 2010.
   Available under the MIT (https://github.com/jquery/jquery/blob/master/LICENSE.txt) license. 
   Please attribute the author if you use it. */
(function($){var o='more';$.JQPlugin.createPlugin({name:o,defaultOptions:{length:100,leeway:5,wordBreak:false,ignoreTags:['br','hr','img'],toggle:true,ellipsisText:'...',moreText:'Show more',lessText:'Show less',andNext:'',onChange:null},_ellipsisClass:o+'-ellipsis',_linkClass:o+'-link',_hiddenClass:o+'-hidden',_tagName:/^<(\w+).*>$/,_instSettings:function(a,b){return{html:a.html()}},_optionsChanged:function(d,e,f){var g=this;$.extend(e.options,f);this._preDestroy(d,e);var h='';if(d.text().length>e.options.length+e.options.leeway){var j=d.html().match(/(<[^>]+>)|([^<]+)/g);var i=0;var k=0;var l=[];for(;i<j.length;i++){if(j[i][0]==='<'){if(j[i][1]==='/'||j[i][j[i].length-2]==='/'){l.pop()}else if($.inArray(j[i].toLowerCase().replace(this._tagName,'$1'),e.options.ignoreTags)===-1){l.push(j[i])}}else if(k+j[i].length>e.options.length){break}else{k+=j[i].length}}k=e.options.length-k;if(e.options.wordBreak){var m=j[i].substring(0,k+1).replace('\n',' ').match(/^.*\W/m);k=(m?m[0].length-1:k)}var n=function(a){var b='';for(var i=a.length-1;i>=0;i--){b+='</'+a[i].replace(g._tagName,'$1')+'>'}return b};h=j.slice(0,i).join('')+j[i].substring(0,k)+n(l)+'<span class="'+this._ellipsisClass+'">'+e.options.ellipsisText+'</span>'+'<span class="'+this._hiddenClass+'">'+l.join('')+j[i].substring(k)+n(l)+j.slice(i+1).join('')+'</span>'}else if(f.andNext&&d.nextAll(f.andNext).length){h=d.html()}if(h){h+='<a href="#" class="'+this._linkClass+'">'+e.options.moreText+'</a>';d.html(h).find('a.'+this._linkClass).click(function(a){var b=$(this);var c=b.html()===e.options.moreText;b.html(c?e.options.lessText:e.options.moreText).siblings('span.'+g._ellipsisClass+',span.'+g._hiddenClass).toggle();if(f.andNext){b.parent().nextAll(f.andNext).toggle()}if(!e.options.toggle){b.remove()}if($.isFunction(e.options.onChange)){e.options.onChange.apply(d,[c])}a.stopPropagation();return false});if(f.andNext){d.nextAll(f.andNext).hide()}}},_preDestroy:function(a,b){a.html(b.html);if(b.options.andNext){a.nextAll(b.options.andNext).show()}}})})(jQuery);