-
Notifications
You must be signed in to change notification settings - Fork 1
/
mTruncate.min.js
1 lines (1 loc) · 1.95 KB
/
mTruncate.min.js
1
(function(a){a.fn.mtruncate=function(b){var c=a.extend({maxLines:11,expandText:"Expand",collapseText:"Collapse",hideImageOnCollapse:true},b);return this.each(function(){var e=a(this).css("overflow","hidden");var j=e.wrap('<div class="mTruncate-wrapper mTruncate-collapsed" />').parent();var i=a('<div class="mTruncate-control">'+c.expandText+"</div>").appendTo(j);var g=e.css("float");if(g=="left"||g=="right"){j.css("float",g)}var d=0;var h=0;function f(l,k){if(l==true){d=0;h=0}k.each(function(){if(this.nodeType==8){return true}var o=a(this).prop("tagName");if(typeof o=="undefined"){var q=this.textContent.trim();if(q.length==0){return true}var n=a(this).parent();var m=n.height();var p=parseFloat(n.css("line-height"));var r=Math.round(m/p);d+=parseFloat(n.css("margin-top"));if((h+r)>=c.maxLines){r=(c.maxLines-h)}d+=r*p;h+=r;if(h<c.maxLines){d+=parseFloat(n.css("margin-bottom"))}return true}if(o.indexOf("H")==0&&o.length==2&&!isNaN(o[1])){d+=a(this).height();d+=parseFloat(a(this).css("margin-top"));d+=parseFloat(a(this).css("margin-bottom"));h++}else{if(o.toLowerCase()=="img"){if(c.hideImageOnCollapse){if(a(this).hasClass("mTruncate-hidden")==false){a(this).addClass("mTruncate-hidden")}return true}d+=a(this).height();d+=parseFloat(a(this).css("margin-top"));d+=parseFloat(a(this).css("margin-bottom"));h++}else{if(a(this).contents().length!=0){f(false,a(this).contents())}}}if(h>=c.maxLines){return false}})}a(window).resize(function(){f(true,e.contents());if(j.hasClass("mTruncate-collapsed")){e.height(d)}}).trigger("resize");i.click(function(){var l=a(".mTruncate-hidden");if(j.hasClass("mTruncate-collapsed")){l.show();var k=e.css("height","100%").outerHeight();l.hide();e.css("height",d);e.animate({height:k},"slow",function(){e.css("height","")});i.html(c.collapseText);l.fadeIn("slow");j.removeClass("mTruncate-collapsed")}else{if(c.hideImageOnCollapse==true){l.fadeOut("slow")}e.animate({height:d},"slow");i.html(c.expandText);j.addClass("mTruncate-collapsed")}})})}}(jQuery));