Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit 7b171c0

Browse files
author
Steve Calvert
committed
Adding destroy method and updating tests to use destroy
1 parent 1606c6d commit 7b171c0

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

dist/bellows.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
this._bindEvents();
5353
},
5454

55+
destroy: function() {
56+
this.$bellows
57+
.removeData(this.name)
58+
.off(this.options.event);
59+
},
60+
5561
_bindEvents: function() {
5662
var plugin = this;
5763

dist/bellows.min.js

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

src/js/bellows.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
this._bindEvents();
5353
},
5454

55+
destroy: function() {
56+
this.$bellows
57+
.removeData(this.name)
58+
.off(this.options.event);
59+
},
60+
5561
_bindEvents: function() {
5662
var plugin = this;
5763

tests/unit/constructor.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ define([
55
'bellows'
66
], function(fixture, $) {
77
var Bellows;
8-
var element;
8+
var $element;
99

1010
describe('Bellows constructor', function() {
1111
beforeEach(function() {
1212
Bellows = $.fn.bellows.Constructor;
13-
element = $(fixture);
13+
$element = $(fixture);
1414
});
1515

1616
it('creates a bellows instance', function() {
17-
var bellows = new Bellows(element);
17+
var bellows = new Bellows($element);
1818

1919
assert.isDefined(bellows);
20+
21+
bellows.destroy();
2022
});
2123
});
2224
});

tests/unit/events.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ define([
44
'velocity',
55
'bellows'
66
], function(fixture, $) {
7-
var element;
7+
var $element;
88

99
describe('Bellows events', function() {
1010
var stringify = JSON.stringify;
@@ -28,35 +28,35 @@ define([
2828
});
2929

3030
beforeEach(function() {
31-
element = $(fixture).appendTo('#container');
31+
$element = $(fixture).appendTo('#container');
3232
});
3333

3434
afterEach(function() {
35-
element = null;
35+
$element.bellows('destroy');
3636
});
3737

3838
it('fires the open event when the header is clicked', function(done) {
39-
element.bellows({
39+
$element.bellows({
4040
open: function() {
4141
done();
4242
}
4343
});
4444

45-
element.find('.bellows__header').first().trigger('click');
45+
$element.find('.bellows__header').first().trigger('click');
4646
});
4747

4848
it('fires the opened event when the header is clicked', function(done) {
49-
element.bellows({
49+
$element.bellows({
5050
opened: function() {
5151
done();
5252
}
5353
});
5454

55-
element.find('.bellows__header').first().trigger('click');
55+
$element.find('.bellows__header').first().trigger('click');
5656
});
5757

5858
it('fires the close event when the header is clicked', function(done) {
59-
element.bellows({
59+
$element.bellows({
6060
opened: function(e, ui) {
6161
ui.item.find('.bellows__header').trigger('click');
6262
},
@@ -65,11 +65,11 @@ define([
6565
}
6666
});
6767

68-
element.find('.bellows__header').first().trigger('click');
68+
$element.find('.bellows__header').first().trigger('click');
6969
});
7070

7171
it('fires the closed event when the header is clicked', function(done) {
72-
element.bellows({
72+
$element.bellows({
7373
opened: function(e, ui) {
7474
ui.item.find('.bellows__header').trigger('click');
7575
},
@@ -78,7 +78,7 @@ define([
7878
}
7979
});
8080

81-
element.find('.bellows__header').first().trigger('click');
81+
$element.find('.bellows__header').first().trigger('click');
8282
});
8383
});
8484
});

0 commit comments

Comments
 (0)