diff options
author | Jed Foster <jed@jedfoster.com> | 2014-02-09 21:02:40 -0800 |
---|---|---|
committer | Jed Foster <jed@jedfoster.com> | 2014-02-09 21:11:38 -0800 |
commit | 08321a27ab5154f8559ae7cdc1ed44e8d79979cd (patch) | |
tree | 4b669df4f51174c2d9a2993523e26034b63c0ec6 | |
parent | 7251369428c870a326fdbfdf4f767bf302e36b41 (diff) | |
download | Readmore.js-origin/gh-pages.zip Readmore.js-origin/gh-pages.tar.gz Readmore.js-origin/gh-pages.tar.bz2 |
Import latest demo and minified JSorigin/gh-pages
-rw-r--r-- | index.html | 29 | ||||
-rw-r--r-- | js/readmore.min.js | 12 |
2 files changed, 27 insertions, 14 deletions
@@ -18,8 +18,8 @@ js: | $('#info').readmore({ moreLink: '<a href="#">More examples and options</a>', maxHeight: 390, - afterToggle: function(trigger, element, more) { - if(! more) { // The "Close" link was clicked + afterToggle: function(trigger, element, expanded) { + if(! expanded) { // The "Close" link was clicked $('html, body').animate( { scrollTop: element.offset().top }, {duration: 100 } ); } } @@ -44,31 +44,31 @@ js: | <h3 id="example">Example</h3> {% highlight javascript %} - $('article').readmore(); - {% endhighlight %} <p>Yes, it’s that simple. You can change the speed of the animation, the height of the collapsed block, and the open and close elements.</p> {% highlight javascript %} - $('article').readmore({ speed: 75, maxHeight: 500 }); - {% endhighlight %} <h3 id="theoptions">The options:</h3> <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> <li><code>sectionCSS: 'display: block; width: 100%;'</code> (sets the styling of the blocks)</li> + <li><code>startOpen: false</code> (do not immediately truncate, start in the fully opened position)</li> + <li><code>expandedClass: 'readmore-js-expanded'</code> (class added to expanded blocks)</li> + <li><code>collapsedClass: 'readmore-js-collapsed'</code> (class added to collapsed blocks)</li> <li><code>beforeToggle: function() {}</code> (called after a more or less link is clicked, but <i>before</i> the block is collapsed or expanded)</li> <li><code>afterToggle: function() {}</code> (called <i>after</i> the block is collapsed or expanded)</li> </ul> @@ -90,7 +90,6 @@ $('article').readmore({ <p>Here's an example of how you could use the <code>afterToggle</code> callback to scroll back to the top of a block when the "Close" link is clicked.</p> {% highlight javascript %} - $('article').readmore({ afterToggle: function(trigger, element, more) { if(! more) { // The "Close" link was clicked @@ -98,7 +97,6 @@ $('article').readmore({ } } }); - {% endhighlight %} <h3 id="recommendedcss">Recommended CSS:</h3> @@ -129,6 +127,19 @@ $('article').readmore({sectionCSS: 'display: inline-block; width: 50%;'}); $('article').readmore({embedCSS: false}); {% endhighlight %} + <h2 id="removingreadmore">Removing Readmore</h2> + + <p>You can remove the Readmore functionality like so:</p> + +{% highlight javascript %} +$('article').readmore('destroy'); +{% endhighlight %} + + <p>Or, you can be more surgical by specifying a particular element:</p> + +{% highlight javascript %} +$('article:first').readmore('destroy'); +{% endhighlight %} </section> diff --git a/js/readmore.min.js b/js/readmore.min.js index f5157b2..9188b7f 100644 --- a/js/readmore.min.js +++ b/js/readmore.min.js @@ -1,5 +1,7 @@ -(function(d){function g(c,a){this.element=c;this.options=d.extend({},h,a);d(this.element).data("max-height",this.options.maxHeight);delete this.options.maxHeight;if(this.options.embedCSS&&!k){var b=".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=b:e.appendChild(document.createTextNode(b));document.getElementsByTagName("head")[0].appendChild(e); -k=!0}this._defaults=h;this._name=f;this.init()}var f="readmore",h={speed:100,maxHeight:200,moreLink:'<a href="#">Read More</a>',lessLink:'<a href="#">Close</a>',embedCSS:!0,sectionCSS:"display: block; width: 100%;",beforeToggle:function(){},afterToggle:function(){}},k=!1;g.prototype={init:function(){var c=this;d(this.element).each(function(){var a=d(this),b=a.css("max-height").replace(/[^-\d\.]/g,"")>a.data("max-height")?a.css("max-height").replace(/[^-\d\.]/g,""):a.data("max-height");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)<b)return!0;a.after(d(c.options.moreLink).on("click",function(b){c.toggleSlider(this,a,b)}).addClass("readmore-js-toggle"));a.data("sliderHeight",b);a.css({height:b})})},toggleSlider:function(c,a,b){b.preventDefault();var e=this,f=newLink="";b=!1;f=d(a).data("sliderHeight");d(a).height()==f?(f=d(a).data().boxHeight+"px",newLink="lessLink",b=!0):newLink="moreLink";e.options.beforeToggle(c, -a,b);d(a).animate({height:f},{duration:e.options.speed});d(c).replaceWith(d(e.options[newLink]).on("click",function(b){e.toggleSlider(this,a,b)}).addClass("readmore-js-toggle"));e.options.afterToggle(c,a,b)}};d.fn[f]=function(c){var a=arguments;if(void 0===c||"object"===typeof c)return this.each(function(){d.data(this,"plugin_"+f)||d.data(this,"plugin_"+f,new g(this,c))});if("string"===typeof c&&"_"!==c[0]&&"init"!==c)return this.each(function(){var b=d.data(this,"plugin_"+f);b instanceof g&&"function"=== -typeof b[c]&&b[c].apply(b,Array.prototype.slice.call(a,1))})}})(jQuery); +(function(c){function g(b,a){this.element=b;this.options=c.extend({},h,a);c(this.element).data("max-height",this.options.maxHeight);c(this.element).data("height-margin",this.options.heightMargin);delete this.options.maxHeight;if(this.options.embedCSS&&!k){var d=".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=d:e.appendChild(document.createTextNode(d)); +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,expandedClass:"readmore-js-expanded",collapsedClass:"readmore-js-collapsed",beforeToggle:function(){},afterToggle:function(){}},k=!1;g.prototype={init:function(){var b=this;c(this.element).each(function(){var a= +c(this),d=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");"none"!=a.css("max-height")&&a.css("max-height","none");b.setBoxHeight(a);if(a.outerHeight(!0)<=d+e)return!0;a.addClass("readmore-js-section "+b.options.collapsedClass).data("sliderHeight",d);a.after(c(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:d})});c(window).on("resize",function(a){b.resizeBoxes()})},toggleSlider:function(b,a,d){d.preventDefault();var e=this;d=newLink=sectionClass="";var f=!1;d=c(a).data("sliderHeight");c(a).height()==d?(d=c(a).data().boxHeight+"px",newLink="lessLink",f=!0,sectionClass=e.options.expandedClass):(newLink="moreLink",sectionClass=e.options.collapsedClass);e.options.beforeToggle(b,a,f);c(a).animate({height:d},{duration:e.options.speed,complete:function(){e.options.afterToggle(b, +a,f);c(b).replaceWith(c(e.options[newLink]).on("click",function(b){e.toggleSlider(this,a,b)}).addClass("readmore-js-toggle"));c(this).removeClass(e.options.collapsedClass+" "+e.options.expandedClass).addClass(sectionClass)}})},setBoxHeight:function(b){var a=b.clone().css({height:"auto",width:b.width(),overflow:"hidden"}).insertAfter(b),c=a.outerHeight(!0);a.remove();b.data("boxHeight",c)},resizeBoxes:function(){var b=this;c(".readmore-js-section").each(function(){var a=c(this);b.setBoxHeight(a);(a.height()> +a.data("boxHeight")||a.hasClass(b.options.expandedClass)&&a.height()<a.data("boxHeight"))&&a.css("height",a.data("boxHeight"))})},destroy:function(){var b=this;c(this.element).each(function(){var a=c(this);a.removeClass("readmore-js-section "+b.options.collapsedClass+" "+b.options.expandedClass).css({"max-height":"",height:"auto"}).next(".readmore-js-toggle").remove();a.removeData()})}};c.fn[f]=function(b){var a=arguments;if(void 0===b||"object"===typeof b)return this.each(function(){if(c.data(this, +"plugin_"+f)){var a=c.data(this,"plugin_"+f);a.destroy.apply(a)}c.data(this,"plugin_"+f,new g(this,b))});if("string"===typeof b&&"_"!==b[0]&&"init"!==b)return this.each(function(){var d=c.data(this,"plugin_"+f);d instanceof g&&"function"===typeof d[b]&&d[b].apply(d,Array.prototype.slice.call(a,1))})}})(jQuery); |