@@ -16,6 +16,7 @@ $.extend($.ui, { datepicker: { version: "@VERSION" } });
16
16
17
17
var PROP_NAME = 'datepicker' ;
18
18
var dpuuid = new Date ( ) . getTime ( ) ;
19
+ var instActive ;
19
20
20
21
/* Date picker manager.
21
22
Use the singleton instance of this class, $.datepicker, to interact with the date picker.
@@ -107,7 +108,7 @@ function Datepicker() {
107
108
autoSize : false // True to size the input for the date format, false to leave as is
108
109
} ;
109
110
$ . extend ( this . _defaults , this . regional [ '' ] ) ;
110
- this . dpDiv = $ ( '<div id="' + this . _mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>' ) ;
111
+ this . dpDiv = bindHover ( $ ( '<div id="' + this . _mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>' ) ) ;
111
112
}
112
113
113
114
$ . extend ( Datepicker . prototype , {
@@ -173,7 +174,7 @@ $.extend(Datepicker.prototype, {
173
174
drawMonth : 0 , drawYear : 0 , // month being drawn
174
175
inline : inline , // is datepicker inline or not
175
176
dpDiv : ( ! inline ? this . dpDiv : // presentation div
176
- $ ( '<div class="' + this . _inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>' ) ) } ;
177
+ bindHover ( $ ( '<div class="' + this . _inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>' ) ) ) } ;
177
178
} ,
178
179
179
180
/* Attach the date picker to an input field. */
@@ -674,29 +675,13 @@ $.extend(Datepicker.prototype, {
674
675
_updateDatepicker : function ( inst ) {
675
676
var self = this ;
676
677
var borders = $ . datepicker . _getBorders ( inst . dpDiv ) ;
678
+ instActive = inst ; // for delegate hover events
677
679
inst . dpDiv . empty ( ) . append ( this . _generateHTML ( inst ) ) ;
678
680
var cover = inst . dpDiv . find ( 'iframe.ui-datepicker-cover' ) ; // IE6- only
679
681
if ( ! ! cover . length ) { //avoid call to outerXXXX() when not in IE6
680
682
cover . css ( { left : - borders [ 0 ] , top : - borders [ 1 ] , width : inst . dpDiv . outerWidth ( ) , height : inst . dpDiv . outerHeight ( ) } )
681
683
}
682
- inst . dpDiv . find ( 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a' )
683
- . bind ( 'mouseout' , function ( ) {
684
- $ ( this ) . removeClass ( 'ui-state-hover' ) ;
685
- if ( this . className . indexOf ( 'ui-datepicker-prev' ) != - 1 ) $ ( this ) . removeClass ( 'ui-datepicker-prev-hover' ) ;
686
- if ( this . className . indexOf ( 'ui-datepicker-next' ) != - 1 ) $ ( this ) . removeClass ( 'ui-datepicker-next-hover' ) ;
687
- } )
688
- . bind ( 'mouseover' , function ( ) {
689
- if ( ! self . _isDisabledDatepicker ( inst . inline ? inst . dpDiv . parent ( ) [ 0 ] : inst . input [ 0 ] ) ) {
690
- $ ( this ) . parents ( '.ui-datepicker-calendar' ) . find ( 'a' ) . removeClass ( 'ui-state-hover' ) ;
691
- $ ( this ) . addClass ( 'ui-state-hover' ) ;
692
- if ( this . className . indexOf ( 'ui-datepicker-prev' ) != - 1 ) $ ( this ) . addClass ( 'ui-datepicker-prev-hover' ) ;
693
- if ( this . className . indexOf ( 'ui-datepicker-next' ) != - 1 ) $ ( this ) . addClass ( 'ui-datepicker-next-hover' ) ;
694
- }
695
- } )
696
- . end ( )
697
- . find ( '.' + this . _dayOverClass + ' a' )
698
- . trigger ( 'mouseover' )
699
- . end ( ) ;
684
+ inst . dpDiv . find ( '.' + this . _dayOverClass + ' a' ) . mouseover ( ) ;
700
685
var numMonths = this . _getNumberOfMonths ( inst ) ;
701
686
var cols = numMonths [ 1 ] ;
702
687
var width = 17 ;
@@ -1719,6 +1704,28 @@ $.extend(Datepicker.prototype, {
1719
1704
}
1720
1705
} ) ;
1721
1706
1707
+ /*
1708
+ * Bind hover events for datepicker elements.
1709
+ * Done via delegate so the binding only occurs once in the lifetime of the parent div.
1710
+ * Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
1711
+ */
1712
+ function bindHover ( dpDiv ) {
1713
+ var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a' ;
1714
+ return dpDiv . delegate ( selector , 'mouseout' , function ( ) {
1715
+ $ ( this ) . removeClass ( 'ui-state-hover' ) ;
1716
+ if ( this . className . indexOf ( 'ui-datepicker-prev' ) != - 1 ) $ ( this ) . removeClass ( 'ui-datepicker-prev-hover' ) ;
1717
+ if ( this . className . indexOf ( 'ui-datepicker-next' ) != - 1 ) $ ( this ) . removeClass ( 'ui-datepicker-next-hover' ) ;
1718
+ } )
1719
+ . delegate ( selector , 'mouseover' , function ( ) {
1720
+ if ( ! $ . datepicker . _isDisabledDatepicker ( instActive . inline ? dpDiv . parent ( ) [ 0 ] : instActive . input [ 0 ] ) ) {
1721
+ $ ( this ) . parents ( '.ui-datepicker-calendar' ) . find ( 'a' ) . removeClass ( 'ui-state-hover' ) ;
1722
+ $ ( this ) . addClass ( 'ui-state-hover' ) ;
1723
+ if ( this . className . indexOf ( 'ui-datepicker-prev' ) != - 1 ) $ ( this ) . addClass ( 'ui-datepicker-prev-hover' ) ;
1724
+ if ( this . className . indexOf ( 'ui-datepicker-next' ) != - 1 ) $ ( this ) . addClass ( 'ui-datepicker-next-hover' ) ;
1725
+ }
1726
+ } ) ;
1727
+ }
1728
+
1722
1729
/* jQuery extend now ignores nulls! */
1723
1730
function extendRemove ( target , props ) {
1724
1731
$ . extend ( target , props ) ;
0 commit comments