eternicode/bootstrap-datepicker — pull request #389 by angelyordanov (2013-03-11 16:46:13+00:00)
Title: Bind to events only when the picker is shown. (fixes a memory leak)

Right now the datepicker ALWAYS binds to the document mousedown event upon initialization and never unbinds from it, even when 'remove' method is called.

This creates a nasty memory leak if one is creating/removing datepickers which is the case with any single page application using it(mine included).

I've also noticed that on slow computers with IE8 having 10+ datepickers on a single page makes the page unusable as on every click those 10+ mousedown handlers are executed traversing the DOM looking for the closest datepicker.

I've changed the event binding/unbinding for the document and picker events to be done on show/hide so that those events are listened to only when needed.

I've also scoped the events with the '.picker' namespace to ease unbinding.

Thanks!