diff options
author | Jed Foster <jed@jedfoster.com> | 2014-02-08 20:34:22 -0800 |
---|---|---|
committer | Jed Foster <jed@jedfoster.com> | 2014-02-08 20:34:22 -0800 |
commit | f3df04f90007d2018d5c9546140bf4324a83a053 (patch) | |
tree | 4e1c9e9961ff8e39f9c7ef0fc7bdbf730b9b48af | |
parent | 26689dea155d675f78e95ac7c9482d993bfbc50c (diff) | |
download | Readmore.js-f3df04f90007d2018d5c9546140bf4324a83a053.zip Readmore.js-f3df04f90007d2018d5c9546140bf4324a83a053.tar.gz Readmore.js-f3df04f90007d2018d5c9546140bf4324a83a053.tar.bz2 |
Fix up the merge
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | demo.html | 3 | ||||
-rw-r--r-- | readmore.js | 13 | ||||
-rw-r--r-- | readmore.min.js | 6 |
4 files changed, 18 insertions, 5 deletions
@@ -22,6 +22,7 @@ Yes, it's that simple. You can change the speed of the animation, the height of * `speed: 100` (in milliseconds) * `maxHeight: 200` (in pixels) +* `heightMargin: 16` (in pixels, avoids collapsing blocks that are only slightly larger than `maxHeight`) * `moreLink: '<a href="#">Read more</a>'` * `lessLink: '<a href="#">Close</a>'` * `embedCSS: true` (insert required CSS dynamically, set this to `false` if you include the necessary CSS in a stylesheet) @@ -54,7 +54,8 @@ <ul> <li><code>speed: 100</code> (in milliseconds)</li> - <li><code>maxHeight: 200</code> (in pixels)</li> + <li><code>maxHeight: 200</code> (in pixels)</li> + <li><code>heightMargin: 16</code> (in pixels, avoids collapsing blocks that are only slightly larger than <code>maxHeight</code>)</li> <li><code>moreLink: '<a href="#">Read more</a>'</code></li> <li><code>lessLink: '<a href="#">Close</a>'</code></li> <li><code>embedCSS: true</code> (insert required CSS dynamically, set this to <code>false</code> if you include the necessary CSS in a stylesheet)</li> diff --git a/readmore.js b/readmore.js index 272893f..1702369 100644 --- a/readmore.js +++ b/readmore.js @@ -1,10 +1,17 @@ +/*! + * Readmore.js jQuery plugin + * Author: @jed_foster + * Project home: jedfoster.github.io/Readmore.js + * Licensed under the MIT license + */ + ;(function($) { var readmore = 'readmore', defaults = { speed: 100, maxHeight: 200, - heightMargin: 15, + heightMargin: 16, moreLink: '<a href="#">Read More</a>', lessLink: '<a href="#">Close</a>', embedCSS: true, @@ -69,7 +76,7 @@ current.data("boxHeight", current.outerHeight(true)); - if(current.outerHeight(true) < maxHeight + hightMargin) { + if(current.outerHeight(true) <= maxHeight + hightMargin) { // The block is shorter than the limit, so there's no need to truncate it. return true; } @@ -135,4 +142,4 @@ }); } } -})(jQuery);
\ No newline at end of file +})(jQuery); diff --git a/readmore.min.js b/readmore.min.js index 01fc2f7..1f485f9 100644 --- a/readmore.min.js +++ b/readmore.min.js @@ -1 +1,5 @@ -(function(e){function i(i,s){this.element=i;this.options=e.extend({},n,s);e(this.element).data("max-height",this.options.maxHeight);e(this.element).data("height-margin",this.options.heightMargin);delete this.options.maxHeight;if(this.options.embedCSS&&!r){var o=".readmore-js-toggle, .readmore-js-section { "+this.options.sectionCSS+" } .readmore-js-section { overflow: hidden; }";(function(e,t){var n=e.createElement("style");n.type="text/css";if(n.styleSheet){n.styleSheet.cssText=t}else{n.appendChild(e.createTextNode(t))}e.getElementsByTagName("head")[0].appendChild(n)})(document,o);r=true}this._defaults=n;this._name=t;this.init()}var t="readmore",n={speed:100,maxHeight:200,heightMargin:15,moreLink:'<a href="#">Read More</a>',lessLink:'<a href="#">Close</a>',embedCSS:true,sectionCSS:"display: block; width: 100%;",startOpen:false,beforeToggle:function(){},afterToggle:function(){}},r=false;i.prototype={init:function(){var t=this;e(this.element).each(function(){var n=e(this),r=n.css("max-height").replace(/[^-\d\.]/g,"")>n.data("max-height")?n.css("max-height").replace(/[^-\d\.]/g,""):n.data("max-height"),i=n.data("height-margin");n.addClass("readmore-js-section");if(n.css("max-height")!="none"){n.css("max-height","none")}n.data("boxHeight",n.outerHeight(true));if(n.outerHeight(true)<r+i){return true}else{n.data("sliderHeight",r);var s=t.options.startOpen?t.options.lessLink:t.options.moreLink;n.after(e(s).on("click",function(e){t.toggleSlider(this,n,e)}).addClass("readmore-js-toggle"));if(!t.options.startOpen){n.css({height:r})}}})},toggleSlider:function(t,n,r){r.preventDefault();var i=this,s=newLink="",o=false,u=e(n).data("sliderHeight");if(e(n).height()==u){s=e(n).data().boxHeight+"px";newLink="lessLink";o=true}else{s=u;newLink="moreLink"}i.options.beforeToggle(t,n,o);e(n).animate({height:s},{duration:i.options.speed});e(t).replaceWith(e(i.options[newLink]).on("click",function(e){i.toggleSlider(this,n,e)}).addClass("readmore-js-toggle"));i.options.afterToggle(t,n,o)}};e.fn[t]=function(n){var r=arguments;if(n===undefined||typeof n==="object"){return this.each(function(){if(!e.data(this,"plugin_"+t)){e.data(this,"plugin_"+t,new i(this,n))}})}else if(typeof n==="string"&&n[0]!=="_"&&n!=="init"){return this.each(function(){var s=e.data(this,"plugin_"+t);if(s instanceof i&&typeof s[n]==="function"){s[n].apply(s,Array.prototype.slice.call(r,1))}})}}})(jQuery)
\ No newline at end of file +(function(d){function g(b,a){this.element=b;this.options=d.extend({},h,a);d(this.element).data("max-height",this.options.maxHeight);d(this.element).data("height-margin",this.options.heightMargin);delete this.options.maxHeight;if(this.options.embedCSS&&!k){var c=".readmore-js-toggle, .readmore-js-section { "+this.options.sectionCSS+" } .readmore-js-section { overflow: hidden; }",e=document.createElement("style");e.type="text/css";e.styleSheet?e.styleSheet.cssText=c:e.appendChild(document.createTextNode(c)); +document.getElementsByTagName("head")[0].appendChild(e);k=!0}this._defaults=h;this._name=f;this.init()}var f="readmore",h={speed:100,maxHeight:200,heightMargin:16,moreLink:'<a href="#">Read More</a>',lessLink:'<a href="#">Close</a>',embedCSS:!0,sectionCSS:"display: block; width: 100%;",startOpen:!1,beforeToggle:function(){},afterToggle:function(){}},k=!1;g.prototype={init:function(){var b=this;d(this.element).each(function(){var a=d(this),c=a.css("max-height").replace(/[^-\d\.]/g,"")>a.data("max-height")? +a.css("max-height").replace(/[^-\d\.]/g,""):a.data("max-height"),e=a.data("height-margin");a.addClass("readmore-js-section");"none"!=a.css("max-height")&&a.css("max-height","none");a.data("boxHeight",a.outerHeight(!0));if(a.outerHeight(!0)<=c+e)return!0;a.data("sliderHeight",c);a.after(d(b.options.startOpen?b.options.lessLink:b.options.moreLink).on("click",function(c){b.toggleSlider(this,a,c)}).addClass("readmore-js-toggle"));b.options.startOpen||a.css({height:c})})},toggleSlider:function(b,a,c){c.preventDefault(); +var e=this,f=newLink="";c=!1;f=d(a).data("sliderHeight");d(a).height()==f?(f=d(a).data().boxHeight+"px",newLink="lessLink",c=!0):newLink="moreLink";e.options.beforeToggle(b,a,c);d(a).animate({height:f},{duration:e.options.speed});d(b).replaceWith(d(e.options[newLink]).on("click",function(b){e.toggleSlider(this,a,b)}).addClass("readmore-js-toggle"));e.options.afterToggle(b,a,c)}};d.fn[f]=function(b){var a=arguments;if(void 0===b||"object"===typeof b)return this.each(function(){d.data(this,"plugin_"+ +f)||d.data(this,"plugin_"+f,new g(this,b))});if("string"===typeof b&&"_"!==b[0]&&"init"!==b)return this.each(function(){var c=d.data(this,"plugin_"+f);c instanceof g&&"function"===typeof c[b]&&c[b].apply(c,Array.prototype.slice.call(a,1))})}})(jQuery); |