Changeset 801561
- Timestamp:
- 11/09/2013 01:57:53 PM (12 years ago)
- Location:
- contact-form-7-datepicker/trunk/js/jquery-ui-timepicker
- Files:
-
- 3 edited
-
i18n/jquery-ui-timepicker-sv.js (modified) (1 diff)
-
jquery-ui-timepicker-addon.css (modified) (1 diff)
-
jquery-ui-timepicker-addon.js (modified) (110 diffs)
Legend:
- Unmodified
- Added
- Removed
-
contact-form-7-datepicker/trunk/js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-sv.js
r755191 r801561 4 4 $.timepicker.regional['sv'] = { 5 5 timeOnlyTitle: 'Välj en tid', 6 timeText: 'Ti mme',7 hourText: 'Timm ar',8 minuteText: 'Minut er',9 secondText: 'Sekund er',10 millisecText: 'Millisekund er',11 microsecText: 'Mikrosekund er',6 timeText: 'Tid', 7 hourText: 'Timme', 8 minuteText: 'Minut', 9 secondText: 'Sekund', 10 millisecText: 'Millisekund', 11 microsecText: 'Mikrosekund', 12 12 timezoneText: 'Tidszon', 13 13 currentText: 'Nu', -
contact-form-7-datepicker/trunk/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.css
r755191 r801561 1 1 .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } 2 2 .ui-timepicker-div dl { text-align: left; } 3 .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }4 .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }3 .ui-timepicker-div dl dt { float: left; clear:left; padding: 0 0 0 5px; } 4 .ui-timepicker-div dl dd { margin: 0 10px 10px 40%; } 5 5 .ui-timepicker-div td { font-size: 90%; } 6 6 .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } 7 7 8 8 .ui-timepicker-rtl{ direction: rtl; } 9 .ui-timepicker-rtl dl { text-align: right; } 10 .ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; } 9 .ui-timepicker-rtl dl { text-align: right; padding: 0 5px 0 0; } 10 .ui-timepicker-rtl dl dt{ float: right; clear: right; } 11 .ui-timepicker-rtl dl dd { margin: 0 40% 10px 10px; } -
contact-form-7-datepicker/trunk/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.js
r755191 r801561 1 /* 2 * jQuery timepicker addon 3 * By: Trent Richardson [http://trentrichardson.com] 4 * Version 1.3 5 * Last Modified: 05/05/2013 6 * 7 * Copyright 2013 Trent Richardson 8 * You may use this project under MIT or GPL licenses. 9 * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt 10 * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt 11 */ 12 13 /*jslint evil: true, white: false, undef: false, nomen: false */ 14 15 (function($) { 1 /*! jQuery Timepicker Addon - v1.4 - 2013-08-11 2 * http://trentrichardson.com/examples/timepicker 3 * Copyright (c) 2013 Trent Richardson; Licensed MIT */ 4 (function ($) { 16 5 17 6 /* … … 28 17 $.extend($.ui, { 29 18 timepicker: { 30 version: "1. 3"19 version: "1.4" 31 20 } 32 21 }); … … 38 27 * allowing multiple different settings on the same page. 39 28 */ 40 var Timepicker = function () {29 var Timepicker = function () { 41 30 this.regional = []; // Available regional settings, indexed by language code 42 31 this.regional[''] = { // Default regional settings … … 147 136 formattedDateTime: '', 148 137 timezoneList: null, 149 units: ['hour', 'minute','second','millisec', 'microsec'],138 units: ['hour', 'minute', 'second', 'millisec', 'microsec'], 150 139 support: {}, 151 140 control: null, … … 153 142 /* 154 143 * Override the default settings for all instances of the time picker. 155 * @param settings object - the new settings to use as defaults (anonymous object)156 * @return the manager object144 * @param {Object} settings object - the new settings to use as defaults (anonymous object) 145 * @return {Object} the manager object 157 146 */ 158 setDefaults: function (settings) {147 setDefaults: function (settings) { 159 148 extendRemove(this._defaults, settings || {}); 160 149 return this; … … 164 153 * Create a new Timepicker instance 165 154 */ 166 _newInst: function ($input, o) {155 _newInst: function ($input, opts) { 167 156 var tp_inst = new Timepicker(), 168 157 inlineSettings = {}, 169 fns = {},170 overrides, i;158 fns = {}, 159 overrides, i; 171 160 172 161 for (var attrName in this._defaults) { 173 if (this._defaults.hasOwnProperty(attrName)){162 if (this._defaults.hasOwnProperty(attrName)) { 174 163 var attrValue = $input.attr('time:' + attrName); 175 164 if (attrValue) { … … 183 172 } 184 173 185 overrides = {186 beforeShow: function (input, dp_inst) {187 if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) {188 return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst);189 }190 },191 onChangeMonthYear: function (year, month, dp_inst) {192 // Update the time as well : this prevents the time from disappearing from the $input field.193 tp_inst._updateDateTime(dp_inst);194 if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) {195 tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);196 }197 },198 onClose: function (dateText, dp_inst) {199 if (tp_inst.timeDefined === true && $input.val() !== '') {200 tp_inst._updateDateTime(dp_inst);201 }202 if ($.isFunction(tp_inst._defaults.evnts.onClose)) {203 tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst);204 }205 }206 };207 for (i in overrides) {208 if (overrides.hasOwnProperty(i)) {209 fns[i] = o[i] || null;210 }211 }212 213 tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, {214 evnts:fns,215 timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');216 });217 tp_inst.amNames = $.map(tp_inst._defaults.amNames, function (val) {174 overrides = { 175 beforeShow: function (input, dp_inst) { 176 if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { 177 return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst); 178 } 179 }, 180 onChangeMonthYear: function (year, month, dp_inst) { 181 // Update the time as well : this prevents the time from disappearing from the $input field. 182 tp_inst._updateDateTime(dp_inst); 183 if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) { 184 tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); 185 } 186 }, 187 onClose: function (dateText, dp_inst) { 188 if (tp_inst.timeDefined === true && $input.val() !== '') { 189 tp_inst._updateDateTime(dp_inst); 190 } 191 if ($.isFunction(tp_inst._defaults.evnts.onClose)) { 192 tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); 193 } 194 } 195 }; 196 for (i in overrides) { 197 if (overrides.hasOwnProperty(i)) { 198 fns[i] = opts[i] || null; 199 } 200 } 201 202 tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, opts, overrides, { 203 evnts: fns, 204 timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); 205 }); 206 tp_inst.amNames = $.map(tp_inst._defaults.amNames, function (val) { 218 207 return val.toUpperCase(); 219 208 }); 220 tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function (val) {209 tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function (val) { 221 210 return val.toUpperCase(); 222 211 }); … … 225 214 tp_inst.support = detectSupport( 226 215 tp_inst._defaults.timeFormat + 227 (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat:'') +228 (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat:''));216 (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') + 217 (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : '')); 229 218 230 219 // controlType is string - key to our this._controls 231 if (typeof(tp_inst._defaults.controlType) === 'string'){232 if (tp_inst._defaults.controlType == 'slider' && typeof(jQuery.ui.slider) === 'undefined'){220 if (typeof(tp_inst._defaults.controlType) === 'string') { 221 if (tp_inst._defaults.controlType === 'slider' && typeof($.ui.slider) === 'undefined') { 233 222 tp_inst._defaults.controlType = 'select'; 234 223 } … … 236 225 } 237 226 // controlType is an object and must implement create, options, value methods 238 else {227 else { 239 228 tp_inst.control = tp_inst._defaults.controlType; 240 229 } 241 230 242 231 // prep the timezone options 243 var timezoneList = [-720, -660,-600,-570,-540,-480,-420,-360,-300,-270,-240,-210,-180,-120,-60,244 0, 60,120,180,210,240,270,300,330,345,360,390,420,480,525,540,570,600,630,660,690,720,765,780,840];232 var timezoneList = [-720, -660, -600, -570, -540, -480, -420, -360, -300, -270, -240, -210, -180, -120, -60, 233 0, 60, 120, 180, 210, 240, 270, 300, 330, 345, 360, 390, 420, 480, 525, 540, 570, 600, 630, 660, 690, 720, 765, 780, 840]; 245 234 if (tp_inst._defaults.timezoneList !== null) { 246 235 timezoneList = tp_inst._defaults.timezoneList; 247 236 } 248 var tzl =timezoneList.length,tzi=0,tzv=null;237 var tzl = timezoneList.length, tzi = 0, tzv = null; 249 238 if (tzl > 0 && typeof timezoneList[0] !== 'object') { 250 for (; tzi<tzl; tzi++){239 for (; tzi < tzl; tzi++) { 251 240 tzv = timezoneList[tzi]; 252 241 timezoneList[tzi] = { value: tzv, label: $.timepicker.timezoneOffsetString(tzv, tp_inst.support.iso8601) }; … … 256 245 257 246 // set the default units 258 tp_inst.timezone = tp_inst._defaults.timezone !== null ? $.timepicker.timezoneOffsetNumber(tp_inst._defaults.timezone) :259 ((new Date()).getTimezoneOffset() *-1);260 tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin ? tp_inst._defaults.hourMin :261 tp_inst._defaults.hour > tp_inst._defaults.hourMax ? tp_inst._defaults.hourMax : tp_inst._defaults.hour;262 tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin ? tp_inst._defaults.minuteMin :263 tp_inst._defaults.minute > tp_inst._defaults.minuteMax ? tp_inst._defaults.minuteMax : tp_inst._defaults.minute;264 tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin ? tp_inst._defaults.secondMin :265 tp_inst._defaults.second > tp_inst._defaults.secondMax ? tp_inst._defaults.secondMax : tp_inst._defaults.second;266 tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin ? tp_inst._defaults.millisecMin :267 tp_inst._defaults.millisec > tp_inst._defaults.millisecMax ? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec;268 tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin ? tp_inst._defaults.microsecMin :269 tp_inst._defaults.microsec > tp_inst._defaults.microsecMax ? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec;247 tp_inst.timezone = tp_inst._defaults.timezone !== null ? $.timepicker.timezoneOffsetNumber(tp_inst._defaults.timezone) : 248 ((new Date()).getTimezoneOffset() * -1); 249 tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin ? tp_inst._defaults.hourMin : 250 tp_inst._defaults.hour > tp_inst._defaults.hourMax ? tp_inst._defaults.hourMax : tp_inst._defaults.hour; 251 tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin ? tp_inst._defaults.minuteMin : 252 tp_inst._defaults.minute > tp_inst._defaults.minuteMax ? tp_inst._defaults.minuteMax : tp_inst._defaults.minute; 253 tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin ? tp_inst._defaults.secondMin : 254 tp_inst._defaults.second > tp_inst._defaults.secondMax ? tp_inst._defaults.secondMax : tp_inst._defaults.second; 255 tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin ? tp_inst._defaults.millisecMin : 256 tp_inst._defaults.millisec > tp_inst._defaults.millisecMax ? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec; 257 tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin ? tp_inst._defaults.microsecMin : 258 tp_inst._defaults.microsec > tp_inst._defaults.microsecMax ? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec; 270 259 tp_inst.ampm = ''; 271 260 tp_inst.$input = $input; 272 261 273 if ( o.altField) {274 tp_inst.$altInput = $( o.altField).css({262 if (tp_inst._defaults.altField) { 263 tp_inst.$altInput = $(tp_inst._defaults.altField).css({ 275 264 cursor: 'pointer' 276 }).focus(function () {265 }).focus(function () { 277 266 $input.trigger("focus"); 278 267 }); … … 299 288 tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); 300 289 } 301 tp_inst.$input.bind('focus', function () {290 tp_inst.$input.bind('focus', function () { 302 291 tp_inst._onFocus(); 303 292 }); … … 309 298 * add our sliders to the calendar 310 299 */ 311 _addTimePicker: function (dp_inst) {300 _addTimePicker: function (dp_inst) { 312 301 var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val(); 313 302 … … 320 309 * parse the time string from input value or _setTime 321 310 */ 322 _parseTime: function (timeString, withDate) {311 _parseTime: function (timeString, withDate) { 323 312 if (!this.inst) { 324 313 this.inst = $.datepicker._getInst(this.$input[0]); … … 354 343 * generate and inject html for timepicker into ui datepicker 355 344 */ 356 _injectTimePicker: function () {345 _injectTimePicker: function () { 357 346 var $dp = this.inst.dpDiv, 358 347 o = this.inst.settings, … … 364 353 gridSize = {}, 365 354 size = null, 366 i =0,367 l =0;355 i = 0, 356 l = 0; 368 357 369 358 // Prevent displaying twice 370 359 if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) { 371 360 var noDisplay = ' style="display:none;"', 372 html = '<div class="ui-timepicker-div' + (o.isRTL? ' ui-timepicker-rtl' : '') +'"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +361 html = '<div class="ui-timepicker-div' + (o.isRTL ? ' ui-timepicker-rtl' : '') + '"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' + 373 362 '<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>'; 374 363 375 364 // Create the markup 376 for (i=0,l=this.units.length; i<l; i++){365 for (i = 0, l = this.units.length; i < l; i++) { 377 366 litem = this.units[i]; 378 uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1);379 show = o['show' +uitem] !== null? o['show'+uitem] : this.support[litem];367 uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1); 368 show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; 380 369 381 370 // Added by Peter Medeiros: 382 371 // - Figure out what the hour/minute/second max should be based on the step values. 383 372 // - Example: if stepMinute is 15, then minMax is 45. 384 max[litem] = parseInt((o[litem +'Max'] - ((o[litem+'Max'] - o[litem+'Min']) % o['step'+uitem])), 10);373 max[litem] = parseInt((o[litem + 'Max'] - ((o[litem + 'Max'] - o[litem + 'Min']) % o['step' + uitem])), 10); 385 374 gridSize[litem] = 0; 386 375 387 html += '<dt class="ui_tpicker_' + litem +'_label"' + (show ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' +388 '<dd class="ui_tpicker_' + litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + (show ? '' : noDisplay) + '></div>';389 390 if (show && o[litem +'Grid'] > 0) {376 html += '<dt class="ui_tpicker_' + litem + '_label"' + (show ? '' : noDisplay) + '>' + o[litem + 'Text'] + '</dt>' + 377 '<dd class="ui_tpicker_' + litem + '"><div class="ui_tpicker_' + litem + '_slider"' + (show ? '' : noDisplay) + '></div>'; 378 379 if (show && o[litem + 'Grid'] > 0) { 391 380 html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; 392 381 393 if (litem == 'hour'){394 for (var h = o[litem +'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) {382 if (litem === 'hour') { 383 for (var h = o[litem + 'Min']; h <= max[litem]; h += parseInt(o[litem + 'Grid'], 10)) { 395 384 gridSize[litem]++; 396 var tmph = $.datepicker.formatTime(this.support.ampm ? 'hht':'HH', {hour:h}, o);397 html += '<td data-for="' +litem+'">' + tmph + '</td>';385 var tmph = $.datepicker.formatTime(this.support.ampm ? 'hht' : 'HH', {hour: h}, o); 386 html += '<td data-for="' + litem + '">' + tmph + '</td>'; 398 387 } 399 388 } 400 else {401 for (var m = o[litem +'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) {389 else { 390 for (var m = o[litem + 'Min']; m <= max[litem]; m += parseInt(o[litem + 'Grid'], 10)) { 402 391 gridSize[litem]++; 403 html += '<td data-for="' +litem+'">' + ((m < 10) ? '0' : '') + m + '</td>';392 html += '<td data-for="' + litem + '">' + ((m < 10) ? '0' : '') + m + '</td>'; 404 393 } 405 394 } … … 411 400 412 401 // Timezone 413 var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone;402 var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone; 414 403 html += '<dt class="ui_tpicker_timezone_label"' + (showTz ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; 415 404 html += '<dd class="ui_tpicker_timezone" ' + (showTz ? '' : noDisplay) + '></dd>'; … … 426 415 427 416 // add sliders, adjust grids, add events 428 for (i=0,l=tp_inst.units.length; i<l; i++){417 for (i = 0, l = tp_inst.units.length; i < l; i++) { 429 418 litem = tp_inst.units[i]; 430 uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1);431 show = o['show' +uitem] !== null? o['show'+uitem] : this.support[litem];419 uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1); 420 show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; 432 421 433 422 // add the slider 434 tp_inst[litem +'_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_'+litem+'_slider'), litem, tp_inst[litem], o[litem+'Min'], max[litem], o['step'+uitem]);423 tp_inst[litem + '_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_' + litem + '_slider'), litem, tp_inst[litem], o[litem + 'Min'], max[litem], o['step' + uitem]); 435 424 436 425 // adjust the grid and add click event 437 if (show && o[litem +'Grid'] > 0) {438 size = 100 * gridSize[litem] * o[litem +'Grid'] / (max[litem] - o[litem+'Min']);439 $tp.find('.ui_tpicker_' +litem+' table').css({426 if (show && o[litem + 'Grid'] > 0) { 427 size = 100 * gridSize[litem] * o[litem + 'Grid'] / (max[litem] - o[litem + 'Min']); 428 $tp.find('.ui_tpicker_' + litem + ' table').css({ 440 429 width: size + "%", 441 marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"),442 marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0',430 marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"), 431 marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0', 443 432 borderCollapse: 'collapse' 444 }).find("td").click(function (e){433 }).find("td").click(function (e) { 445 434 var $t = $(this), 446 435 h = $t.html(), 447 n = parseInt(h.replace(/[^0-9]/g), 10),436 n = parseInt(h.replace(/[^0-9]/g), 10), 448 437 ap = h.replace(/[^apm]/ig), 449 438 f = $t.data('for'); // loses scope, so we use data-for 450 439 451 if (f == 'hour'){452 if (ap.indexOf('p') !== -1 && n < 12){440 if (f === 'hour') { 441 if (ap.indexOf('p') !== -1 && n < 12) { 453 442 n += 12; 454 443 } 455 else {456 if (ap.indexOf('a') !== -1 && n === 12){444 else { 445 if (ap.indexOf('a') !== -1 && n === 12) { 457 446 n = 0; 458 447 } … … 460 449 } 461 450 462 tp_inst.control.value(tp_inst, tp_inst[f +'_slider'], litem, n);451 tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n); 463 452 464 453 tp_inst._onTimeChange(); … … 476 465 this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select"); 477 466 $.fn.append.apply(this.timezone_select, 478 $.map(o.timezoneList, function (val, idx) {479 return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val== "object" ? val.label : val);467 $.map(o.timezoneList, function (val, idx) { 468 return $("<option />").val(typeof val === "object" ? val.value : val).text(typeof val === "object" ? val.label : val); 480 469 })); 481 if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {482 var local_timezone = (new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12)).getTimezoneOffset() *-1;483 if (local_timezone == this.timezone) {470 if (typeof(this.timezone) !== "undefined" && this.timezone !== null && this.timezone !== "") { 471 var local_timezone = (new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12)).getTimezoneOffset() * -1; 472 if (local_timezone === this.timezone) { 484 473 selectLocalTimezone(tp_inst); 485 474 } else { … … 487 476 } 488 477 } else { 489 if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") {478 if (typeof(this.hour) !== "undefined" && this.hour !== null && this.hour !== "") { 490 479 this.timezone_select.val(o.timezone); 491 480 } else { … … 493 482 } 494 483 } 495 this.timezone_select.change(function () {484 this.timezone_select.change(function () { 496 485 tp_inst._onTimeChange(); 497 486 tp_inst._onSelectHandler(); … … 521 510 sliderAccessArgs.isRTL = rtl; 522 511 523 setTimeout(function () { // fix for inline mode512 setTimeout(function () { // fix for inline mode 524 513 if ($tp.find('.ui-slider-access').length === 0) { 525 514 $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs); … … 528 517 var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true); 529 518 if (sliderAccessWidth) { 530 $tp.find('table:visible').each(function () {519 $tp.find('table:visible').each(function () { 531 520 var $g = $(this), 532 521 oldWidth = $g.outerWidth(), 533 oldMarginLeft = $g.css(rtl ? 'marginRight':'marginLeft').toString().replace('%', ''),522 oldMarginLeft = $g.css(rtl ? 'marginRight' : 'marginLeft').toString().replace('%', ''), 534 523 newWidth = oldWidth - sliderAccessWidth, 535 524 newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%', 536 525 css = { width: newWidth, marginRight: 0, marginLeft: 0 }; 537 css[rtl ? 'marginRight':'marginLeft'] = newMarginLeft;526 css[rtl ? 'marginRight' : 'marginLeft'] = newMarginLeft; 538 527 $g.css(css); 539 528 }); … … 544 533 // end slideAccess integration 545 534 535 tp_inst._limitMinMaxDateTime(this.inst, true); 546 536 } 547 537 }, … … 551 541 * min/max date range 552 542 */ 553 _limitMinMaxDateTime: function (dp_inst, adjustSliders) {543 _limitMinMaxDateTime: function (dp_inst, adjustSliders) { 554 544 var o = this._defaults, 555 545 dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay); … … 571 561 } 572 562 573 if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) {563 if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() === dp_date.getTime()) { 574 564 this._defaults.hourMin = minDateTime.getHours(); 575 565 if (this.hour <= this._defaults.hourMin) { … … 582 572 this.second = this._defaults.secondMin; 583 573 this._defaults.millisecMin = minDateTime.getMilliseconds(); 584 if (this.millisec <= this._defaults.millisecMin) {574 if (this.millisec <= this._defaults.millisecMin) { 585 575 this.millisec = this._defaults.millisecMin; 586 576 this._defaults.microsecMin = minDateTime.getMicroseconds(); … … 627 617 } 628 618 629 if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()) {619 if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() === dp_date.getTime()) { 630 620 this._defaults.hourMax = maxDateTime.getHours(); 631 621 if (this.hour >= this._defaults.hourMax) { … … 675 665 minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10), 676 666 secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10), 677 millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10) ;667 millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10), 678 668 microsecMax = parseInt((this._defaults.microsecMax - ((this._defaults.microsecMax - this._defaults.microsecMin) % this._defaults.stepMicrosec)), 10); 679 669 … … 706 696 * on time change is also called when the time is updated in the text field 707 697 */ 708 _onTimeChange: function() { 698 _onTimeChange: function () { 699 if (!this._defaults.showTimepicker) { 700 return; 701 } 709 702 var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false, 710 703 minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false, … … 717 710 pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix; 718 711 719 if (typeof(hour) == 'object') {712 if (typeof(hour) === 'object') { 720 713 hour = false; 721 714 } 722 if (typeof(minute) == 'object') {715 if (typeof(minute) === 'object') { 723 716 minute = false; 724 717 } 725 if (typeof(second) == 'object') {718 if (typeof(second) === 'object') { 726 719 second = false; 727 720 } 728 if (typeof(millisec) == 'object') {721 if (typeof(millisec) === 'object') { 729 722 millisec = false; 730 723 } 731 if (typeof(microsec) == 'object') {724 if (typeof(microsec) === 'object') { 732 725 microsec = false; 733 726 } 734 if (typeof(timezone) == 'object') {727 if (typeof(timezone) === 'object') { 735 728 timezone = false; 736 729 } … … 756 749 // If the update was done in the input field, the input field should not be updated. 757 750 // If the update was done using the sliders, update the input field. 758 var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec || microsec != this.microsec 759 || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) 760 || (this.timezone !== null && timezone != this.timezone)); 751 var hasChanged = (hour !== this.hour || minute !== this.minute || second !== this.second || millisec !== this.millisec || microsec !== this.microsec || 752 (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) || (this.timezone !== null && timezone !== this.timezone)); 761 753 762 754 if (hasChanged) { … … 794 786 this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o); 795 787 if (this.$timeObj) { 796 if (pickerTimeFormat === o.timeFormat){788 if (pickerTimeFormat === o.timeFormat) { 797 789 this.$timeObj.text(this.formattedTime + pickerTimeSuffix); 798 790 } 799 else {791 else { 800 792 this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix); 801 793 } … … 812 804 * bind to sliders slidestop, and grid click. 813 805 */ 814 _onSelectHandler: function () {806 _onSelectHandler: function () { 815 807 var onSelect = this._defaults.onSelect || this.inst.settings.onSelect; 816 808 var inputEl = this.$input ? this.$input[0] : null; … … 823 815 * update our input with the new date time.. 824 816 */ 825 _updateDateTime: function (dp_inst) {817 _updateDateTime: function (dp_inst) { 826 818 dp_inst = this.inst || dp_inst; 827 var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), 819 var dtTmp = (dp_inst.currentYear > 0? 820 new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay) : 821 new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), 822 dt = $.datepicker._daylightSavingAdjust(dtTmp), 823 //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), 824 //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay)), 828 825 dateFmt = $.datepicker._get(dp_inst, 'dateFormat'), 829 826 formatCfg = $.datepicker._getFormatConfig(dp_inst), … … 833 830 834 831 // if a slider was changed but datepicker doesn't have a value yet, set it 835 if (dp_inst.lastVal===""){836 dp_inst.currentYear =dp_inst.selectedYear;837 dp_inst.currentMonth =dp_inst.selectedMonth;838 dp_inst.currentDay =dp_inst.selectedDay;832 if (dp_inst.lastVa === "") { 833 dp_inst.currentYear = dp_inst.selectedYear; 834 dp_inst.currentMonth = dp_inst.selectedMonth; 835 dp_inst.currentDay = dp_inst.selectedDay; 839 836 } 840 837 … … 867 864 altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix; 868 865 869 if (!this._defaults.timeOnly){870 if (this._defaults.altFormat) {866 if (!this._defaults.timeOnly) { 867 if (this._defaults.altFormat) { 871 868 altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg); 872 869 } 873 else {870 else { 874 871 altFormattedDateTime = this.formattedDate; 875 872 } 876 873 877 if (altFormattedDateTime) {874 if (altFormattedDateTime) { 878 875 altFormattedDateTime += altSeparator; 879 876 } 880 877 } 881 878 882 if (this._defaults.altTimeFormat){879 if (this._defaults.altTimeFormat) { 883 880 altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix; 884 881 } 885 else {882 else { 886 883 altFormattedDateTime += this.formattedTime + altTimeSuffix; 887 884 } … … 894 891 }, 895 892 896 _onFocus: function () {893 _onFocus: function () { 897 894 if (!this.$input.val() && this._defaults.defaultValue) { 898 895 this.$input.val(this._defaults.defaultValue); … … 900 897 tp_inst = $.datepicker._get(inst, 'timepicker'); 901 898 if (tp_inst) { 902 if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {899 if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) { 903 900 try { 904 901 $.datepicker._updateDatepicker(inst); … … 918 915 // slider methods 919 916 slider: { 920 create: function (tp_inst, obj, unit, val, min, max, step){917 create: function (tp_inst, obj, unit, val, min, max, step) { 921 918 var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60 922 919 return obj.prop('slide', null).slider({ 923 920 orientation: "horizontal", 924 value: rtl ? val*-1 : val,925 min: rtl ? max*-1 : min,926 max: rtl ? min*-1 : max,921 value: rtl ? val * -1 : val, 922 min: rtl ? max * -1 : min, 923 max: rtl ? min * -1 : max, 927 924 step: step, 928 slide: function (event, ui) {929 tp_inst.control.value(tp_inst, $(this), unit, rtl ? ui.value*-1:ui.value);925 slide: function (event, ui) { 926 tp_inst.control.value(tp_inst, $(this), unit, rtl ? ui.value * -1 : ui.value); 930 927 tp_inst._onTimeChange(); 931 928 }, 932 stop: function (event, ui) {929 stop: function (event, ui) { 933 930 tp_inst._onSelectHandler(); 934 931 } 935 932 }); 936 933 }, 937 options: function (tp_inst, obj, unit, opts, val){938 if (tp_inst._defaults.isRTL){939 if (typeof(opts) == 'string'){940 if (opts == 'min' || opts == 'max'){941 if (val !== undefined){942 return obj.slider(opts, val *-1);934 options: function (tp_inst, obj, unit, opts, val) { 935 if (tp_inst._defaults.isRTL) { 936 if (typeof(opts) === 'string') { 937 if (opts === 'min' || opts === 'max') { 938 if (val !== undefined) { 939 return obj.slider(opts, val * -1); 943 940 } 944 941 return Math.abs(obj.slider(opts)); … … 949 946 max = opts.max; 950 947 opts.min = opts.max = null; 951 if (min !== undefined){948 if (min !== undefined) { 952 949 opts.max = min * -1; 953 950 } 954 if (max !== undefined){951 if (max !== undefined) { 955 952 opts.min = max * -1; 956 953 } 957 954 return obj.slider(opts); 958 955 } 959 if (typeof(opts) == 'string' && val !== undefined){960 return obj.slider(opts, val);956 if (typeof(opts) === 'string' && val !== undefined) { 957 return obj.slider(opts, val); 961 958 } 962 959 return obj.slider(opts); 963 960 }, 964 value: function (tp_inst, obj, unit, val){965 if (tp_inst._defaults.isRTL){966 if (val !== undefined){967 return obj.slider('value', val *-1);961 value: function (tp_inst, obj, unit, val) { 962 if (tp_inst._defaults.isRTL) { 963 if (val !== undefined) { 964 return obj.slider('value', val * -1); 968 965 } 969 966 return Math.abs(obj.slider('value')); 970 967 } 971 if (val !== undefined){968 if (val !== undefined) { 972 969 return obj.slider('value', val); 973 970 } … … 977 974 // select methods 978 975 select: { 979 create: function (tp_inst, obj, unit, val, min, max, step){980 var sel = '<select class="ui-timepicker-select" data-unit="' + unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">',976 create: function (tp_inst, obj, unit, val, min, max, step) { 977 var sel = '<select class="ui-timepicker-select" data-unit="' + unit + '" data-min="' + min + '" data-max="' + max + '" data-step="' + step + '">', 981 978 format = tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat; 982 979 983 for (var i=min; i<=max; i+=step){984 sel += '<option value="' + i +'"'+ (i==val? ' selected':'') +'>';985 if (unit == 'hour'){986 sel += $.datepicker.formatTime($.trim(format.replace(/[^ht ]/ig, '')), {hour:i}, tp_inst._defaults);980 for (var i = min; i <= max; i += step) { 981 sel += '<option value="' + i + '"' + (i === val ? ' selected' : '') + '>'; 982 if (unit === 'hour') { 983 sel += $.datepicker.formatTime($.trim(format.replace(/[^ht ]/ig, '')), {hour: i}, tp_inst._defaults); 987 984 } 988 else if (unit == 'millisec' || unit == 'microsec' || i >= 10){ sel += i; }989 else {sel += '0' + i.toString(); }985 else if (unit === 'millisec' || unit === 'microsec' || i >= 10) { sel += i; } 986 else {sel += '0' + i.toString(); } 990 987 sel += '</option>'; 991 988 } … … 994 991 obj.children('select').remove(); 995 992 996 $(sel).appendTo(obj).change(function (e){993 $(sel).appendTo(obj).change(function (e) { 997 994 tp_inst._onTimeChange(); 998 995 tp_inst._onSelectHandler(); … … 1001 998 return obj; 1002 999 }, 1003 options: function (tp_inst, obj, unit, opts, val){1000 options: function (tp_inst, obj, unit, opts, val) { 1004 1001 var o = {}, 1005 1002 $t = obj.children('select'); 1006 if (typeof(opts) == 'string'){1007 if (val === undefined){1003 if (typeof(opts) === 'string') { 1004 if (val === undefined) { 1008 1005 return $t.data(opts); 1009 1006 } 1010 1007 o[opts] = val; 1011 1008 } 1012 else { o = opts; }1009 else { o = opts; } 1013 1010 return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min || $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step')); 1014 1011 }, 1015 value: function (tp_inst, obj, unit, val){1012 value: function (tp_inst, obj, unit, val) { 1016 1013 var $t = obj.children('select'); 1017 if (val !== undefined){1014 if (val !== undefined) { 1018 1015 return $t.val(val); 1019 1016 } … … 1027 1024 $.fn.extend({ 1028 1025 /* 1029 * shorthand just to use timepicker. .1026 * shorthand just to use timepicker. 1030 1027 */ 1031 timepicker: function (o) {1028 timepicker: function (o) { 1032 1029 o = o || {}; 1033 1030 var tmp_args = Array.prototype.slice.call(arguments); 1034 1031 1035 if (typeof o == 'object') {1032 if (typeof o === 'object') { 1036 1033 tmp_args[0] = $.extend(o, { 1037 1034 timeOnly: true … … 1039 1036 } 1040 1037 1041 return $(this).each(function () {1038 return $(this).each(function () { 1042 1039 $.fn.datetimepicker.apply($(this), tmp_args); 1043 1040 }); … … 1047 1044 * extend timepicker to datepicker 1048 1045 */ 1049 datetimepicker: function (o) {1046 datetimepicker: function (o) { 1050 1047 o = o || {}; 1051 1048 var tmp_args = arguments; 1052 1049 1053 if (typeof(o) == 'string') {1054 if (o == 'getDate') {1050 if (typeof(o) === 'string') { 1051 if (o === 'getDate') { 1055 1052 return $.fn.datepicker.apply($(this[0]), tmp_args); 1056 1053 } else { 1057 return this.each(function () {1054 return this.each(function () { 1058 1055 var $t = $(this); 1059 1056 $t.datepicker.apply($t, tmp_args); … … 1061 1058 } 1062 1059 } else { 1063 return this.each(function () {1060 return this.each(function () { 1064 1061 var $t = $(this); 1065 1062 $t.datepicker($.timepicker._newInst($t, o)._defaults); … … 1072 1069 * Public Utility to parse date and time 1073 1070 */ 1074 $.datepicker.parseDateTime = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {1071 $.datepicker.parseDateTime = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { 1075 1072 var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings); 1076 1073 if (parseRes.timeObj) { 1077 1074 var t = parseRes.timeObj; 1078 1075 parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec); 1079 parseRe x.date.setMicroseconds(t.microsec);1076 parseRes.date.setMicroseconds(t.microsec); 1080 1077 } 1081 1078 … … 1086 1083 * Public utility to parse time 1087 1084 */ 1088 $.datepicker.parseTime = function (timeFormat, timeString, options) {1085 $.datepicker.parseTime = function (timeFormat, timeString, options) { 1089 1086 var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}), 1090 iso8601 = (timeFormat.replace(/\'.*?\'/g, '').indexOf('Z') !== -1);1087 iso8601 = (timeFormat.replace(/\'.*?\'/g, '').indexOf('Z') !== -1); 1091 1088 1092 1089 // Strict parse requires the timeString to match the timeFormat exactly 1093 var strictParse = function (f, s, o){1090 var strictParse = function (f, s, o) { 1094 1091 1095 1092 // pattern for standard and localized AM/PM markers 1096 var getPatternAmpm = function (amNames, pmNames) {1093 var getPatternAmpm = function (amNames, pmNames) { 1097 1094 var markers = []; 1098 1095 if (amNames) { … … 1102 1099 $.merge(markers, pmNames); 1103 1100 } 1104 markers = $.map(markers, function (val) {1101 markers = $.map(markers, function (val) { 1105 1102 return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); 1106 1103 }); … … 1109 1106 1110 1107 // figure out position of time elements.. cause js cant do named captures 1111 var getFormatPositions = function (timeFormat) {1108 var getFormatPositions = function (timeFormat) { 1112 1109 var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g), 1113 1110 orders = { … … 1123 1120 if (finds) { 1124 1121 for (var i = 0; i < finds.length; i++) { 1125 if (orders[finds[i].toString().charAt(0)] == -1) {1122 if (orders[finds[i].toString().charAt(0)] === -1) { 1126 1123 orders[finds[i].toString().charAt(0)] = i + 1; 1127 1124 } … … 1135 1132 var ml = match.length; 1136 1133 switch (match.charAt(0).toLowerCase()) { 1137 case 'h': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; 1138 case 'm': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; 1139 case 's': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; 1140 case 'l': return '(\\d?\\d?\\d)'; 1141 case 'c': return '(\\d?\\d?\\d)'; 1142 case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?'; 1143 case 't': return getPatternAmpm(o.amNames, o.pmNames); 1144 default: // literal escaped in quotes 1145 return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?'; 1134 case 'h': 1135 return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})'; 1136 case 'm': 1137 return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})'; 1138 case 's': 1139 return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})'; 1140 case 'l': 1141 return '(\\d?\\d?\\d)'; 1142 case 'c': 1143 return '(\\d?\\d?\\d)'; 1144 case 'z': 1145 return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?'; 1146 case 't': 1147 return getPatternAmpm(o.amNames, o.pmNames); 1148 default: // literal escaped in quotes 1149 return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?'; 1146 1150 } 1147 1151 }) … … 1169 1173 } else { 1170 1174 ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM'; 1171 resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0];1175 resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0]; 1172 1176 } 1173 1177 } 1174 1178 1175 1179 if (order.h !== -1) { 1176 if (ampm == 'AM' && treg[order.h]== '12') {1180 if (ampm === 'AM' && treg[order.h] === '12') { 1177 1181 resTime.hour = 0; // 12am = 0 hour 1178 1182 } else { 1179 if (ampm == 'PM' && treg[order.h] != '12') {1183 if (ampm === 'PM' && treg[order.h] !== '12') { 1180 1184 resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12 1181 1185 } else { … … 1208 1212 1209 1213 // First try JS Date, if that fails, use strictParse 1210 var looseParse = function (f,s,o){1211 try {1212 var d = new Date('2012-01-01 ' + s);1213 if (isNaN(d.getTime())){1214 d = new Date('2012-01-01T' + s);1215 if (isNaN(d.getTime())){1216 d = new Date('01/01/2012 ' + s);1217 if (isNaN(d.getTime())){1218 throw "Unable to parse time with native Date: " + s;1214 var looseParse = function (f, s, o) { 1215 try { 1216 var d = new Date('2012-01-01 ' + s); 1217 if (isNaN(d.getTime())) { 1218 d = new Date('2012-01-01T' + s); 1219 if (isNaN(d.getTime())) { 1220 d = new Date('01/01/2012 ' + s); 1221 if (isNaN(d.getTime())) { 1222 throw "Unable to parse time with native Date: " + s; 1219 1223 } 1220 1224 } … … 1227 1231 millisec: d.getMilliseconds(), 1228 1232 microsec: d.getMicroseconds(), 1229 timezone: d.getTimezoneOffset() *-11233 timezone: d.getTimezoneOffset() * -1 1230 1234 }; 1231 1235 } 1232 catch (err){1233 try {1234 return strictParse(f, s,o);1235 } 1236 catch (err2){1237 $.timepicker.log("Unable to parse \ntimeString: " + s +"\ntimeFormat: "+ f);1236 catch (err) { 1237 try { 1238 return strictParse(f, s, o); 1239 } 1240 catch (err2) { 1241 $.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f); 1238 1242 } 1239 1243 } … … 1241 1245 }; // end looseParse 1242 1246 1243 if (typeof o.parse === "function"){1247 if (typeof o.parse === "function") { 1244 1248 return o.parse(timeFormat, timeString, o); 1245 1249 } 1246 if (o.parse === 'loose'){1250 if (o.parse === 'loose') { 1247 1251 return looseParse(timeFormat, timeString, o); 1248 1252 } … … 1250 1254 }; 1251 1255 1252 /* 1253 * Public utility to format the time 1254 * format = string format of the time 1255 * time = a {}, not a Date() for timezones 1256 * options = essentially the regional[].. amNames, pmNames, ampm 1257 */ 1258 $.datepicker.formatTime = function(format, time, options) { 1256 /** 1257 * Public utility to format the time 1258 * @param {string} format format of the time 1259 * @param {Object} time Object not a Date for timezones 1260 * @param {Object} [options] essentially the regional[].. amNames, pmNames, ampm 1261 * @returns {string} the formatted time 1262 */ 1263 $.datepicker.formatTime = function (format, time, options) { 1259 1264 options = options || {}; 1260 1265 options = $.extend({}, $.timepicker._defaults, options); … … 1264 1269 second: 0, 1265 1270 millisec: 0, 1266 timezone: 0 1271 microsec: 0, 1272 timezone: null 1267 1273 }, time); 1268 1274 … … 1275 1281 } 1276 1282 1277 tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[zZ]|[lc]| ('.*?'|".*?"))/g, function(match) {1278 switch (match) {1283 tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) { 1284 switch (match) { 1279 1285 case 'HH': 1280 1286 return ('0' + hour).slice(-2); … … 1298 1304 return ('00' + time.microsec).slice(-3); 1299 1305 case 'z': 1300 return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, false);1306 return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, false); 1301 1307 case 'Z': 1302 return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, true);1303 case 'T': 1308 return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, true); 1309 case 'T': 1304 1310 return ampmName.charAt(0).toUpperCase(); 1305 case 'TT': 1311 case 'TT': 1306 1312 return ampmName.toUpperCase(); 1307 1313 case 't': … … 1310 1316 return ampmName.toLowerCase(); 1311 1317 default: 1312 return match.replace(/ \'/g, "") || "'";1318 return match.replace(/'/g, ""); 1313 1319 } 1314 1320 }); 1315 1321 1316 tmptime = $.trim(tmptime);1317 1322 return tmptime; 1318 1323 }; 1319 1324 1320 1325 /* 1321 * the bad hack :/ override datepicker so it doesn t close on select1326 * the bad hack :/ override datepicker so it doesn't close on select 1322 1327 // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378 1323 1328 */ 1324 1329 $.datepicker._base_selectDate = $.datepicker._selectDate; 1325 $.datepicker._selectDate = function (id, dateStr) {1330 $.datepicker._selectDate = function (id, dateStr) { 1326 1331 var inst = this._getInst($(id)[0]), 1327 1332 tp_inst = this._get(inst, 'timepicker'); … … 1345 1350 */ 1346 1351 $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker; 1347 $.datepicker._updateDatepicker = function (inst) {1352 $.datepicker._updateDatepicker = function (inst) { 1348 1353 1349 1354 // don't popup the datepicker if there is another instance already opened 1350 1355 var input = inst.input[0]; 1351 if ($.datepicker._curInst && $.datepicker._curInst != inst && $.datepicker._datepickerShowing && $.datepicker._lastInput != input) {1356 if ($.datepicker._curInst && $.datepicker._curInst !== inst && $.datepicker._datepickerShowing && $.datepicker._lastInput !== input) { 1352 1357 return; 1353 1358 } … … 1369 1374 */ 1370 1375 $.datepicker._base_doKeyPress = $.datepicker._doKeyPress; 1371 $.datepicker._doKeyPress = function (event) {1376 $.datepicker._doKeyPress = function (event) { 1372 1377 var inst = $.datepicker._getInst(event.target), 1373 1378 tp_inst = $.datepicker._get(inst, 'timepicker'); … … 1376 1381 if ($.datepicker._get(inst, 'constrainInput')) { 1377 1382 var ampm = tp_inst.support.ampm, 1378 tz = tp_inst._defaults.showTimezone !== null ? tp_inst._defaults.showTimezone : tp_inst.support.timezone,1383 tz = tp_inst._defaults.showTimezone !== null ? tp_inst._defaults.showTimezone : tp_inst.support.timezone, 1379 1384 dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')), 1380 1385 datetimeChars = tp_inst._defaults.timeFormat.toString() … … 1401 1406 /* 1402 1407 * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField 1408 * Update any alternate field to synchronise with the main field. 1403 1409 */ 1404 1410 $.datepicker._base_updateAlternate = $.datepicker._updateAlternate; 1405 /* Update any alternate field to synchronise with the main field. */ 1406 $.datepicker._updateAlternate = function(inst) { 1411 $.datepicker._updateAlternate = function (inst) { 1407 1412 var tp_inst = this._get(inst, 'timepicker'); 1408 if (tp_inst){1413 if (tp_inst) { 1409 1414 var altField = tp_inst._defaults.altField; 1410 1415 if (altField) { // update alternate field too … … 1418 1423 1419 1424 altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix; 1420 if (!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null){1421 if (tp_inst._defaults.altFormat){1425 if (!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null) { 1426 if (tp_inst._defaults.altFormat) { 1422 1427 altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime; 1423 1428 } 1424 else {1429 else { 1425 1430 altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime; 1426 1431 } … … 1429 1434 } 1430 1435 } 1431 else {1436 else { 1432 1437 $.datepicker._base_updateAlternate(inst); 1433 1438 } … … 1438 1443 */ 1439 1444 $.datepicker._base_doKeyUp = $.datepicker._doKeyUp; 1440 $.datepicker._doKeyUp = function (event) {1445 $.datepicker._doKeyUp = function (event) { 1441 1446 var inst = $.datepicker._getInst(event.target), 1442 1447 tp_inst = $.datepicker._get(inst, 'timepicker'); 1443 1448 1444 1449 if (tp_inst) { 1445 if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {1450 if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) { 1446 1451 try { 1447 1452 $.datepicker._updateDatepicker(inst); … … 1459 1464 */ 1460 1465 $.datepicker._base_gotoToday = $.datepicker._gotoToday; 1461 $.datepicker._gotoToday = function (id) {1466 $.datepicker._gotoToday = function (id) { 1462 1467 var inst = this._getInst($(id)[0]), 1463 1468 $dp = inst.dpDiv; … … 1473 1478 * Disable & enable the Time in the datetimepicker 1474 1479 */ 1475 $.datepicker._disableTimepickerDatepicker = function (target) {1480 $.datepicker._disableTimepickerDatepicker = function (target) { 1476 1481 var inst = this._getInst(target); 1477 1482 if (!inst) { … … 1482 1487 $(target).datepicker('getDate'); // Init selected[Year|Month|Day] 1483 1488 if (tp_inst) { 1489 inst.settings.showTimepicker = false; 1484 1490 tp_inst._defaults.showTimepicker = false; 1485 1491 tp_inst._updateDateTime(inst); … … 1487 1493 }; 1488 1494 1489 $.datepicker._enableTimepickerDatepicker = function (target) {1495 $.datepicker._enableTimepickerDatepicker = function (target) { 1490 1496 var inst = this._getInst(target); 1491 1497 if (!inst) { … … 1496 1502 $(target).datepicker('getDate'); // Init selected[Year|Month|Day] 1497 1503 if (tp_inst) { 1504 inst.settings.showTimepicker = true; 1498 1505 tp_inst._defaults.showTimepicker = true; 1499 1506 tp_inst._addTimePicker(inst); // Could be disabled on page load … … 1505 1512 * Create our own set time function 1506 1513 */ 1507 $.datepicker._setTime = function (inst, date) {1514 $.datepicker._setTime = function (inst, date) { 1508 1515 var tp_inst = this._get(inst, 'timepicker'); 1509 1516 if (tp_inst) { … … 1528 1535 * Create new public method to set only time, callable as $().datepicker('setTime', date) 1529 1536 */ 1530 $.datepicker._setTimeDatepicker = function (target, date, withDate) {1537 $.datepicker._setTimeDatepicker = function (target, date, withDate) { 1531 1538 var inst = this._getInst(target); 1532 1539 if (!inst) { … … 1540 1547 var tp_date; 1541 1548 if (date) { 1542 if (typeof date == "string") {1549 if (typeof date === "string") { 1543 1550 tp_inst._parseTime(date, withDate); 1544 1551 tp_date = new Date(); … … 1547 1554 } else { 1548 1555 tp_date = new Date(date.getTime()); 1549 } 1550 if (tp_date.toString() == 'Invalid Date') { 1556 tp_date.setMicroseconds(date.getMicroseconds()); 1557 } 1558 if (tp_date.toString() === 'Invalid Date') { 1551 1559 tp_date = undefined; 1552 1560 } … … 1561 1569 */ 1562 1570 $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker; 1563 $.datepicker._setDateDatepicker = function (target, date) {1571 $.datepicker._setDateDatepicker = function (target, date) { 1564 1572 var inst = this._getInst(target); 1565 1573 if (!inst) { … … 1567 1575 } 1568 1576 1569 var tp_inst = this._get(inst, 'timepicker'), 1570 tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; 1577 if (typeof(date) === 'string') { 1578 date = new Date(date); 1579 if (!date.getTime()) { 1580 $.timepicker.log("Error creating Date object from string."); 1581 } 1582 } 1583 1584 var tp_inst = this._get(inst, 'timepicker'); 1585 var tp_date; 1586 if (date instanceof Date) { 1587 tp_date = new Date(date.getTime()); 1588 tp_date.setMicroseconds(date.getMicroseconds()); 1589 } else { 1590 tp_date = date; 1591 } 1571 1592 1572 1593 // This is important if you are using the timezone option, javascript's Date … … 1574 1595 // adjust it accordingly. If not using timezone option this won't matter.. 1575 1596 // If a timezone is different in tp, keep the timezone as is 1576 if(tp_inst && tp_inst.timezone != null){ 1597 if (tp_inst) { 1598 // look out for DST if tz wasn't specified 1599 if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) { 1600 tp_inst.timezone = tp_date.getTimezoneOffset() * -1; 1601 } 1577 1602 date = $.timepicker.timezoneAdjust(date, tp_inst.timezone); 1578 1603 tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone); … … 1588 1613 */ 1589 1614 $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker; 1590 $.datepicker._getDateDatepicker = function (target, noDefault) {1615 $.datepicker._getDateDatepicker = function (target, noDefault) { 1591 1616 var inst = this._getInst(target); 1592 1617 if (!inst) { … … 1598 1623 if (tp_inst) { 1599 1624 // if it hasn't yet been defined, grab from field 1600 if (inst.lastVal === undefined){1625 if (inst.lastVal === undefined) { 1601 1626 this._setDateFromField(inst, noDefault); 1602 1627 } … … 1610 1635 // object will only return the timezone offset for the current locale, so we 1611 1636 // adjust it accordingly. If not using timezone option this won't matter.. 1612 if(tp_inst.timezone != null){ 1637 if (tp_inst.timezone != null) { 1638 // look out for DST if tz wasn't specified 1639 if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) { 1640 tp_inst.timezone = date.getTimezoneOffset() * -1; 1641 } 1613 1642 date = $.timepicker.timezoneAdjust(date, tp_inst.timezone); 1614 1643 } … … 1624 1653 */ 1625 1654 $.datepicker._base_parseDate = $.datepicker.parseDate; 1626 $.datepicker.parseDate = function (format, value, settings) {1655 $.datepicker.parseDate = function (format, value, settings) { 1627 1656 var date; 1628 1657 try { … … 1633 1662 // attempting to perfectly reproduce the parsing algorithm. 1634 1663 if (err.indexOf(":") >= 0) { 1635 date = this._base_parseDate(format, value.substring(0, value.length-(err.length-err.indexOf(':')-2)), settings);1664 date = this._base_parseDate(format, value.substring(0, value.length - (err.length - err.indexOf(':') - 2)), settings); 1636 1665 $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format); 1637 1666 } else { … … 1646 1675 */ 1647 1676 $.datepicker._base_formatDate = $.datepicker._formatDate; 1648 $.datepicker._formatDate = function (inst, day, month, year) {1677 $.datepicker._formatDate = function (inst, day, month, year) { 1649 1678 var tp_inst = this._get(inst, 'timepicker'); 1650 1679 if (tp_inst) { … … 1659 1688 */ 1660 1689 $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker; 1661 $.datepicker._optionDatepicker = function (target, name, value) {1690 $.datepicker._optionDatepicker = function (target, name, value) { 1662 1691 var inst = this._getInst(target), 1663 name_clone;1692 name_clone; 1664 1693 if (!inst) { 1665 1694 return null; … … 1674 1703 fns = {}, 1675 1704 prop; 1676 if (typeof name== 'string') { // if min/max was set with the string1677 if (name === 'minDate' || name === 'minDateTime') {1678 min = value;1679 } else if (name === 'maxDate' || name === 'maxDateTime') {1680 max = value;1681 } else if (name === 'onSelect') {1682 onselect = value;1683 } else if (overrides.hasOwnProperty(name)) {1684 if (typeof (value) === 'undefined') {1685 return overrides[name];1686 }1687 fns[name] = value;1688 name_clone = {}; //empty results in exiting function after overrides updated1689 }1690 } else if (typeof name== 'object') { //if min/max was set with the JSON1691 if (name.minDate) {1692 min = name.minDate;1693 } else if (name.minDateTime) {1694 min = name.minDateTime;1695 } else if (name.maxDate) {1696 max = name.maxDate;1697 } else if (name.maxDateTime) {1698 max = name.maxDateTime;1699 }1700 for (prop in overrides) {1701 if (overrides.hasOwnProperty(prop) && name[prop]) {1702 fns[prop] = name[prop];1703 }1704 }1705 }1706 for (prop in fns) {1707 if (fns.hasOwnProperty(prop)) {1708 overrides[prop] = fns[prop];1709 if (!name_clone) { name_clone = $.extend({}, name);}1710 delete name_clone[prop];1711 }1712 }1713 if (name_clone && isEmptyObject(name_clone)) { return; }1714 if (min) { //if min was set1715 if (min === 0) {1716 min = new Date();1717 } else {1718 min = new Date(min);1719 }1720 tp_inst._defaults.minDate = min;1721 tp_inst._defaults.minDateTime = min;1722 } else if (max) { //if max was set1723 if (max === 0) {1724 max = new Date();1725 } else {1726 max = new Date(max);1727 }1728 tp_inst._defaults.maxDate = max;1729 tp_inst._defaults.maxDateTime = max;1730 } else if (onselect) {1731 tp_inst._defaults.onSelect = onselect;1732 }1705 if (typeof name === 'string') { // if min/max was set with the string 1706 if (name === 'minDate' || name === 'minDateTime') { 1707 min = value; 1708 } else if (name === 'maxDate' || name === 'maxDateTime') { 1709 max = value; 1710 } else if (name === 'onSelect') { 1711 onselect = value; 1712 } else if (overrides.hasOwnProperty(name)) { 1713 if (typeof (value) === 'undefined') { 1714 return overrides[name]; 1715 } 1716 fns[name] = value; 1717 name_clone = {}; //empty results in exiting function after overrides updated 1718 } 1719 } else if (typeof name === 'object') { //if min/max was set with the JSON 1720 if (name.minDate) { 1721 min = name.minDate; 1722 } else if (name.minDateTime) { 1723 min = name.minDateTime; 1724 } else if (name.maxDate) { 1725 max = name.maxDate; 1726 } else if (name.maxDateTime) { 1727 max = name.maxDateTime; 1728 } 1729 for (prop in overrides) { 1730 if (overrides.hasOwnProperty(prop) && name[prop]) { 1731 fns[prop] = name[prop]; 1732 } 1733 } 1734 } 1735 for (prop in fns) { 1736 if (fns.hasOwnProperty(prop)) { 1737 overrides[prop] = fns[prop]; 1738 if (!name_clone) { name_clone = $.extend({}, name); } 1739 delete name_clone[prop]; 1740 } 1741 } 1742 if (name_clone && isEmptyObject(name_clone)) { return; } 1743 if (min) { //if min was set 1744 if (min === 0) { 1745 min = new Date(); 1746 } else { 1747 min = new Date(min); 1748 } 1749 tp_inst._defaults.minDate = min; 1750 tp_inst._defaults.minDateTime = min; 1751 } else if (max) { //if max was set 1752 if (max === 0) { 1753 max = new Date(); 1754 } else { 1755 max = new Date(max); 1756 } 1757 tp_inst._defaults.maxDate = max; 1758 tp_inst._defaults.maxDateTime = max; 1759 } else if (onselect) { 1760 tp_inst._defaults.onSelect = onselect; 1761 } 1733 1762 } 1734 1763 if (value === undefined) { … … 1742 1771 * it will return false for all objects 1743 1772 */ 1744 var isEmptyObject = function (obj) {1773 var isEmptyObject = function (obj) { 1745 1774 var prop; 1746 1775 for (prop in obj) { 1747 if (obj.hasOwnProperty( obj)) {1776 if (obj.hasOwnProperty(prop)) { 1748 1777 return false; 1749 1778 } … … 1755 1784 * jQuery extend now ignores nulls! 1756 1785 */ 1757 var extendRemove = function (target, props) {1786 var extendRemove = function (target, props) { 1758 1787 $.extend(target, props); 1759 1788 for (var name in props) { … … 1769 1798 * Returns an object of booleans for each unit 1770 1799 */ 1771 var detectSupport = function (timeFormat){1772 var tf = timeFormat.replace(/ \'.*?\'/g,'').toLowerCase(), // removes literals1773 isIn = function (f, t){ // does the format contain the token?1774 return f.indexOf(t) !== -1 ? true:false;1800 var detectSupport = function (timeFormat) { 1801 var tf = timeFormat.replace(/'.*?'/g, '').toLowerCase(), // removes literals 1802 isIn = function (f, t) { // does the format contain the token? 1803 return f.indexOf(t) !== -1 ? true : false; 1775 1804 }; 1776 1805 return { 1777 hour: isIn(tf, 'h'),1778 minute: isIn(tf, 'm'),1779 second: isIn(tf, 's'),1780 millisec: isIn(tf, 'l'),1781 microsec: isIn(tf, 'c'),1782 timezone: isIn(tf, 'z'),1783 ampm: isIn( 't') && isIn(timeFormat,'h'),1806 hour: isIn(tf, 'h'), 1807 minute: isIn(tf, 'm'), 1808 second: isIn(tf, 's'), 1809 millisec: isIn(tf, 'l'), 1810 microsec: isIn(tf, 'c'), 1811 timezone: isIn(tf, 'z'), 1812 ampm: isIn(tf, 't') && isIn(timeFormat, 'h'), 1784 1813 iso8601: isIn(timeFormat, 'Z') 1785 1814 }; … … 1790 1819 * Returns 12 hour without leading 0 1791 1820 */ 1792 var convert24to12 = function(hour) { 1793 if (hour > 12) { 1794 hour = hour - 12; 1795 } 1821 var convert24to12 = function (hour) { 1822 hour %= 12; 1796 1823 1797 1824 if (hour === 0) { … … 1802 1829 }; 1803 1830 1804 /* 1805 * Splits datetime string into date ans time substrings. 1831 var computeEffectiveSetting = function (settings, property) { 1832 return settings && settings[property] ? settings[property] : $.timepicker._defaults[property]; 1833 }; 1834 1835 /* 1836 * Splits datetime string into date and time substrings. 1806 1837 * Throws exception when date can't be parsed 1807 * Returns [dateString, timeString] 1808 */ 1809 var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) { 1810 try { 1811 // The idea is to get the number separator occurances in datetime and the time format requested (since time has 1812 // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split. 1813 var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator, 1814 format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat, 1815 timeParts = format.split(separator), // how many occurances of separator may be in our format? 1816 timePartsLen = timeParts.length, 1817 allParts = dateTimeString.split(separator), 1818 allPartsLen = allParts.length; 1819 1820 if (allPartsLen > 1) { 1821 return [ 1822 allParts.splice(0,allPartsLen-timePartsLen).join(separator), 1823 allParts.splice(0,timePartsLen).join(separator) 1824 ]; 1825 } 1826 1827 } catch (err) { 1828 $.timepicker.log('Could not split the date from the time. Please check the following datetimepicker options' + 1829 "\nthrown error: " + err + 1830 "\ndateTimeString" + dateTimeString + 1831 "\ndateFormat = " + dateFormat + 1832 "\nseparator = " + timeSettings.separator + 1833 "\ntimeFormat = " + timeSettings.timeFormat); 1834 1835 if (err.indexOf(":") >= 0) { 1836 // Hack! The error message ends with a colon, a space, and 1837 // the "extra" characters. We rely on that instead of 1838 // attempting to perfectly reproduce the parsing algorithm. 1839 var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2), 1840 timeString = dateTimeString.substring(dateStringLength); 1841 1842 return [$.trim(dateTimeString.substring(0, dateStringLength)), $.trim(dateTimeString.substring(dateStringLength))]; 1843 1844 } else { 1845 throw err; 1846 } 1847 } 1848 return [dateTimeString, '']; 1838 * Returns {dateString: dateString, timeString: timeString} 1839 */ 1840 var splitDateTime = function (dateTimeString, timeSettings) { 1841 // The idea is to get the number separator occurrences in datetime and the time format requested (since time has 1842 // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split. 1843 var separator = computeEffectiveSetting(timeSettings, 'separator'), 1844 format = computeEffectiveSetting(timeSettings, 'timeFormat'), 1845 timeParts = format.split(separator), // how many occurrences of separator may be in our format? 1846 timePartsLen = timeParts.length, 1847 allParts = dateTimeString.split(separator), 1848 allPartsLen = allParts.length; 1849 1850 if (allPartsLen > 1) { 1851 return { 1852 dateString: allParts.splice(0, allPartsLen - timePartsLen).join(separator), 1853 timeString: allParts.splice(0, timePartsLen).join(separator) 1854 }; 1855 } 1856 1857 return { 1858 dateString: dateTimeString, 1859 timeString: '' 1860 }; 1849 1861 }; 1850 1862 … … 1855 1867 * timeObj = {hour: , minute: , second: , millisec: , microsec: } - parsed time. Optional 1856 1868 */ 1857 var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { 1858 var date; 1859 var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings); 1860 date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings); 1861 if (splitRes[1] !== '') { 1862 var timeString = splitRes[1], 1863 parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings); 1864 1865 if (parsedTime === null) { 1866 throw 'Wrong time format'; 1867 } 1868 return { 1869 date: date, 1870 timeObj: parsedTime 1871 }; 1872 } else { 1869 var parseDateTimeInternal = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { 1870 var date, 1871 parts, 1872 parsedTime; 1873 1874 parts = splitDateTime(dateTimeString, timeSettings); 1875 date = $.datepicker._base_parseDate(dateFormat, parts.dateString, dateSettings); 1876 1877 if (parts.timeString === '') { 1873 1878 return { 1874 1879 date: date 1875 1880 }; 1876 1881 } 1882 1883 parsedTime = $.datepicker.parseTime(timeFormat, parts.timeString, timeSettings); 1884 1885 if (!parsedTime) { 1886 throw 'Wrong time format'; 1887 } 1888 1889 return { 1890 date: date, 1891 timeObj: parsedTime 1892 }; 1877 1893 }; 1878 1894 … … 1880 1896 * Internal function to set timezone_select to the local timezone 1881 1897 */ 1882 var selectLocalTimezone = function (tp_inst, date) {1898 var selectLocalTimezone = function (tp_inst, date) { 1883 1899 if (tp_inst && tp_inst.timezone_select) { 1884 var now = typeof date !== 'undefined' ? date :new Date();1885 tp_inst.timezone_select.val( now.getTimezoneOffset()*-1);1886 } 1887 }; 1888 1889 /* 1890 * Create a Singleton Ins ance1900 var now = date || new Date(); 1901 tp_inst.timezone_select.val(-now.getTimezoneOffset()); 1902 } 1903 }; 1904 1905 /* 1906 * Create a Singleton Instance 1891 1907 */ 1892 1908 $.timepicker = new Timepicker(); … … 1894 1910 /** 1895 1911 * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5) 1896 * @param number if not a numberthis value is returned1897 * @param booleanif true formats in accordance to iso8601 "+12:45"1898 * @return string1912 * @param {number} tzMinutes if not a number, less than -720 (-1200), or greater than 840 (+1400) this value is returned 1913 * @param {boolean} iso8601 if true formats in accordance to iso8601 "+12:45" 1914 * @return {string} 1899 1915 */ 1900 $.timepicker.timezoneOffsetString = function (tzMinutes, iso8601) {1901 if (isNaN(tzMinutes) || tzMinutes > 840){1916 $.timepicker.timezoneOffsetString = function (tzMinutes, iso8601) { 1917 if (isNaN(tzMinutes) || tzMinutes > 840 || tzMinutes < -720) { 1902 1918 return tzMinutes; 1903 1919 } … … 1906 1922 minutes = off % 60, 1907 1923 hours = (off - minutes) / 60, 1908 iso = iso8601 ? ':':'',1909 tz = (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + iso + ('0' + (minutes * 101).toString()).slice(-2);1924 iso = iso8601 ? ':' : '', 1925 tz = (off >= 0 ? '+' : '-') + ('0' + Math.abs(hours)).slice(-2) + iso + ('0' + Math.abs(minutes)).slice(-2); 1910 1926 1911 if (tz == '+00:00'){1927 if (tz === '+00:00') { 1912 1928 return 'Z'; 1913 1929 } … … 1917 1933 /** 1918 1934 * Get the number in minutes that represents a timezone string 1919 * @param string formated like "+0500", "-1245"1920 * @return number1935 * @param {string} tzString formatted like "+0500", "-1245", "Z" 1936 * @return {number} the offset minutes or the original string if it doesn't match expectations 1921 1937 */ 1922 $.timepicker.timezoneOffsetNumber = function (tzString) {1923 tzString = tzString.toString().replace(':',''); // excuse any iso8601, end up with "+1245"1924 1925 if (tzString.toUpperCase() === 'Z'){ // if iso8601 with Z, its 0 minute offset1938 $.timepicker.timezoneOffsetNumber = function (tzString) { 1939 var normalized = tzString.toString().replace(':', ''); // excuse any iso8601, end up with "+1245" 1940 1941 if (normalized.toUpperCase() === 'Z') { // if iso8601 with Z, its 0 minute offset 1926 1942 return 0; 1927 1943 } 1928 1944 1929 if (!/^(\-|\+)\d{4}$/.test(tzString)){ // possibly a user defined tz, so just give it back1945 if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back 1930 1946 return tzString; 1931 1947 } 1932 1948 1933 return (( tzString.substr(0,1) =='-'? -1 : 1) * // plus or minus1934 ((parseInt( tzString.substr(1,2),10)*60) + // hours (converted to minutes)1935 parseInt( tzString.substr(3,2),10))); // minutes1949 return ((normalized.substr(0, 1) === '-' ? -1 : 1) * // plus or minus 1950 ((parseInt(normalized.substr(1, 2), 10) * 60) + // hours (converted to minutes) 1951 parseInt(normalized.substr(3, 2), 10))); // minutes 1936 1952 }; 1937 1953 1938 1954 /** 1939 1955 * No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate) 1940 * @param date1941 * @param string formated like "+0500", "-1245"1942 * @return date1956 * @param {Date} date 1957 * @param {string} toTimezone formatted like "+0500", "-1245" 1958 * @return {Date} 1943 1959 */ 1944 $.timepicker.timezoneAdjust = function (date, toTimezone) {1960 $.timepicker.timezoneAdjust = function (date, toTimezone) { 1945 1961 var toTz = $.timepicker.timezoneOffsetNumber(toTimezone); 1946 if(!isNaN(toTz)){ 1947 var currTz = date.getTimezoneOffset()*-1, 1948 diff = currTz - toTz; // difference in minutes 1949 1950 date.setMinutes(date.getMinutes()+diff); 1962 if (!isNaN(toTz)) { 1963 date.setMinutes(date.getMinutes() + -date.getTimezoneOffset() - toTz); 1951 1964 } 1952 1965 return date; … … 1957 1970 * enforce date range limits. 1958 1971 * n.b. The input value must be correctly formatted (reformatting is not supported) 1959 * @param ElementstartTime1960 * @param ElementendTime1961 * @param objoptions Options for the timepicker() call1962 * @return jQuery1972 * @param {Element} startTime 1973 * @param {Element} endTime 1974 * @param {Object} options Options for the timepicker() call 1975 * @return {jQuery} 1963 1976 */ 1964 $.timepicker.timeRange = function (startTime, endTime, options) {1977 $.timepicker.timeRange = function (startTime, endTime, options) { 1965 1978 return $.timepicker.handleRange('timepicker', startTime, endTime, options); 1966 1979 }; … … 1969 1982 * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to 1970 1983 * enforce date range limits. 1971 * @param ElementstartTime1972 * @param ElementendTime1973 * @param objoptions Options for the `timepicker()` call. Also supports `reformat`,1984 * @param {Element} startTime 1985 * @param {Element} endTime 1986 * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`, 1974 1987 * a boolean value that can be used to reformat the input values to the `dateFormat`. 1975 * @param stringmethod Can be used to specify the type of picker to be added1976 * @return jQuery1988 * @param {string} method Can be used to specify the type of picker to be added 1989 * @return {jQuery} 1977 1990 */ 1978 $.timepicker.datetimeRange = function (startTime, endTime, options) {1991 $.timepicker.datetimeRange = function (startTime, endTime, options) { 1979 1992 $.timepicker.handleRange('datetimepicker', startTime, endTime, options); 1993 }; 1994 1995 /** 1996 * Calls `datepicker` on the `startTime` and `endTime` elements, and configures them to 1997 * enforce date range limits. 1998 * @param {Element} startTime 1999 * @param {Element} endTime 2000 * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`, 2001 * a boolean value that can be used to reformat the input values to the `dateFormat`. 2002 * @return {jQuery} 2003 */ 2004 $.timepicker.dateRange = function (startTime, endTime, options) { 2005 $.timepicker.handleRange('datepicker', startTime, endTime, options); 1980 2006 }; 1981 2007 … … 1983 2009 * Calls `method` on the `startTime` and `endTime` elements, and configures them to 1984 2010 * enforce date range limits. 1985 * @param Element startTime 1986 * @param Element endTime 1987 * @param obj options Options for the `timepicker()` call. Also supports `reformat`, 2011 * @param {string} method Can be used to specify the type of picker to be added 2012 * @param {Element} startTime 2013 * @param {Element} endTime 2014 * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`, 1988 2015 * a boolean value that can be used to reformat the input values to the `dateFormat`. 1989 * @return jQuery2016 * @return {jQuery} 1990 2017 */ 1991 $.timepicker.dateRange = function(startTime, endTime, options) { 1992 $.timepicker.handleRange('datepicker', startTime, endTime, options); 1993 }; 1994 1995 /** 1996 * Calls `method` on the `startTime` and `endTime` elements, and configures them to 1997 * enforce date range limits. 1998 * @param string method Can be used to specify the type of picker to be added 1999 * @param Element startTime 2000 * @param Element endTime 2001 * @param obj options Options for the `timepicker()` call. Also supports `reformat`, 2002 * a boolean value that can be used to reformat the input values to the `dateFormat`. 2003 * @return jQuery 2004 */ 2005 $.timepicker.handleRange = function(method, startTime, endTime, options) { 2018 $.timepicker.handleRange = function (method, startTime, endTime, options) { 2006 2019 options = $.extend({}, { 2007 2020 minInterval: 0, // min allowed interval in milliseconds … … 2011 2024 }, options); 2012 2025 2013 $.fn[method].call(startTime, $.extend({2014 onClose: function(dateText, inst) {2015 checkDates($(this), endTime);2016 },2017 onSelect: function(selectedDateTime) {2018 selected($(this), endTime, 'minDate');2019 }2020 }, options, options.start));2021 $.fn[method].call(endTime, $.extend({2022 onClose: function(dateText, inst) {2023 checkDates($(this), startTime);2024 },2025 onSelect: function(selectedDateTime) {2026 selected($(this), startTime, 'maxDate');2027 }2028 }, options, options.end));2029 2030 checkDates(startTime, endTime);2031 selected(startTime, endTime, 'minDate');2032 selected(endTime, startTime, 'maxDate');2033 2034 2026 function checkDates(changed, other) { 2035 2027 var startdt = startTime[method]('getDate'), … … 2037 2029 changeddt = changed[method]('getDate'); 2038 2030 2039 if (startdt !== null){2031 if (startdt !== null) { 2040 2032 var minDate = new Date(startdt.getTime()), 2041 2033 maxDate = new Date(startdt.getTime()); … … 2044 2036 maxDate.setMilliseconds(maxDate.getMilliseconds() + options.maxInterval); 2045 2037 2046 if (options.minInterval > 0 && minDate > enddt){ // minInterval check2047 endTime[method]('setDate', minDate);2048 } 2049 else if (options.maxInterval > 0 && maxDate < enddt){ // max interval check2050 endTime[method]('setDate', maxDate);2038 if (options.minInterval > 0 && minDate > enddt) { // minInterval check 2039 endTime[method]('setDate', minDate); 2040 } 2041 else if (options.maxInterval > 0 && maxDate < enddt) { // max interval check 2042 endTime[method]('setDate', maxDate); 2051 2043 } 2052 2044 else if (startdt > enddt) { 2053 other[method]('setDate', changeddt);2045 other[method]('setDate', changeddt); 2054 2046 } 2055 2047 } … … 2061 2053 } 2062 2054 var date = changed[method].call(changed, 'getDate'); 2063 if (date !== null && options.minInterval > 0){2064 if (option == 'minDate'){2065 date.setMilliseconds(date.getMilliseconds() + options.minInterval); 2066 } 2067 if (option == 'maxDate'){2055 if (date !== null && options.minInterval > 0) { 2056 if (option === 'minDate') { 2057 date.setMilliseconds(date.getMilliseconds() + options.minInterval); 2058 } 2059 if (option === 'maxDate') { 2068 2060 date.setMilliseconds(date.getMilliseconds() - options.minInterval); 2069 2061 } … … 2073 2065 } 2074 2066 } 2067 2068 $.fn[method].call(startTime, $.extend({ 2069 onClose: function (dateText, inst) { 2070 checkDates($(this), endTime); 2071 }, 2072 onSelect: function (selectedDateTime) { 2073 selected($(this), endTime, 'minDate'); 2074 } 2075 }, options, options.start)); 2076 $.fn[method].call(endTime, $.extend({ 2077 onClose: function (dateText, inst) { 2078 checkDates($(this), startTime); 2079 }, 2080 onSelect: function (selectedDateTime) { 2081 selected($(this), startTime, 'maxDate'); 2082 } 2083 }, options, options.end)); 2084 2085 checkDates(startTime, endTime); 2086 selected(startTime, endTime, 'minDate'); 2087 selected(endTime, startTime, 'maxDate'); 2075 2088 return $([startTime.get(0), endTime.get(0)]); 2076 2089 }; … … 2078 2091 /** 2079 2092 * Log error or data to the console during error or debugging 2080 * @param Objecterr pass any type object to log to the console during error or debugging2081 * @return void2093 * @param {Object} err pass any type object to log to the console during error or debugging 2094 * @return {void} 2082 2095 */ 2083 $.timepicker.log = function(err){ 2084 if(window.console){ 2085 console.log(err); 2086 } 2087 }; 2088 2089 /* 2090 * Rough microsecond support 2091 */ 2092 if(!Date.prototype.getMicroseconds){ 2093 Date.microseconds = 0; 2094 Date.prototype.getMicroseconds = function(){ return this.microseconds; }; 2095 Date.prototype.setMicroseconds = function(m){ this.microseconds = m; return this; }; 2096 $.timepicker.log = function (err) { 2097 if (window.console) { 2098 window.console.log(err); 2099 } 2100 }; 2101 2102 /* 2103 * Add util object to allow access to private methods for testability. 2104 */ 2105 $.timepicker._util = { 2106 _extendRemove: extendRemove, 2107 _isEmptyObject: isEmptyObject, 2108 _convert24to12: convert24to12, 2109 _detectSupport: detectSupport, 2110 _selectLocalTimezone: selectLocalTimezone, 2111 _computeEffectiveSetting: computeEffectiveSetting, 2112 _splitDateTime: splitDateTime, 2113 _parseDateTimeInternal: parseDateTimeInternal 2114 }; 2115 2116 /* 2117 * Microsecond support 2118 */ 2119 if (!Date.prototype.getMicroseconds) { 2120 Date.prototype.microseconds = 0; 2121 Date.prototype.getMicroseconds = function () { return this.microseconds; }; 2122 Date.prototype.setMicroseconds = function (m) { 2123 this.setMilliseconds(this.getMilliseconds() + Math.floor(m / 1000)); 2124 this.microseconds = m % 1000; 2125 return this; 2126 }; 2096 2127 } 2097 2128 … … 2099 2130 * Keep up with the version 2100 2131 */ 2101 $.timepicker.version = "1. 3";2132 $.timepicker.version = "1.4"; 2102 2133 2103 2134 })(jQuery);
Note: See TracChangeset
for help on using the changeset viewer.