Skip to content

Commit 7a11749

Browse files
committed
feat(manager): add destroy method
1 parent a302b31 commit 7a11749

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Your manager has the following signature :
122122
on: Function,
123123
off: Function,
124124
get: Function, // get a specific joystick
125+
destroy: Function,
125126
options: {
126127
zone: Element,
127128
multitouch: Boolean,
@@ -164,6 +165,14 @@ An helper to get an instance via its identifier.
164165
manager.get(0);
165166
```
166167

168+
#### `manager.destroy()`
169+
170+
Gently remove all nipples from the DOM and unbind all events.
171+
172+
```javascript
173+
manager.destroy();
174+
```
175+
167176
### nipple instance (joystick)
168177

169178
Each joystick has the following signature :

src/manager.js

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var Manager = function (options) {
1111
self.nipples.on = self.on.bind(self);
1212
self.nipples.off = self.off.bind(self);
1313
self.nipples.options = self.options;
14+
self.nipples.destroy = self.destroy.bind(self);
1415
self.nipples.get = function (id) {
1516
for (var i = 0, max = self.nipples.length; i < max; i += 1) {
1617
if (self.nipples[i].identifier === id) {
@@ -270,3 +271,12 @@ Manager.prototype.processOnEnd = function (evt) {
270271
var index = self.nipples.indexOf(nipple);
271272
self.nipples.splice(index, 1);
272273
};
274+
275+
// Cleanly destroy the manager
276+
Manager.prototype.destroy = function () {
277+
this.off();
278+
this.unbindEvt(this.options.zone, 'start');
279+
this.nipples.forEach(function(nipple) {
280+
nipple.destroy();
281+
});
282+
}

0 commit comments

Comments
 (0)