@@ -21,58 +21,82 @@ $.widget( "ui.datepicker", {
21
21
} ,
22
22
_create : function ( ) {
23
23
var self = this ;
24
- self . element
25
- . bind ( "mousedown.datepicker" , function ( event ) {
26
- self . open ( ) ;
27
- } )
28
- . bind ( "keydown.datepicker" , function ( event ) {
29
-
30
- } ) ;
31
24
this . date = $ . date ( ) ;
32
25
if ( this . element . is ( "input" ) ) {
26
+ self . _bind ( {
27
+ click : "open" ,
28
+ // TODO click on picker should not close
29
+ blur : "close"
30
+ } ) ;
33
31
this . picker = $ ( "<div/>" ) . insertAfter ( this . element ) . hide ( ) ;
32
+ this . picker . css ( {
33
+ position : "absolute"
34
+ } ) ;
34
35
} else {
35
36
this . inline = true ;
36
37
this . picker = this . element ;
37
38
}
39
+ this . picker . delegate ( ".ui-datepicker-prev" , "click" , function ( ) {
40
+ self . date . adjust ( "M" , - 1 ) ;
41
+ self . refresh ( ) ;
42
+ } ) ;
43
+ this . picker . delegate ( ".ui-datepicker-next" , "click" , function ( ) {
44
+ self . date . adjust ( "M" , + 1 )
45
+ self . refresh ( ) ;
46
+ } ) ;
47
+ this . picker . delegate ( ".ui-datepicker-calendar a" , "click" , function ( event ) {
48
+ self . date . setDay ( + $ ( this ) . text ( ) ) ;
49
+ if ( ! self . inline ) {
50
+ self . element . val ( self . date . format ( ) ) ;
51
+ self . close ( ) ;
52
+ }
53
+ self . _trigger ( "select" , event , {
54
+ date : self . date . format ( ) ,
55
+ } ) ;
56
+ } ) ;
57
+
38
58
this . refresh ( ) ;
39
59
} ,
40
60
refresh : function ( ) {
61
+ this . date . refresh ( ) ;
41
62
this . picker . empty ( ) ;
42
- // TODO wrapper div get losts when appending to new element, works for inline
43
- $ ( "#ui-datepicker-div " ) . tmpl ( {
63
+
64
+ $ ( "#ui-datepicker-tmpl " ) . tmpl ( {
44
65
date : this . date
45
66
} ) . appendTo ( this . picker )
46
- . find ( "button" ) . button ( ) . end ( )
47
- // looks uglyyy
48
- //.find(".ui-datepicker-header a").button();
49
- if ( this . inline ) {
50
- // against display:none in datepicker.css
51
- this . picker . find ( ".ui-datepicker" ) . css ( "display" , "block" ) ;
52
- }
67
+ . find ( "button" ) . button ( ) . end ( )
68
+
69
+ // against display:none in datepicker.css
70
+ this . picker . find ( ".ui-datepicker" ) . css ( "display" , "block" ) ;
71
+ this . _hoverable ( this . picker . find ( ".ui-datepicker-header a" ) ) ;
72
+ this . _hoverable ( this . picker . find ( ".ui-datepicker-header a, .ui-datepicker-calendar a" ) ) ;
53
73
} ,
54
74
_setOption : function ( key , value ) {
55
75
$ . Widget . prototype . _setOption . apply ( this , arguments ) ;
56
76
if ( key === "" ) {
57
77
}
58
78
} ,
59
79
open : function ( event ) {
60
- this . picker . show ( ) ;
61
- /*
62
- if (this.picker != this.element ) {
80
+ this . picker . fadeIn ( "fast" ) ;
81
+ // would open ever get called for non-inline datepickers?
82
+ if ( ! this . inline ) {
63
83
this . picker . position ( {
84
+ my : "left top" ,
85
+ at : "left bottom" ,
64
86
of : this . element
65
87
} ) ;
66
88
}
67
- */
68
89
} ,
69
90
close : function ( event ) {
70
- this . picker . hide ( ) ;
91
+ this . picker . fadeOut ( ) ;
71
92
} ,
72
93
destroy : function ( ) {
94
+ if ( ! this . inline ) {
95
+ this . picker . remove ( ) ;
96
+ }
73
97
} ,
74
98
widget : function ( ) {
75
- return this . element ;
99
+ return this . picker ;
76
100
}
77
101
} ) ;
78
102
0 commit comments