2
2
* jQuery timepicker addon
3
3
* By: Trent Richardson [http://trentrichardson.com]
4
4
* Version 0.8.1
5
- * Last Modified: 11/15 /2010 by Charles Phillips
5
+ * Last Modified: 11/18 /2010 by Charles Phillips
6
6
*
7
7
* Copyright 2010 Trent Richardson
8
8
* Dual licensed under the MIT and GPL licenses.
@@ -89,6 +89,58 @@ $.extend(Timepicker.prototype, {
89
89
return this ;
90
90
} ,
91
91
92
+ //########################################################################
93
+ // Create a new Timepicker instance
94
+ //########################################################################
95
+ _newInst : function ( $input , o ) {
96
+ var tp_inst = new Timepicker ( ) ,
97
+ inlineSettings = { } ;
98
+
99
+ for ( var attrName in tp_inst . _defaults ) {
100
+ var attrValue = $input . attr ( 'time:' + attrName ) ;
101
+ if ( attrValue ) {
102
+ try {
103
+ inlineSettings [ attrName ] = eval ( attrValue ) ;
104
+ } catch ( err ) {
105
+ inlineSettings [ attrName ] = attrValue ;
106
+ }
107
+ }
108
+ }
109
+ tp_inst . _defaults = $ . extend ( { } , tp_inst . _defaults , inlineSettings , o , {
110
+ beforeShow : function ( input , dp_inst ) {
111
+ tp_inst . hour = tp_inst . _defaults . hour ;
112
+ tp_inst . minute = tp_inst . _defaults . minute ;
113
+ tp_inst . second = tp_inst . _defaults . second ;
114
+ tp_inst . ampm = '' ;
115
+ tp_inst . $input = $ ( input ) ;
116
+ if ( o . altField )
117
+ tp_inst . $altInput = $ ( $ . datepicker . _get ( dp_inst , 'altField' ) )
118
+ . css ( { cursor : 'pointer' } )
119
+ . focus ( function ( ) {
120
+ $input . trigger ( "focus" ) ;
121
+ } ) ;
122
+ tp_inst . inst = dp_inst ;
123
+ tp_inst . _addTimePicker ( ) ;
124
+ if ( $ . isFunction ( o . beforeShow ) )
125
+ o . beforeShow ( input , dp_inst ) ;
126
+ } ,
127
+ onChangeMonthYear : function ( year , month , dp_inst ) {
128
+ // Update the time as well : this prevents the time from disappearing from the $input field.
129
+ tp_inst . _updateDateTime ( dp_inst ) ;
130
+ if ( $ . isFunction ( o . onChangeMonthYear ) )
131
+ o . onChangeMonthYear ( year , month , dp_inst ) ;
132
+ } ,
133
+ onClose : function ( dateText , dp_inst ) {
134
+ if ( tp_inst . timeDefined === true && $input . val ( ) != '' )
135
+ tp_inst . _updateDateTime ( dp_inst ) ;
136
+ if ( $ . isFunction ( o . onClose ) )
137
+ o . onClose ( dateText , dp_inst ) ;
138
+ } ,
139
+ timepicker : tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
140
+ } ) ;
141
+ return tp_inst ;
142
+ } ,
143
+
92
144
//########################################################################
93
145
// add our sliders to the calendar
94
146
//########################################################################
@@ -361,7 +413,7 @@ $.extend(Timepicker.prototype, {
361
413
}
362
414
363
415
var $buttonPanel = $dp . find ( '.ui-datepicker-buttonpane' ) ;
364
- if ( buttonPanel . length ) $buttonPanel . before ( $tp ) ;
416
+ if ( $ buttonPanel. length ) $buttonPanel . before ( $tp ) ;
365
417
else $dp . append ( $tp ) ;
366
418
367
419
this . $timeObj = $ ( '#ui_tpicker_time_' + dp_id ) ;
@@ -475,10 +527,10 @@ $.fn.extend({
475
527
o = o || { } ;
476
528
var tmp_args = arguments ;
477
529
478
- if ( typeof o == 'object' ) o = $ . extend ( o , { timeOnly : true } ) ;
530
+ if ( typeof o == 'object' ) tmp_args [ 0 ] = $ . extend ( o , { timeOnly : true } ) ;
479
531
480
532
return this . each ( function ( ) {
481
- $ ( this ) . datetimepicker ( o , tmp_args [ 1 ] , tmp_args [ 2 ] , tmp_args [ 3 ] , tmp_args [ 4 ] ) ;
533
+ $ . fn . datepicker . apply ( this , tmp_args ) ;
482
534
} ) ;
483
535
} ,
484
536
@@ -490,70 +542,14 @@ $.fn.extend({
490
542
var $input = this ,
491
543
tmp_args = arguments ;
492
544
493
- if ( typeof ( o ) == 'string' ) {
494
- if ( o == 'setDate' ) return this . each ( function ( ) {
495
- $ ( this ) . datepicker ( o , tmp_args [ 1 ] ) ;
496
- } ) ;
497
- else if ( o == 'option' && typeof ( tmp_args [ 1 ] ) == 'string' ) return this . each ( function ( ) {
498
- $ ( this ) . datepicker ( o , tmp_args [ 1 ] , tmp_args [ 2 ] ) ;
499
- } ) ;
500
- else if ( o == 'dialog' ) return this . each ( function ( ) {
501
- $ ( this ) . datepicker ( o , tmp_args [ 1 ] , tmp_args [ 2 ] , tmp_args [ 3 ] , tmp_args [ 4 ] ) ;
502
- } ) ;
503
- else return this . each ( function ( ) {
504
- $ ( this ) . datepicker ( o ) ;
505
- } ) ;
506
- } else {
507
- var tp_inst = new Timepicker ( ) ,
508
- inlineSettings = { } ;
509
-
510
- for ( var attrName in tp_inst . _defaults ) {
511
- var attrValue = $input . attr ( 'time:' + attrName ) ;
512
- if ( attrValue ) {
513
- try {
514
- inlineSettings [ attrName ] = eval ( attrValue ) ;
515
- } catch ( err ) {
516
- inlineSettings [ attrName ] = attrValue ;
517
- }
518
- }
519
- }
520
- tp_inst . _defaults = $ . extend ( { } , tp_inst . _defaults , inlineSettings , o , {
521
- beforeShow : function ( input , dp_inst ) {
522
- tp_inst . hour = tp_inst . _defaults . hour ;
523
- tp_inst . minute = tp_inst . _defaults . minute ;
524
- tp_inst . second = tp_inst . _defaults . second ;
525
- tp_inst . ampm = '' ;
526
- tp_inst . $input = $ ( input ) ;
527
- if ( o . altField )
528
- tp_inst . $altInput = $ ( $ . datepicker . _get ( dp_inst , 'altField' ) )
529
- . css ( { cursor : 'pointer' } )
530
- . focus ( function ( ) {
531
- $input . trigger ( "focus" ) ;
532
- } ) ;
533
- tp_inst . inst = dp_inst ;
534
- tp_inst . _addTimePicker ( ) ;
535
- if ( $ . isFunction ( o . beforeShow ) )
536
- o . beforeShow ( input , dp_inst ) ;
537
- } ,
538
- onChangeMonthYear : function ( year , month , dp_inst ) {
539
- // Update the time as well : this prevents the time from disappearing from the $input field.
540
- tp_inst . _updateDateTime ( dp_inst ) ;
541
- if ( $ . isFunction ( o . onChangeMonthYear ) )
542
- o . onChangeMonthYear ( year , month , dp_inst ) ;
543
- } ,
544
- onClose : function ( dateText , dp_inst ) {
545
- if ( tp_inst . timeDefined === true && $input . val ( ) != '' )
546
- tp_inst . _updateDateTime ( dp_inst ) ;
547
- if ( $ . isFunction ( o . onClose ) )
548
- o . onClose ( dateText , dp_inst ) ;
549
- } ,
550
- timepicker : tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
545
+ if ( typeof ( o ) == 'string' )
546
+ return this . each ( function ( ) {
547
+ $ . fn . datepicker . apply ( this , tmp_args ) ;
551
548
} ) ;
552
-
549
+ else
553
550
return this . each ( function ( ) {
554
- $ ( this ) . datepicker ( tp_inst . _defaults ) ;
551
+ $ ( this ) . datepicker ( $ . timepicker . _newInst ( $input , o ) . _defaults ) ;
555
552
} ) ;
556
- }
557
553
}
558
554
} ) ;
559
555
@@ -716,7 +712,7 @@ $.datepicker._getDate = function(inst) {
716
712
function extendRemove ( target , props ) {
717
713
$ . extend ( target , props ) ;
718
714
for ( var name in props )
719
- if ( props [ name ] == null || props [ name ] == undefined )
715
+ if ( props [ name ] === null || props [ name ] = == undefined )
720
716
target [ name ] = props [ name ] ;
721
717
return target ;
722
718
}
@@ -725,4 +721,3 @@ $.timepicker = new Timepicker(); // singleton instance
725
721
$ . timepicker . version = "0.8.1" ;
726
722
727
723
} ) ( jQuery ) ;
728
-
0 commit comments