ivaynberg/select2 — pull request #764 by jpurcell001 (2013-01-28 20:05:59+00:00)
Title: Adding defensive check during the document mousedown/touchend event handler.

There is currently a global listener (not bound to the lifecycle of any particular select2 control). This handler was throwing an error if the select2 control did not exist by the time processing occurred - for example, if select2("destroy") was called first.

Feels like this event handler should perhaps not be global and instead be bound to each individual select2 instance, and automatically removed on calls to select2.destroy, but wasn't sure from code inspection what side effect this might have.

Solution to avoid throwing the error was to add a defensive check in the event handler to first ensure that the target.data("select2") was not empty before proceeding.