meltingice/ajax-chosen — pull request #63 by michaelperrin (2013-07-25 13:01:00+00:00)
Title: Feature/jquery plugin structure

Hi Ryan,

It's been a little why I didn't contribute to your project!
I'm now back with this apparently pretty big pull request that restructures your plugin for more flexibility.

I transformed the plugin to something that looks more like a standard jQuery plugin (see for example http://jqueryboilerplate.com/) and I split the whole main function into smaller pieces, making things easier to understand.

There are now 3 main methods:

* A `constructor` method that instantiates the plugin for a given `select` element (the constructor is called for each select element corresponding to the selector the plugin is called on)
* A `update_list` method that is called each time a change has been done in the search field
* A `show_results` method that displays the results after an AJAX call has been made.

There is one more method which is called `register_observers` that register observers to call the `update_list` method.

This allowed me to add a small new feature: **the `minTermLength` parameter can now be set to 0** so that a search is made even at the first click on the Chosen element.

It seems really big code change but don't be afraid, it's mostly about blocks cut & pasted.

**All backward compatibility is preserved** and all compiled files have been generated (JS, minified JS) using `cake`.

If you have any concerns about code structure, naming conventions or anything else, feel free to ask!

And sorry about previous commits shown in this PR, this is because I changed my username.