Skip to content

Commit

Permalink
using mouseover and mouseout to determine if input parsing should be …
Browse files Browse the repository at this point in the history
…done instead of document.body
  • Loading branch information
Alex Vernacchia committed Dec 13, 2013
1 parent c201d2b commit 4af8aa4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ define(function (require) {
this.stagedDate = new Date();
}

this.elementClicked = null;
this.inputParsingTarget = null;

this.viewDate.setHours( 0,0,0,0 );
this.stagedDate.setHours( 0,0,0,0 );
Expand Down Expand Up @@ -563,6 +563,7 @@ define(function (require) {
},

_select: function( e ) {
this.inputParsingTarget = null;
if( e.target.className.indexOf( 'restrict' ) > -1 ) {
return this._killEvent(e);
} else {
Expand Down Expand Up @@ -826,7 +827,7 @@ define(function (require) {
this.$element.find('input[type="text"]').val( displayDate );
},

_inputDateParsing: function( e ) {
_inputDateParsing: function() {
// the formats we support when using moment.js are either "L" or "l"
// these can be found here http://momentjs.com/docs/#/customization/long-date-formats/
var inputValue = this.$input.val();
Expand Down Expand Up @@ -886,17 +887,18 @@ define(function (require) {

_addBindings: function() {
var self = this;

// parsing dates on user input is only available when momentjs is used
if( Boolean( this.moment ) ) {
$(document.body).on( 'mousedown', function( mousedownEvent ) {
if( self.$calendar.find( mousedownEvent.target ).length > 0 ) {
self.elementClicked = 'calendar';
} else {
self.elementClicked = null;
}
this.$calendar.on( 'mouseover', function() {
self.inputParsingTarget = 'calendar';
});
this.$calendar.on( 'mouseout', function() {
self.inputParsingTarget = null;
});

this.$input.on( 'blur', function() {
if( self.elementClicked === null ) {
if( self.inputParsingTarget === null ) {
self._inputDateParsing();
}
});
Expand All @@ -922,6 +924,8 @@ define(function (require) {
_removeBindings: function() {
// remove event only if moment is available (meaning it was initialized in the first place)
if( Boolean( this.moment ) ) {
this.$calendar.off( 'mouseover' );
this.$calendar.off( 'mouseout' );
this.$input.off( 'blur' );
}

Expand Down

0 comments on commit 4af8aa4

Please sign in to comment.