summaryrefslogtreecommitdiffstats
path: root/readmore.js
diff options
context:
space:
mode:
authorJed Foster <jed@jedfoster.com>2014-02-09 15:54:25 -0800
committerJed Foster <jed@jedfoster.com>2014-02-09 15:54:25 -0800
commit1fb6a5674589e70d0c6a456d72f8d96e9de19026 (patch)
tree0eab5d26b3a392a951e1e9614760d62b25640a5f /readmore.js
parent3df7f7a23f0e58f9b96ed87bf65dcda78f8e4b81 (diff)
downloadReadmore.js-1fb6a5674589e70d0c6a456d72f8d96e9de19026.zip
Readmore.js-1fb6a5674589e70d0c6a456d72f8d96e9de19026.tar.gz
Readmore.js-1fb6a5674589e70d0c6a456d72f8d96e9de19026.tar.bz2
Refactor jQuery plugin init so destroy() is called first if Readmore already exists on the element
Diffstat (limited to 'readmore.js')
-rw-r--r--readmore.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/readmore.js b/readmore.js
index 840d82f..e1332e2 100644
--- a/readmore.js
+++ b/readmore.js
@@ -130,6 +130,8 @@
},
destroy: function() {
+ var $this = this;
+
$(this.element).each(function() {
var current = $(this);
@@ -144,9 +146,12 @@
var args = arguments;
if (options === undefined || typeof options === 'object') {
return this.each(function () {
- if (!$.data(this, 'plugin_' + readmore)) {
- $.data(this, 'plugin_' + readmore, new Readmore( this, options ));
+ if ($.data(this, 'plugin_' + readmore)) {
+ var instance = $.data(this, 'plugin_' + readmore);
+ instance['destroy'].apply(instance);
}
+
+ $.data(this, 'plugin_' + readmore, new Readmore( this, options ));
});
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
return this.each(function () {