Skip to content

Commit

Permalink
feat(manager): add destroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
JSteunou committed Sep 20, 2015
1 parent a302b31 commit 7a11749
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Your manager has the following signature :
on: Function,
off: Function,
get: Function, // get a specific joystick
destroy: Function,
options: {
zone: Element,
multitouch: Boolean,
Expand Down Expand Up @@ -164,6 +165,14 @@ An helper to get an instance via its identifier.
manager.get(0);
```

#### `manager.destroy()`

Gently remove all nipples from the DOM and unbind all events.

```javascript
manager.destroy();
```

### nipple instance (joystick)

Each joystick has the following signature :
Expand Down
10 changes: 10 additions & 0 deletions src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var Manager = function (options) {
self.nipples.on = self.on.bind(self);
self.nipples.off = self.off.bind(self);
self.nipples.options = self.options;
self.nipples.destroy = self.destroy.bind(self);
self.nipples.get = function (id) {
for (var i = 0, max = self.nipples.length; i < max; i += 1) {
if (self.nipples[i].identifier === id) {
Expand Down Expand Up @@ -270,3 +271,12 @@ Manager.prototype.processOnEnd = function (evt) {
var index = self.nipples.indexOf(nipple);
self.nipples.splice(index, 1);
};

// Cleanly destroy the manager
Manager.prototype.destroy = function () {
this.off();
this.unbindEvt(this.options.zone, 'start');
this.nipples.forEach(function(nipple) {
nipple.destroy();
});
}

0 comments on commit 7a11749

Please sign in to comment.