harvesthq/chosen — pull request #1379 by koenpunt (2013-07-20 22:29:25+00:00)
Title: Feature: Destroy method

As requested in #133 and #1127, a method to destroy the Chosen instance and restore the original ``.

#### Usage:

In jQuery you can destroy the instance using the `destroy` api function:
```javascript
$('#chzn-select').chosen({});

...

$('#chzn-select').chosen('destroy');
```

For the prototype version you use the objects destroy method:

```javascript
var chosen = new Chosen($('chzn-select'), {});

...

chosen.destroy();
```

#### Info

I've removed the `chzn-done` class adding and the jQuery version now checks for the existence of Chosen in the element's `data('chosen')`.

For the destroy method to work easily I've added a namespace to all the events in the jQuery version so unbinding is just a matter of unbinding the namespace. (`@container.unbind('.chosen')`)

Also, there was some ugly event forwarding in the prototype version to keep context:
```coffeescript
@container.observe "mousedown", (evt) => this.container_mousedown(evt)
```

Which I replaced with prototype's `Function#bind`:
```coffeescript
@container.observe "mousedown", this.container_mousedown.bind(this)
```

_I know, in coffeescript it doesn't look like a big change but in the resulting javascript it is._