Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 8a15da2

Browse files
committed
Added .destroy() method.
* Resolves #47.
1 parent ba53523 commit 8a15da2

File tree

4 files changed

+39
-33
lines changed

4 files changed

+39
-33
lines changed

dist/jquery.cascadingdropdown.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
/*!
2-
* jQuery Cascading Dropdown Plugin 1.2.6
3-
* https://github.com/dnasir/jquery-cascading-dropdown
4-
*
5-
* Copyright 2015, Dzulqarnain Nasir
6-
* http://dnasir.com
7-
*
8-
* Licensed under the MIT license:
9-
* http://www.opensource.org/licenses/MIT
10-
*/
11-
1+
/*! jquery-cascading-dropdown 1.2.7 | (c) 2016 Dzulqarnain Nasir <[email protected]> | MIT */
122
(function ($, undefined) {
133
'use strict';
144

@@ -34,6 +24,8 @@
3424

3525
self.pending = 0;
3626
self.initialised = false;
27+
self.initialState = self.el.clone(true);
28+
self.el.data('plugin_cascadingDropdown', this);
3729
self.originalDropdownItems = self.el.children('option');
3830

3931
// Init event handlers
@@ -68,6 +60,11 @@
6860
// Call update
6961
self.update();
7062
},
63+
64+
// Destroys the instance and reverts everything back to initial state
65+
_destroy: function() {
66+
this.el.replaceWith(this.initialState).removeData('plugin_cascadingDropdown');
67+
},
7168

7269
// Enables the dropdown
7370
enable: function() {
@@ -365,16 +362,23 @@
365362
// Create the instance
366363
var instance = new Dropdown(this, self);
367364

368-
// Assign it to the element as a data property
369-
$(this.selector, self.el).data('plugin_cascadingDropdown', instance);
370-
371365
// Insert it into the dropdown instance array
372366
self.dropdowns.push(instance);
373367

374368
// Call the create method
375369
instance._create();
376370
});
377371
},
372+
373+
// Destroys the instance and reverts everything back to its initial state
374+
destroy: function() {
375+
$.each(this.dropdowns, function(index, item){
376+
item._destroy();
377+
});
378+
this.el.removeData('plugin_cascadingDropdown');
379+
380+
return this.el;
381+
},
378382

379383
// Fetches the values from all dropdowns in this group
380384
getValues: function() {

dist/jquery.cascadingdropdown.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)