1
1
/*
2
- * jQuery UI Datepicker Lite
3
- *
4
- * Copyright 2010 Marc Grabanski
5
- * Licensed under the MIT license
6
- *
7
- *
8
- * Depends:
9
- * jquery.ui.core.js
10
- * jquery.ui.widget.js
11
- * jquery.ui.position.js
12
- * jquery.ui.button.js
13
- * jquery.date.js
14
- * jquery.tmpl.js
15
- * jquery.ui.datepicker.html
2
+ * Experimental datepicker rewrite to evaluate jquery-tmpl.
3
+ *
4
+ * Based on Marc Grabanski's https://github.com/1Marc/jquery-ui-datepicker-lite
16
5
*/
17
6
( function ( $ , undefined ) {
18
7
@@ -22,35 +11,36 @@ $.widget( "ui.datepicker", {
22
11
_create : function ( ) {
23
12
var self = this ;
24
13
this . date = $ . date ( ) ;
25
- if ( this . element . is ( "input" ) ) {
14
+ if ( this . element . is ( "input" ) ) {
26
15
self . _bind ( {
27
16
click : "open" ,
28
17
// TODO click on picker should not close
29
18
blur : "close"
30
19
} ) ;
31
- this . picker = $ ( "<div/>" ) . insertAfter ( this . element ) . hide ( ) ;
32
- this . picker . css ( {
20
+ this . picker = $ ( "<div/>" ) . insertAfter ( this . element ) . hide ( ) ;
21
+ this . picker . css ( {
33
22
position : "absolute"
34
23
} ) ;
35
24
} else {
36
25
this . inline = true ;
37
26
this . picker = this . element ;
38
27
}
39
- this . picker . delegate ( ".ui-datepicker-prev" , "click" , function ( ) {
40
- self . date . adjust ( "M" , - 1 ) ;
28
+ this . picker . delegate ( ".ui-datepicker-prev" , "click" , function ( ) {
29
+ self . date . adjust ( "M" , - 1 ) ;
41
30
self . refresh ( ) ;
42
31
} ) ;
43
- this . picker . delegate ( ".ui-datepicker-next" , "click" , function ( ) {
44
- self . date . adjust ( "M" , + 1 )
32
+ this . picker . delegate ( ".ui-datepicker-next" , "click" , function ( ) {
33
+ self . date . adjust ( "M" , + 1 )
45
34
self . refresh ( ) ;
46
35
} ) ;
47
- this . picker . delegate ( ".ui-datepicker-calendar a" , "click" , function ( event ) {
48
- self . date . setDay ( + $ ( this ) . text ( ) ) ;
49
- if ( ! self . inline ) {
36
+ this . picker . delegate ( ".ui-datepicker-calendar a" , "click" , function ( event ) {
37
+ // TODO exclude clicks on lead days or handle them correctly
38
+ self . date . setDay ( + $ ( this ) . text ( ) ) ;
39
+ if ( ! self . inline ) {
50
40
self . element . val ( self . date . format ( ) ) ;
51
41
self . close ( ) ;
52
42
}
53
- self . _trigger ( "select" , event , {
43
+ self . _trigger ( "select" , event , {
54
44
date : self . date . format ( ) ,
55
45
} ) ;
56
46
} ) ;
@@ -61,37 +51,29 @@ $.widget( "ui.datepicker", {
61
51
this . date . refresh ( ) ;
62
52
this . picker . empty ( ) ;
63
53
64
- $ ( "#ui-datepicker-tmpl" ) . tmpl ( {
54
+ $ ( "#ui-datepicker-tmpl" ) . tmpl ( {
65
55
date : this . date
66
- } ) . appendTo ( this . picker )
67
- . find ( "button" ) . button ( ) . end ( )
56
+ } ) . appendTo ( this . picker )
57
+ . find ( "button" ) . button ( ) . end ( )
68
58
69
59
// against display:none in datepicker.css
70
- this . picker . find ( ".ui-datepicker" ) . css ( "display" , "block" ) ;
60
+ this . picker . find ( ".ui-datepicker" ) . css ( "display" , "block" ) ;
71
61
this . _hoverable ( this . picker . find ( ".ui-datepicker-header a" ) ) ;
72
62
this . _hoverable ( this . picker . find ( ".ui-datepicker-header a, .ui-datepicker-calendar a" ) ) ;
73
63
} ,
74
- _setOption : function ( key , value ) {
75
- $ . Widget . prototype . _setOption . apply ( this , arguments ) ;
76
- if ( key === "" ) {
77
- }
78
- } ,
79
64
open : function ( event ) {
80
65
this . picker . fadeIn ( "fast" ) ;
81
- // would open ever get called for non-inline datepickers?
82
- if ( ! this . inline ) {
83
- this . picker . position ( {
84
- my : "left top" ,
85
- at : "left bottom" ,
86
- of : this . element
87
- } ) ;
88
- }
66
+ this . picker . position ( {
67
+ my : "left top" ,
68
+ at : "left bottom" ,
69
+ of : this . element
70
+ } ) ;
89
71
} ,
90
72
close : function ( event ) {
91
73
this . picker . fadeOut ( ) ;
92
74
} ,
93
- destroy : function ( ) {
94
- if ( ! this . inline ) {
75
+ _destroy : function ( ) {
76
+ if ( ! this . inline ) {
95
77
this . picker . remove ( ) ;
96
78
}
97
79
} ,
0 commit comments