summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJed Foster <jed@jedfoster.com>2014-02-09 13:05:06 -0800
committerJed Foster <jed@jedfoster.com>2014-02-09 13:05:06 -0800
commit53bbc02465e694f4b909ccabf513b6fa7e59c28a (patch)
treebeac37d37bffa97cf997400238f58d51f20595e2
parentce591e2f0b849dcb48a5c165a96d935a08ae94e1 (diff)
parent007a37e89107a769f1979443757180e242a00a0d (diff)
downloadReadmore.js-53bbc02465e694f4b909ccabf513b6fa7e59c28a.zip
Readmore.js-53bbc02465e694f4b909ccabf513b6fa7e59c28a.tar.gz
Readmore.js-53bbc02465e694f4b909ccabf513b6fa7e59c28a.tar.bz2
Merge branch 'destroy-method'
Closes #12
-rw-r--r--README.md16
-rw-r--r--demo.html11
-rw-r--r--readmore.js10
-rw-r--r--readmore.min.js10
4 files changed, 40 insertions, 7 deletions
diff --git a/README.md b/README.md
index 325c663..8bbd164 100644
--- a/README.md
+++ b/README.md
@@ -81,4 +81,18 @@ If you want to include the necessary styling in your site's stylesheet, you can
```javascript
$('article').readmore({embedCSS: false});
-``` \ No newline at end of file
+```
+
+## Removing Readmore
+
+You can remove the Readmore functionality like so:
+
+```javascript
+$('article').readmore('destroy');
+```
+
+Or, you can be more surgical by specifying a particular element:
+
+```javascript
+$('article:first').readmore('destroy');
+```
diff --git a/demo.html b/demo.html
index 948b369..26867dc 100644
--- a/demo.html
+++ b/demo.html
@@ -81,7 +81,7 @@
<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>
- <pre><code>$('article').readmore({
+ <pre><code class="javascript">$('article').readmore({
afterToggle: function(trigger, element, more) {
if(! more) { // The "Close" link was clicked
$('html, body').animate( { scrollTop: element.offset().top }, {duration: 100 } );
@@ -111,6 +111,15 @@
<pre><code class="javascript">$(&apos;article&apos;).readmore({embedCSS: false});</code></pre>
+ <h2 id="removingreadmore">Removing Readmore</h2>
+
+ <p>You can remove the Readmore functionality like so:</p>
+
+ <pre><code class="javascript">$('article').readmore('destroy');</code></pre>
+
+ <p>Or, you can be more surgical by specifying a particular element:</p>
+
+ <pre><code class="javascript">$('article:first').readmore('destroy');</code></pre>
</section>
<h1>Demo</h1>
diff --git a/readmore.js b/readmore.js
index 1702369..f2b009f 100644
--- a/readmore.js
+++ b/readmore.js
@@ -122,6 +122,16 @@
// Fire afterToggle callback
$this.options.afterToggle(trigger, element, more);
+ },
+
+ destroy: function() {
+ $(this.element).each(function() {
+ var current = $(this);
+
+ current.removeClass('readmore-js-section').css({'max-height': '', 'height': 'auto'}).next('.readmore-js-toggle').remove();
+
+ current.removeData();
+ });
}
};
diff --git a/readmore.min.js b/readmore.min.js
index 1f485f9..5daa9d7 100644
--- a/readmore.min.js
+++ b/readmore.min.js
@@ -1,5 +1,5 @@
-(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);
+(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,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");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)<=d+e)return!0;a.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})})},toggleSlider:function(b,a,d){d.preventDefault();
+var e=this,f=newLink="";d=!1;f=c(a).data("sliderHeight");c(a).height()==f?(f=c(a).data().boxHeight+"px",newLink="lessLink",d=!0):newLink="moreLink";e.options.beforeToggle(b,a,d);c(a).animate({height:f},{duration:e.options.speed});c(b).replaceWith(c(e.options[newLink]).on("click",function(b){e.toggleSlider(this,a,b)}).addClass("readmore-js-toggle"));e.options.afterToggle(b,a,d)},destroy:function(){c(this.element).each(function(){var b=c(this);b.removeClass("readmore-js-section").css({"max-height":"",
+height:"auto"}).next(".readmore-js-toggle").remove();b.removeData()})}};c.fn[f]=function(b){var a=arguments;if(void 0===b||"object"===typeof b)return this.each(function(){c.data(this,"plugin_"+f)||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);