|
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 */ |
12 | 2 | (function ($, undefined) {
|
13 | 3 | 'use strict';
|
14 | 4 |
|
|
34 | 24 |
|
35 | 25 | self.pending = 0;
|
36 | 26 | self.initialised = false;
|
| 27 | + self.initialState = self.el.clone(true); |
| 28 | + self.el.data('plugin_cascadingDropdown', this); |
37 | 29 | self.originalDropdownItems = self.el.children('option');
|
38 | 30 |
|
39 | 31 | // Init event handlers
|
|
68 | 60 | // Call update
|
69 | 61 | self.update();
|
70 | 62 | },
|
| 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 | + }, |
71 | 68 |
|
72 | 69 | // Enables the dropdown
|
73 | 70 | enable: function() {
|
|
365 | 362 | // Create the instance
|
366 | 363 | var instance = new Dropdown(this, self);
|
367 | 364 |
|
368 |
| - // Assign it to the element as a data property |
369 |
| - $(this.selector, self.el).data('plugin_cascadingDropdown', instance); |
370 |
| - |
371 | 365 | // Insert it into the dropdown instance array
|
372 | 366 | self.dropdowns.push(instance);
|
373 | 367 |
|
374 | 368 | // Call the create method
|
375 | 369 | instance._create();
|
376 | 370 | });
|
377 | 371 | },
|
| 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 | + }, |
378 | 382 |
|
379 | 383 | // Fetches the values from all dropdowns in this group
|
380 | 384 | getValues: function() {
|
|
0 commit comments