eternicode/bootstrap-datepicker — pull request #420 by michaelbrooks (2013-04-03 21:09:36+00:00)
Title: detect click inside picker or input to avoid show/hide

I found that when I set up the date picker on an input element, clicking inside the input once would cause the picker to appear and then clicking on it again would cause the picker to disappear.

If nobody is noticing this, maybe I did not set up my HTML quite right, but I also see this behavior on the [eyecon.ro](http://www.eyecon.ro/bootstrap-datepicker/) date picker (I know this code has diverged from that date picker, but I'm sure they still have much in common). Just try clicking twice on the input element in the first example to see what I mean.

The other possibility is that others consider this desirable behavior, in which case I'm curious about why.

The original behavior on document 'click' events is to check the parents of the target (clicked) element for `.datepicker.datepicker-inline` or `.datepicker.datepicker-dropdown` elements. For me this returns no matches when the target is the input element.

Instead, I decided to explicitly check both this.element (either the input itself or a container for the input in a component construction) and this.picker (the date picker element) to see if they contain the click target. If they do not, then the picker is hidden.

Seems straightforward and it works for me, but I know there may be scenarios for using the date picker that this logic misses.