1
1
/*!
2
- * jQuery UI Timepicker 0.2.1
2
+ * jQuery UI DateTimepicker @VERSION
3
+ *
4
+ * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
5
+ * Dual licensed under the MIT or GPL Version 2 licenses.
6
+ * http://jquery.org/license
3
7
*
4
8
* Copyright (c) 2009 Martin Milesich (http://milesich.com/)
5
9
* http://addyosmani.com/blog/the-missing-date-time-selector-for-jquery-ui/
6
10
*
7
- * Copyright (c) 2010 Gábor Czigola (http://gablog.eu)
8
- *
11
+ * Copyright (c) 2010 Gábor Czigola
9
12
*
10
- * $Id: timepicker.js 28 2009-08-11 20:31:23Z majlo $
13
+ * http://docs.jquery.com/UI/Timepicker
11
14
*
12
15
* Depends:
13
16
* ui.core.js
@@ -92,6 +95,8 @@ $.datepicker._checkExternalClick = function (event) {
92
95
if ( ! $ . datepicker . _curInst ) return ;
93
96
var $target = $ ( event . target ) ;
94
97
98
+ $ . datepicker . _curInst . closeButtonClicked = $target . parents ( '.ui-datepicker-buttonpane' ) . length ;
99
+
95
100
if ( ( $target . parents ( '#' + $ . timepicker . _mainDivId ) . length == 0 ) ) {
96
101
$ . datepicker . _checkExternalClickOverride ( event ) ;
97
102
}
@@ -108,18 +113,28 @@ $.datepicker._hideDatepicker = function(input, duration) {
108
113
109
114
if ( ! inst || ( input && inst != $ . data ( input , PROP_NAME ) ) ) return ;
110
115
116
+ // Change the field only when Done button clicked or sliders changed.
117
+ var saveOnHide = $ . timepicker . _modified ;
118
+ try {
119
+ saveOnHide |= inst . closeButtonClicked ;
120
+ }
121
+ catch ( err ) { }
122
+
111
123
// Get the value of showTime property
112
124
var showTime = this . _get ( inst , 'showTime' ) ;
113
125
114
- if ( input === undefined && showTime ) {
126
+ if ( saveOnHide && input === undefined && showTime ) {
115
127
if ( inst . input ) {
116
128
inst . input . val ( this . _formatDate ( inst ) ) ;
117
- inst . input . trigger ( 'change' ) ; // fire the change event
118
129
}
119
130
120
131
this . _updateAlternate ( inst ) ;
121
132
122
133
if ( showTime ) $ . timepicker . update ( this . _formatDate ( inst ) ) ;
134
+
135
+ if ( inst . input ) {
136
+ inst . input . trigger ( 'change' ) ; // fire the change event
137
+ }
123
138
}
124
139
125
140
// Hide datepicker
@@ -129,6 +144,8 @@ $.datepicker._hideDatepicker = function(input, duration) {
129
144
if ( showTime ) {
130
145
$ . timepicker . hide ( ) ;
131
146
}
147
+
148
+ $ . timepicker . _modified = false ;
132
149
} ;
133
150
134
151
/**
@@ -186,6 +203,7 @@ Timepicker.prototype = {
186
203
this . _orgMinute = null ;
187
204
this . _colonPos = - 1 ;
188
205
this . _visible = false ;
206
+ this . _modified = false ;
189
207
this . tpDiv = $ ( '<div id="' + this . _mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" style="z-index: 16; width: 100px; display: none; position: absolute;"></div>' ) ;
190
208
this . _generateHtml ( ) ;
191
209
} ,
@@ -302,9 +320,11 @@ Timepicker.prototype = {
302
320
max : 23 ,
303
321
step : 1 ,
304
322
slide : function ( event , ui ) {
323
+ self . _modified = true ;
305
324
self . _writeTime ( 'hour' , ui . value ) ;
306
325
} ,
307
326
stop : function ( event , ui ) {
327
+ self . _modified = true ;
308
328
$ ( '#' + self . _inputId ) . focus ( ) ;
309
329
}
310
330
} ) ;
@@ -405,7 +425,7 @@ Timepicker.prototype = {
405
425
}
406
426
407
427
this . _writeTime ( type , value ) ;
408
- }
428
+ }
409
429
} ;
410
430
411
431
$ . timepicker = new Timepicker ( ) ;
0 commit comments