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

Commit b5af88c

Browse files
committed
Merge pull request #57 from dnasir/Issue#47
Issue#47
2 parents ba53523 + 12bc6ce commit b5af88c

7 files changed

+56
-42
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-cascading-dropdown",
3-
"version": "1.2.6",
3+
"version": "1.2.7",
44
"homepage": "https://github.com/dnasir/jquery-cascading-dropdown",
55
"authors": [
66
"Dzulqarnain Nasir <[email protected]>"

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.

dist/jquery.cascadingdropdown.min.js.map

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

gulpfile.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
var gulp = require('gulp');
2-
var uglifyjs = require('gulp-uglifyjs');
2+
var uglify = require('gulp-uglify');
33
var header = require('gulp-header');
4+
var sourcemaps = require('gulp-sourcemaps');
5+
var rename = require('gulp-rename');
46
var pkg = require('./package.json');
57

6-
var banner = '/*! <%= pkg.name %> <%= pkg.version %> | (c) 2015 <%= pkg.author %> | <%= pkg.license %> */\n';
8+
var year = new Date().getFullYear();
9+
var banner = '/*! <%= pkg.name %> <%= pkg.version %> | (c) ' + year + ' <%= pkg.author %> | <%= pkg.license %> */\n';
710

811
gulp.task('js', function() {
912
gulp.src('src/jquery.cascadingdropdown.js')
10-
.pipe(gulp.dest('dist/'))
11-
.pipe(uglifyjs('jquery.cascadingdropdown.min.js', { outSourceMap: true }))
1213
.pipe(header(banner, { pkg: pkg }))
14+
.pipe(gulp.dest('dist/'))
15+
.pipe(rename('jquery.cascadingdropdown.min.js'))
16+
.pipe(sourcemaps.init())
17+
.pipe(uglify({ preserveComments: 'license' }))
18+
.pipe(sourcemaps.write('./'))
1319
.pipe(gulp.dest('dist/'));
1420
});
1521

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-cascading-dropdown",
3-
"version": "1.2.6",
3+
"version": "1.2.7",
44
"description": "A simple and lighweight jQuery plugin for creating cascading dropdowns.",
55
"main": "dist/jquery.cascadingdropdown.js",
66
"scripts": {
@@ -23,8 +23,10 @@
2323
"homepage": "https://github.com/dnasir/jquery-cascading-dropdown",
2424
"dependencies": {},
2525
"devDependencies": {
26-
"gulp": "~3.8.11",
27-
"gulp-uglifyjs": "~0.6.1",
28-
"gulp-header": "~1.2.2"
26+
"gulp": "^3.9.1",
27+
"gulp-uglify": "^1.5.3",
28+
"gulp-header": "^1.7.1",
29+
"gulp-sourcemaps": "^1.6.0",
30+
"gulp-rename": "^1.2.2"
2931
}
3032
}

src/jquery.cascadingdropdown.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
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-
121
(function ($, undefined) {
132
'use strict';
143

@@ -34,6 +23,8 @@
3423

3524
self.pending = 0;
3625
self.initialised = false;
26+
self.initialState = self.el.clone(true);
27+
self.el.data('plugin_cascadingDropdown', this);
3728
self.originalDropdownItems = self.el.children('option');
3829

3930
// Init event handlers
@@ -68,6 +59,11 @@
6859
// Call update
6960
self.update();
7061
},
62+
63+
// Destroys the instance and reverts everything back to initial state
64+
_destroy: function() {
65+
this.el.replaceWith(this.initialState).removeData('plugin_cascadingDropdown');
66+
},
7167

7268
// Enables the dropdown
7369
enable: function() {
@@ -365,16 +361,23 @@
365361
// Create the instance
366362
var instance = new Dropdown(this, self);
367363

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

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

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

0 commit comments

Comments
 (0)