@@ -65,7 +65,8 @@ function Timepicker() {
65
65
secondGrid : 0 ,
66
66
alwaysSetTime : true ,
67
67
separator : ' ' ,
68
- altFieldTimeOnly : true
68
+ altFieldTimeOnly : true ,
69
+ showTimepicker : true
69
70
} ;
70
71
$ . extend ( this . _defaults , this . regional [ '' ] ) ;
71
72
}
@@ -125,31 +126,30 @@ $.extend(Timepicker.prototype, {
125
126
}
126
127
}
127
128
tp_inst . _defaults = $ . extend ( { } , this . _defaults , inlineSettings , o , {
128
- beforeShow : function ( input , dp_inst ) {
129
- if ( o . altField )
130
- tp_inst . $altInput = $ ( $ . datepicker . _get ( dp_inst , 'altField' ) )
131
- . css ( { cursor : 'pointer' } )
132
- . focus ( function ( ) {
133
- $input . trigger ( "focus" ) ;
134
- } ) ;
129
+ beforeShow : function ( input , dp_inst ) {
135
130
if ( $ . isFunction ( o . beforeShow ) )
136
- o . beforeShow ( input , dp_inst ) ;
131
+ o . beforeShow ( input , dp_inst , tp_inst ) ;
137
132
} ,
138
133
onChangeMonthYear : function ( year , month , dp_inst ) {
139
134
// Update the time as well : this prevents the time from disappearing from the $input field.
140
135
tp_inst . _updateDateTime ( dp_inst ) ;
141
136
if ( $ . isFunction ( o . onChangeMonthYear ) )
142
- o . onChangeMonthYear ( year , month , dp_inst ) ;
137
+ o . onChangeMonthYear ( year , month , dp_inst , tp_inst ) ;
143
138
} ,
144
139
onClose : function ( dateText , dp_inst ) {
145
140
if ( tp_inst . timeDefined === true && $input . val ( ) != '' )
146
141
tp_inst . _updateDateTime ( dp_inst ) ;
147
142
if ( $ . isFunction ( o . onClose ) )
148
- o . onClose ( dateText , dp_inst ) ;
143
+ o . onClose ( dateText , dp_inst , tp_inst ) ;
149
144
} ,
150
145
timepicker : tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
151
146
} ) ;
152
147
148
+ if ( o . altField )
149
+ tp_inst . $altInput = $ ( o . altField )
150
+ . css ( { cursor : 'pointer' } )
151
+ . focus ( function ( ) { $input . trigger ( "focus" ) ; } ) ;
152
+
153
153
// datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
154
154
if ( tp_inst . _defaults . minDate !== undefined && tp_inst . _defaults . minDate instanceof Date )
155
155
tp_inst . _defaults . minDateTime = new Date ( tp_inst . _defaults . minDate . getTime ( ) ) ;
@@ -195,7 +195,7 @@ $.extend(Timepicker.prototype, {
195
195
// the time should come after x number of characters and a space.
196
196
// x = at least the length of text specified by the date format
197
197
var dp_dateFormat = $ . datepicker . _get ( this . inst , 'dateFormat' ) ;
198
- regstr = '.{' + dp_dateFormat . length + ',}\\s* ' + this . _defaults . separator . replace ( / \s / g , '\\s?' ) + regstr ;
198
+ regstr = '.{' + dp_dateFormat . length + ',}' + this . _defaults . separator + regstr ;
199
199
}
200
200
201
201
treg = timeString . match ( new RegExp ( regstr , 'i' ) ) ;
@@ -254,7 +254,8 @@ $.extend(Timepicker.prototype, {
254
254
dp_id = this . inst . id . toString ( ) . replace ( / ( [ ^ A - Z a - z 0 - 9 _ ] ) / g, '' ) ;
255
255
256
256
// Prevent displaying twice
257
- if ( $dp . find ( "div#ui-timepicker-div-" + dp_id ) . length === 0 ) {
257
+ //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
258
+ if ( $dp . find ( "div#ui-timepicker-div-" + dp_id ) . length === 0 && o . showTimepicker ) {
258
259
var noDisplay = ' style="display:none;"' ,
259
260
html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
260
261
'<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
@@ -458,6 +459,18 @@ $.extend(Timepicker.prototype, {
458
459
this . _onTimeChange ( ) ;
459
460
this . timeDefined = timeDefined ;
460
461
}
462
+
463
+ //Emulate datepicker onSelect behavior. Call on slidestop.
464
+ var onSelect = tp_inst . _defaults [ 'onSelect' ] ;
465
+ if ( onSelect ) {
466
+ var inputEl = tp_inst . $input ? tp_inst . $input [ 0 ] : null ;
467
+ var onSelectHandler = function ( ) {
468
+ onSelect . apply ( inputEl , [ tp_inst . formattedDateTime , tp_inst ] ) ; // trigger custom callback*/
469
+ }
470
+ this . hour_slider . bind ( 'slidestop' , onSelectHandler ) ;
471
+ this . minute_slider . bind ( 'slidestop' , onSelectHandler ) ;
472
+ this . second_slider . bind ( 'slidestop' , onSelectHandler ) ;
473
+ }
461
474
}
462
475
} ,
463
476
@@ -549,14 +562,12 @@ $.extend(Timepicker.prototype, {
549
562
550
563
if ( hasChanged ) {
551
564
552
- if ( hour !== false ) {
553
- this . hour = hour ;
554
- if ( this . _defaults . ampm ) this . ampm = ampm ;
555
- }
565
+ if ( hour !== false ) this . hour = hour ;
556
566
if ( minute !== false ) this . minute = minute ;
557
567
if ( second !== false ) this . second = second ;
558
-
559
568
}
569
+ if ( this . _defaults . ampm ) this . ampm = ampm ;
570
+
560
571
this . _formatTime ( ) ;
561
572
if ( this . $timeObj ) this . $timeObj . text ( this . formattedTime ) ;
562
573
this . timeDefined = true ;
@@ -621,8 +632,10 @@ $.extend(Timepicker.prototype, {
621
632
}
622
633
623
634
this . formattedDateTime = formattedDateTime ;
624
-
625
- if ( this . $altInput && this . _defaults . altFieldTimeOnly === true ) {
635
+
636
+ if ( ! this . _defaults . showTimepicker ) {
637
+ this . $input . val ( this . formattedDate ) ;
638
+ } else if ( this . $altInput && this . _defaults . altFieldTimeOnly === true ) {
626
639
this . $altInput . val ( this . formattedTime ) ;
627
640
this . $input . val ( this . formattedDate ) ;
628
641
} else if ( this . $altInput ) {
@@ -689,7 +702,8 @@ $.datepicker._selectDate = function (id, dateStr) {
689
702
if ( tp_inst ) {
690
703
tp_inst . _limitMinMaxDateTime ( inst , true ) ;
691
704
inst . inline = inst . stay_open = true ;
692
- this . _base_selectDate ( id , dateStr ) ;
705
+ //This way the onSelect handler called from calendarpicker get the full dateTime
706
+ this . _base_selectDate ( id , dateStr + tp_inst . _defaults . separator + tp_inst . formattedTime ) ;
693
707
inst . inline = inst . stay_open = false ;
694
708
this . _notifyChange ( inst ) ;
695
709
this . _updateDatepicker ( inst ) ;
@@ -772,6 +786,29 @@ $.datepicker._gotoToday = function(id) {
772
786
this . _setTime ( this . _getInst ( $ ( id ) [ 0 ] ) , new Date ( ) ) ;
773
787
} ;
774
788
789
+ //#######################################################################################
790
+ // Disable & enable the Time in the datetimepicker
791
+ //#######################################################################################
792
+ $ . datepicker . _disableTimepickerDatepicker = function ( target , date , withDate ) {
793
+ var inst = this . _getInst ( target ) ,
794
+ tp_inst = this . _get ( inst , 'timepicker' ) ;
795
+ if ( tp_inst ) {
796
+ tp_inst . _defaults . showTimepicker = false ;
797
+ tp_inst . _onTimeChange ( ) ;
798
+ tp_inst . _updateDateTime ( inst ) ;
799
+ }
800
+ } ;
801
+
802
+ $ . datepicker . _enableTimepickerDatepicker = function ( target , date , withDate ) {
803
+ var inst = this . _getInst ( target ) ,
804
+ tp_inst = this . _get ( inst , 'timepicker' ) ;
805
+ if ( tp_inst ) {
806
+ tp_inst . _defaults . showTimepicker = true ;
807
+ tp_inst . _onTimeChange ( ) ;
808
+ tp_inst . _updateDateTime ( inst ) ;
809
+ }
810
+ } ;
811
+
775
812
//#######################################################################################
776
813
// Create our own set time function
777
814
//#######################################################################################
0 commit comments