forked from jedfoster/Readmore.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadmore.min.js
1 lines (1 loc) · 2.26 KB
/
readmore.min.js
1
;(function(c){var a="readmore",d={speed:100,maxHeight:200,moreLink:'<a href="#">Read More</a>',lessLink:'<a href="#">Close</a>',embedCSS:true,sectionCSS:"display: block; width: 100%;",startOpen:false,beforeToggle:function(){},afterToggle:function(){}},e=false;function b(g,f){this.element=g;this.options=c.extend({},d,f);c(this.element).data("max-height",this.options.maxHeight);delete (this.options.maxHeight);if(this.options.embedCSS&&!e){var h=".readmore-js-toggle, .readmore-js-section { "+this.options.sectionCSS+" } .readmore-js-section { overflow: hidden; }";(function(k,i){var j=k.createElement("style");j.type="text/css";if(j.styleSheet){j.styleSheet.cssText=i}else{j.appendChild(k.createTextNode(i))}k.getElementsByTagName("head")[0].appendChild(j)}(document,h));e=true}this._defaults=d;this._name=a;this.init()}b.prototype={init:function(){var f=this;c(this.element).each(function(){var i=c(this),h=(i.css("max-height").replace(/[^-\d\.]/g,"")>i.data("max-height"))?i.css("max-height").replace(/[^-\d\.]/g,""):i.data("max-height");i.addClass("readmore-js-section");if(i.css("max-height")!="none"){i.css("max-height","none")}i.data("boxHeight",i.outerHeight(true));if(i.outerHeight(true)<h){return true}else{i.data("sliderHeight",h);var g=f.options.startOpen?f.options.lessLink:f.options.moreLink;i.after(c(g).on("click",function(j){f.toggleSlider(this,i,j)}).addClass("readmore-js-toggle"));if(!f.options.startOpen){i.css({height:h})}}})},toggleSlider:function(g,i,j){j.preventDefault();var k=this,f=newLink="",h=false,l=c(i).data("sliderHeight");if(c(i).height()==l){f=c(i).data().boxHeight+"px";newLink="lessLink";h=true}else{f=l;newLink="moreLink"}k.options.beforeToggle(g,i,h);c(i).animate({height:f},{duration:k.options.speed,complete:function(){k.options.afterToggle(g,i,h)}});c(g).replaceWith(c(k.options[newLink]).on("click",function(m){k.toggleSlider(this,i,m)}).addClass("readmore-js-toggle"))}};c.fn[a]=function(g){var f=arguments;if(g===undefined||typeof g==="object"){return this.each(function(){if(!c.data(this,"plugin_"+a)){c.data(this,"plugin_"+a,new b(this,g))}})}else{if(typeof g==="string"&&g[0]!=="_"&&g!=="init"){return this.each(function(){var h=c.data(this,"plugin_"+a);if(h instanceof b&&typeof h[g]==="function"){h[g].apply(h,Array.prototype.slice.call(f,1))}})}}}})(jQuery);