From dba3bcc2aa9aac319e8773b59c97bfaa500ca33c Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 20 Aug 2013 18:37:09 +0000 Subject: [PATCH] Update timepicker, some work on date-timeonly so it returns a value --- etemplate/js/et2_widget_date.js | 6 +- .../js/jquery/jquery-ui-timepicker-addon.js | 3268 ++++++++++------- phpgwapi/js/jsapi/egw_calendar.js | 2 +- 3 files changed, 2044 insertions(+), 1232 deletions(-) diff --git a/etemplate/js/et2_widget_date.js b/etemplate/js/et2_widget_date.js index 2023616e96..5b40ed37bf 100644 --- a/etemplate/js/et2_widget_date.js +++ b/etemplate/js/et2_widget_date.js @@ -179,6 +179,10 @@ var et2_date = et2_inputWidget.extend( { current += " "; } + else + { + current = ''; + } this.input_date.val(current + jQuery.datepicker.formatTime(this.input_date.datepicker("option","timeFormat"),{ hour: this.date.getHours(), minute: this.date.getMinutes(), @@ -200,7 +204,7 @@ var et2_date = et2_inputWidget.extend( } if(this._type == "date-timeonly") { - return this.value; + return this.input_date.val(); } else { diff --git a/phpgwapi/js/jquery/jquery-ui-timepicker-addon.js b/phpgwapi/js/jquery/jquery-ui-timepicker-addon.js index bd6cceb916..ab1d9b1836 100644 --- a/phpgwapi/js/jquery/jquery-ui-timepicker-addon.js +++ b/phpgwapi/js/jquery/jquery-ui-timepicker-addon.js @@ -1,1326 +1,2134 @@ -/* -* jQuery timepicker addon -* By: Trent Richardson [http://trentrichardson.com] -* Version 0.9.9 -* Last Modified: 02/05/2012 -* -* Copyright 2012 Trent Richardson -* Dual licensed under the MIT and GPL licenses. -* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt -* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt -* -* HERES THE CSS: -* .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } -* .ui-timepicker-div dl { text-align: left; } -* .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; } -* .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; } -* .ui-timepicker-div td { font-size: 90%; } -* .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } -*/ +/*! jQuery Timepicker Addon - v1.4 - 2013-08-11 +* http://trentrichardson.com/examples/timepicker +* Copyright (c) 2013 Trent Richardson; Licensed MIT */ +(function ($) { -(function($) { + /* + * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded" + */ + $.ui.timepicker = $.ui.timepicker || {}; + if ($.ui.timepicker.version) { + return; + } -$.extend($.ui, { timepicker: { version: "0.9.9" } }); + /* + * Extend jQueryUI, get it started with our version number + */ + $.extend($.ui, { + timepicker: { + version: "1.4" + } + }); -/* Time picker manager. - Use the singleton instance of this class, $.timepicker, to interact with the time picker. - Settings for (groups of) time pickers are maintained in an instance object, - allowing multiple different settings on the same page. */ - -function Timepicker() { - this.regional = []; // Available regional settings, indexed by language code - this.regional[''] = { // Default regional settings - currentText: 'Now', - closeText: 'Done', - ampm: false, - amNames: ['AM', 'A'], - pmNames: ['PM', 'P'], - timeFormat: 'hh:mm tt', - timeSuffix: '', - timeOnlyTitle: 'Choose Time', - timeText: 'Time', - hourText: 'Hour', - minuteText: 'Minute', - secondText: 'Second', - millisecText: 'Millisecond', - timezoneText: 'Time Zone' + /* + * Timepicker manager. + * Use the singleton instance of this class, $.timepicker, to interact with the time picker. + * Settings for (groups of) time pickers are maintained in an instance object, + * allowing multiple different settings on the same page. + */ + var Timepicker = function () { + this.regional = []; // Available regional settings, indexed by language code + this.regional[''] = { // Default regional settings + currentText: 'Now', + closeText: 'Done', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], + timeFormat: 'HH:mm', + timeSuffix: '', + timeOnlyTitle: 'Choose Time', + timeText: 'Time', + hourText: 'Hour', + minuteText: 'Minute', + secondText: 'Second', + millisecText: 'Millisecond', + microsecText: 'Microsecond', + timezoneText: 'Time Zone', + isRTL: false + }; + this._defaults = { // Global defaults for all the datetime picker instances + showButtonPanel: true, + timeOnly: false, + showHour: null, + showMinute: null, + showSecond: null, + showMillisec: null, + showMicrosec: null, + showTimezone: null, + showTime: true, + stepHour: 1, + stepMinute: 1, + stepSecond: 1, + stepMillisec: 1, + stepMicrosec: 1, + hour: 0, + minute: 0, + second: 0, + millisec: 0, + microsec: 0, + timezone: null, + hourMin: 0, + minuteMin: 0, + secondMin: 0, + millisecMin: 0, + microsecMin: 0, + hourMax: 23, + minuteMax: 59, + secondMax: 59, + millisecMax: 999, + microsecMax: 999, + minDateTime: null, + maxDateTime: null, + onSelect: null, + hourGrid: 0, + minuteGrid: 0, + secondGrid: 0, + millisecGrid: 0, + microsecGrid: 0, + alwaysSetTime: true, + separator: ' ', + altFieldTimeOnly: true, + altTimeFormat: null, + altSeparator: null, + altTimeSuffix: null, + pickerTimeFormat: null, + pickerTimeSuffix: null, + showTimepicker: true, + timezoneList: null, + addSliderAccess: false, + sliderAccessArgs: null, + controlType: 'slider', + defaultValue: null, + parse: 'strict' + }; + $.extend(this._defaults, this.regional['']); }; - this._defaults = { // Global defaults for all the datetime picker instances - showButtonPanel: true, - timeOnly: false, - showHour: true, - showMinute: true, - showSecond: false, - showMillisec: false, - showTimezone: false, - showTime: true, - stepHour: 1, - stepMinute: 1, - stepSecond: 1, - stepMillisec: 1, + + $.extend(Timepicker.prototype, { + $input: null, + $altInput: null, + $timeObj: null, + inst: null, + hour_slider: null, + minute_slider: null, + second_slider: null, + millisec_slider: null, + microsec_slider: null, + timezone_select: null, hour: 0, minute: 0, second: 0, millisec: 0, - timezone: '+0000', - hourMin: 0, - minuteMin: 0, - secondMin: 0, - millisecMin: 0, - hourMax: 23, - minuteMax: 59, - secondMax: 59, - millisecMax: 999, - minDateTime: null, - maxDateTime: null, - onSelect: null, - hourGrid: 0, - minuteGrid: 0, - secondGrid: 0, - millisecGrid: 0, - alwaysSetTime: true, - separator: ' ', - altFieldTimeOnly: true, - showTimepicker: true, - timezoneIso8609: false, + microsec: 0, + timezone: null, + hourMinOriginal: null, + minuteMinOriginal: null, + secondMinOriginal: null, + millisecMinOriginal: null, + microsecMinOriginal: null, + hourMaxOriginal: null, + minuteMaxOriginal: null, + secondMaxOriginal: null, + millisecMaxOriginal: null, + microsecMaxOriginal: null, + ampm: '', + formattedDate: '', + formattedTime: '', + formattedDateTime: '', timezoneList: null, - addSliderAccess: false, - sliderAccessArgs: null - }; - $.extend(this._defaults, this.regional['']); -}; + units: ['hour', 'minute', 'second', 'millisec', 'microsec'], + support: {}, + control: null, -$.extend(Timepicker.prototype, { - $input: null, - $altInput: null, - $timeObj: null, - inst: null, - hour_slider: null, - minute_slider: null, - second_slider: null, - millisec_slider: null, - timezone_select: null, - hour: 0, - minute: 0, - second: 0, - millisec: 0, - timezone: '+0000', - hourMinOriginal: null, - minuteMinOriginal: null, - secondMinOriginal: null, - millisecMinOriginal: null, - hourMaxOriginal: null, - minuteMaxOriginal: null, - secondMaxOriginal: null, - millisecMaxOriginal: null, - ampm: '', - formattedDate: '', - formattedTime: '', - formattedDateTime: '', - timezoneList: null, + /* + * Override the default settings for all instances of the time picker. + * @param {Object} settings object - the new settings to use as defaults (anonymous object) + * @return {Object} the manager object + */ + setDefaults: function (settings) { + extendRemove(this._defaults, settings || {}); + return this; + }, - /* Override the default settings for all instances of the time picker. - @param settings object - the new settings to use as defaults (anonymous object) - @return the manager object */ - setDefaults: function(settings) { - extendRemove(this._defaults, settings || {}); - return this; - }, + /* + * Create a new Timepicker instance + */ + _newInst: function ($input, opts) { + var tp_inst = new Timepicker(), + inlineSettings = {}, + fns = {}, + overrides, i; - //######################################################################## - // Create a new Timepicker instance - //######################################################################## - _newInst: function($input, o) { - var tp_inst = new Timepicker(), - inlineSettings = {}; - - for (var attrName in this._defaults) { - var attrValue = $input.attr('time:' + attrName); - if (attrValue) { - try { - inlineSettings[attrName] = eval(attrValue); - } catch (err) { - inlineSettings[attrName] = attrValue; - } - } - } - tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, { - beforeShow: function(input, dp_inst) { - if ($.isFunction(o.beforeShow)) - return o.beforeShow(input, dp_inst, tp_inst); - }, - onChangeMonthYear: function(year, month, dp_inst) { - // Update the time as well : this prevents the time from disappearing from the $input field. - tp_inst._updateDateTime(dp_inst); - if ($.isFunction(o.onChangeMonthYear)) - o.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); - }, - onClose: function(dateText, dp_inst) { - if (tp_inst.timeDefined === true && $input.val() != '') - tp_inst._updateDateTime(dp_inst); - if ($.isFunction(o.onClose)) - o.onClose.call($input[0], dateText, dp_inst, tp_inst); - }, - timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); - }); - tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() }); - tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase() }); - - if (tp_inst._defaults.timezoneList === null) { - var timezoneList = []; - for (var i = -11; i <= 12; i++) - timezoneList.push((i >= 0 ? '+' : '-') + ('0' + Math.abs(i).toString()).slice(-2) + '00'); - if (tp_inst._defaults.timezoneIso8609) - timezoneList = $.map(timezoneList, function(val) { - return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); - }); - tp_inst._defaults.timezoneList = timezoneList; - } - - tp_inst.hour = tp_inst._defaults.hour; - tp_inst.minute = tp_inst._defaults.minute; - tp_inst.second = tp_inst._defaults.second; - tp_inst.millisec = tp_inst._defaults.millisec; - tp_inst.ampm = ''; - tp_inst.$input = $input; - - if (o.altField) - tp_inst.$altInput = $(o.altField) - .css({ cursor: 'pointer' }) - .focus(function(){ $input.trigger("focus"); }); - - if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0) - { - tp_inst._defaults.minDate=new Date(); - } - if(tp_inst._defaults.maxDate==0 || tp_inst._defaults.maxDateTime==0) - { - tp_inst._defaults.maxDate=new Date(); - } - - // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. - if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) - tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); - if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) - tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); - if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) - tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); - if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) - tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); - return tp_inst; - }, - - //######################################################################## - // add our sliders to the calendar - //######################################################################## - _addTimePicker: function(dp_inst) { - var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? - this.$input.val() + ' ' + this.$altInput.val() : - this.$input.val(); - - this.timeDefined = this._parseTime(currDT); - this._limitMinMaxDateTime(dp_inst, false); - this._injectTimePicker(); - }, - - //######################################################################## - // parse the time string from input value or _setTime - //######################################################################## - _parseTime: function(timeString, withDate) { - var regstr = this._defaults.timeFormat.toString() - .replace(/h{1,2}/ig, '(\\d?\\d)') - .replace(/m{1,2}/ig, '(\\d?\\d)') - .replace(/s{1,2}/ig, '(\\d?\\d)') - .replace(/l{1}/ig, '(\\d?\\d?\\d)') - .replace(/t{1,2}/ig, this._getPatternAmpm()) - .replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?') - .replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$', - order = this._getFormatPositions(), - ampm = '', - treg; - - if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]); - - if (withDate || !this._defaults.timeOnly) { - // the time should come after x number of characters and a space. - // x = at least the length of text specified by the date format - var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); - // escape special regex characters in the seperator - var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); - regstr = '^.{' + dp_dateFormat.length + ',}?' + this._defaults.separator.replace(specials, "\\$&") + regstr; - } - - treg = timeString.match(new RegExp(regstr, 'i')); - - if (treg) { - if (order.t !== -1) { - if (treg[order.t] === undefined || treg[order.t].length === 0) { - ampm = ''; - this.ampm = ''; - } else { - ampm = $.inArray(treg[order.t].toUpperCase(), this.amNames) !== -1 ? 'AM' : 'PM'; - this.ampm = this._defaults[ampm == 'AM' ? 'amNames' : 'pmNames'][0]; - } - } - - if (order.h !== -1) { - if (ampm == 'AM' && treg[order.h] == '12') - this.hour = 0; // 12am = 0 hour - else if (ampm == 'PM' && treg[order.h] != '12') - this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12 - else this.hour = Number(treg[order.h]); - } - - if (order.m !== -1) this.minute = Number(treg[order.m]); - if (order.s !== -1) this.second = Number(treg[order.s]); - if (order.l !== -1) this.millisec = Number(treg[order.l]); - if (order.z !== -1 && treg[order.z] !== undefined) { - var tz = treg[order.z].toUpperCase(); - switch (tz.length) { - case 1: // Z - tz = this._defaults.timezoneIso8609 ? 'Z' : '+0000'; - break; - case 5: // +hhmm - if (this._defaults.timezoneIso8609) - tz = tz.substring(1) == '0000' - ? 'Z' - : tz.substring(0, 3) + ':' + tz.substring(3); - break; - case 6: // +hh:mm - if (!this._defaults.timezoneIso8609) - tz = tz == 'Z' || tz.substring(1) == '00:00' - ? '+0000' - : tz.replace(/:/, ''); - else if (tz.substring(1) == '00:00') - tz = 'Z'; - break; - } - this.timezone = tz; - } - - return true; - - } - return false; - }, - - //######################################################################## - // pattern for standard and localized AM/PM markers - //######################################################################## - _getPatternAmpm: function() { - var markers = []; - o = this._defaults; - if (o.amNames) - $.merge(markers, o.amNames); - if (o.pmNames) - $.merge(markers, o.pmNames); - markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&') }); - return '(' + markers.join('|') + ')?'; - }, - - //######################################################################## - // figure out position of time elements.. cause js cant do named captures - //######################################################################## - _getFormatPositions: function() { - var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g), - orders = { h: -1, m: -1, s: -1, l: -1, t: -1, z: -1 }; - - if (finds) - for (var i = 0; i < finds.length; i++) - if (orders[finds[i].toString().charAt(0)] == -1) - orders[finds[i].toString().charAt(0)] = i + 1; - - return orders; - }, - - //######################################################################## - // generate and inject html for timepicker into ui datepicker - //######################################################################## - _injectTimePicker: function() { - var $dp = this.inst.dpDiv, - o = this._defaults, - tp_inst = this, - // Added by Peter Medeiros: - // - Figure out what the hour/minute/second max should be based on the step values. - // - Example: if stepMinute is 15, then minMax is 45. - hourMax = parseInt((o.hourMax - ((o.hourMax - o.hourMin) % o.stepHour)) ,10), - minMax = parseInt((o.minuteMax - ((o.minuteMax - o.minuteMin) % o.stepMinute)) ,10), - secMax = parseInt((o.secondMax - ((o.secondMax - o.secondMin) % o.stepSecond)) ,10), - millisecMax = parseInt((o.millisecMax - ((o.millisecMax - o.millisecMin) % o.stepMillisec)) ,10), - dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, ''); - - // Prevent displaying twice - //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) { - if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) { - var noDisplay = ' style="display:none;"', - html = '
' + - '
' + o.timeText + '
' + - '
' + - '
' + o.hourText + '
', - hourGridSize = 0, - minuteGridSize = 0, - secondGridSize = 0, - millisecGridSize = 0, - size; - - // Hours - html += '
'; - if (o.showHour && o.hourGrid > 0) { - html += '
'; - - for (var h = o.hourMin; h <= hourMax; h += parseInt(o.hourGrid,10)) { - hourGridSize++; - var tmph = (o.ampm && h > 12) ? h-12 : h; - if (tmph < 10) tmph = '0' + tmph; - if (o.ampm) { - if (h == 0) tmph = 12 +'a'; - else if (h < 12) tmph += 'a'; - else tmph += 'p'; + for (var attrName in this._defaults) { + if (this._defaults.hasOwnProperty(attrName)) { + var attrValue = $input.attr('time:' + attrName); + if (attrValue) { + try { + inlineSettings[attrName] = eval(attrValue); + } catch (err) { + inlineSettings[attrName] = attrValue; + } } - html += ''; } - - html += '
' + tmph + '
'; } - html += '
'; - // Minutes - html += '
' + o.minuteText + '
'+ - '
'; - - if (o.showMinute && o.minuteGrid > 0) { - html += '
'; - - for (var m = o.minuteMin; m <= minMax; m += parseInt(o.minuteGrid,10)) { - minuteGridSize++; - html += ''; + overrides = { + beforeShow: function (input, dp_inst) { + if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { + return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst); + } + }, + onChangeMonthYear: function (year, month, dp_inst) { + // Update the time as well : this prevents the time from disappearing from the $input field. + tp_inst._updateDateTime(dp_inst); + if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) { + tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); + } + }, + onClose: function (dateText, dp_inst) { + if (tp_inst.timeDefined === true && $input.val() !== '') { + tp_inst._updateDateTime(dp_inst); + } + if ($.isFunction(tp_inst._defaults.evnts.onClose)) { + tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); + } } - - html += '
' + ((m < 10) ? '0' : '') + m + '
'; - } - html += '
'; - - // Seconds - html += '
' + o.secondText + '
'+ - '
'; - - if (o.showSecond && o.secondGrid > 0) { - html += '
'; - - for (var s = o.secondMin; s <= secMax; s += parseInt(o.secondGrid,10)) { - secondGridSize++; - html += ''; + }; + for (i in overrides) { + if (overrides.hasOwnProperty(i)) { + fns[i] = opts[i] || null; } - - html += '
' + ((s < 10) ? '0' : '') + s + '
'; } - html += '
'; - // Milliseconds - html += '
' + o.millisecText + '
'+ - '
'; + tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, opts, overrides, { + evnts: fns, + timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); + }); + tp_inst.amNames = $.map(tp_inst._defaults.amNames, function (val) { + return val.toUpperCase(); + }); + tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function (val) { + return val.toUpperCase(); + }); - if (o.showMillisec && o.millisecGrid > 0) { - html += '
'; + // detect which units are supported + tp_inst.support = detectSupport( + tp_inst._defaults.timeFormat + + (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') + + (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : '')); - for (var l = o.millisecMin; l <= millisecMax; l += parseInt(o.millisecGrid,10)) { - millisecGridSize++; - html += ''; + // controlType is string - key to our this._controls + if (typeof(tp_inst._defaults.controlType) === 'string') { + if (tp_inst._defaults.controlType === 'slider' && typeof($.ui.slider) === 'undefined') { + tp_inst._defaults.controlType = 'select'; } - - html += '
' + ((l < 10) ? '0' : '') + l + '
'; + tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType]; + } + // controlType is an object and must implement create, options, value methods + else { + tp_inst.control = tp_inst._defaults.controlType; } - html += '
'; - // Timezone - html += '
' + o.timezoneText + '
'; - html += '
'; + // prep the timezone options + var timezoneList = [-720, -660, -600, -570, -540, -480, -420, -360, -300, -270, -240, -210, -180, -120, -60, + 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]; + if (tp_inst._defaults.timezoneList !== null) { + timezoneList = tp_inst._defaults.timezoneList; + } + var tzl = timezoneList.length, tzi = 0, tzv = null; + if (tzl > 0 && typeof timezoneList[0] !== 'object') { + for (; tzi < tzl; tzi++) { + tzv = timezoneList[tzi]; + timezoneList[tzi] = { value: tzv, label: $.timepicker.timezoneOffsetString(tzv, tp_inst.support.iso8601) }; + } + } + tp_inst._defaults.timezoneList = timezoneList; - html += '
'; - $tp = $(html); + // set the default units + tp_inst.timezone = tp_inst._defaults.timezone !== null ? $.timepicker.timezoneOffsetNumber(tp_inst._defaults.timezone) : + ((new Date()).getTimezoneOffset() * -1); + tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin ? tp_inst._defaults.hourMin : + tp_inst._defaults.hour > tp_inst._defaults.hourMax ? tp_inst._defaults.hourMax : tp_inst._defaults.hour; + tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin ? tp_inst._defaults.minuteMin : + tp_inst._defaults.minute > tp_inst._defaults.minuteMax ? tp_inst._defaults.minuteMax : tp_inst._defaults.minute; + tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin ? tp_inst._defaults.secondMin : + tp_inst._defaults.second > tp_inst._defaults.secondMax ? tp_inst._defaults.secondMax : tp_inst._defaults.second; + tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin ? tp_inst._defaults.millisecMin : + tp_inst._defaults.millisec > tp_inst._defaults.millisecMax ? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec; + tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin ? tp_inst._defaults.microsecMin : + tp_inst._defaults.microsec > tp_inst._defaults.microsecMax ? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec; + tp_inst.ampm = ''; + tp_inst.$input = $input; + + if (tp_inst._defaults.altField) { + tp_inst.$altInput = $(tp_inst._defaults.altField).css({ + cursor: 'pointer' + }).focus(function () { + $input.trigger("focus"); + }); + } + + if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) { + tp_inst._defaults.minDate = new Date(); + } + if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) { + tp_inst._defaults.maxDate = new Date(); + } + + // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. + if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) { + tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); + } + if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) { + tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); + } + if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) { + tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); + } + if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) { + tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); + } + tp_inst.$input.bind('focus', function () { + tp_inst._onFocus(); + }); + + return tp_inst; + }, + + /* + * add our sliders to the calendar + */ + _addTimePicker: function (dp_inst) { + var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val(); + + this.timeDefined = this._parseTime(currDT); + this._limitMinMaxDateTime(dp_inst, false); + this._injectTimePicker(); + }, + + /* + * parse the time string from input value or _setTime + */ + _parseTime: function (timeString, withDate) { + if (!this.inst) { + this.inst = $.datepicker._getInst(this.$input[0]); + } + + if (withDate || !this._defaults.timeOnly) { + var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); + try { + var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults); + if (!parseRes.timeObj) { + return false; + } + $.extend(this, parseRes.timeObj); + } catch (err) { + $.timepicker.log("Error parsing the date/time string: " + err + + "\ndate/time string = " + timeString + + "\ntimeFormat = " + this._defaults.timeFormat + + "\ndateFormat = " + dp_dateFormat); + return false; + } + return true; + } else { + var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults); + if (!timeObj) { + return false; + } + $.extend(this, timeObj); + return true; + } + }, + + /* + * generate and inject html for timepicker into ui datepicker + */ + _injectTimePicker: function () { + var $dp = this.inst.dpDiv, + o = this.inst.settings, + tp_inst = this, + litem = '', + uitem = '', + show = null, + max = {}, + gridSize = {}, + size = null, + i = 0, + l = 0; + + // Prevent displaying twice + if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) { + var noDisplay = ' style="display:none;"', + html = '
' + '
' + o.timeText + '
' + + '
'; + + // Create the markup + for (i = 0, l = this.units.length; i < l; i++) { + litem = this.units[i]; + uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1); + show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; + + // Added by Peter Medeiros: + // - Figure out what the hour/minute/second max should be based on the step values. + // - Example: if stepMinute is 15, then minMax is 45. + max[litem] = parseInt((o[litem + 'Max'] - ((o[litem + 'Max'] - o[litem + 'Min']) % o['step' + uitem])), 10); + gridSize[litem] = 0; + + html += '
' + o[litem + 'Text'] + '
' + + '
'; + + if (show && o[litem + 'Grid'] > 0) { + html += '
'; + + if (litem === 'hour') { + for (var h = o[litem + 'Min']; h <= max[litem]; h += parseInt(o[litem + 'Grid'], 10)) { + gridSize[litem]++; + var tmph = $.datepicker.formatTime(this.support.ampm ? 'hht' : 'HH', {hour: h}, o); + html += ''; + } + } + else { + for (var m = o[litem + 'Min']; m <= max[litem]; m += parseInt(o[litem + 'Grid'], 10)) { + gridSize[litem]++; + html += ''; + } + } + + html += '
' + tmph + '' + ((m < 10) ? '0' : '') + m + '
'; + } + html += '
'; + } + + // Timezone + var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone; + html += '
' + o.timezoneText + '
'; + html += '
'; + + // Create the elements from string + html += '
'; + var $tp = $(html); // if we only want time picker... - if (o.timeOnly === true) { - $tp.prepend( - '
' + - '
' + o.timeOnlyTitle + '
' + - '
'); - $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); - } - - this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({ - orientation: "horizontal", - value: this.hour, - min: o.hourMin, - max: hourMax, - step: o.stepHour, - slide: function(event, ui) { - tp_inst.hour_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); + if (o.timeOnly === true) { + $tp.prepend('
' + '
' + o.timeOnlyTitle + '
' + '
'); + $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); } - }); + + // add sliders, adjust grids, add events + for (i = 0, l = tp_inst.units.length; i < l; i++) { + litem = tp_inst.units[i]; + uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1); + show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; - - // Updated by Peter Medeiros: - // - Pass in Event and UI instance into slide function - this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({ - orientation: "horizontal", - value: this.minute, - min: o.minuteMin, - max: minMax, - step: o.stepMinute, - slide: function(event, ui) { - tp_inst.minute_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); + // add the slider + 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]); - this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({ - orientation: "horizontal", - value: this.second, - min: o.secondMin, - max: secMax, - step: o.stepSecond, - slide: function(event, ui) { - tp_inst.second_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); + // adjust the grid and add click event + if (show && o[litem + 'Grid'] > 0) { + size = 100 * gridSize[litem] * o[litem + 'Grid'] / (max[litem] - o[litem + 'Min']); + $tp.find('.ui_tpicker_' + litem + ' table').css({ + width: size + "%", + marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"), + marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0', + borderCollapse: 'collapse' + }).find("td").click(function (e) { + var $t = $(this), + h = $t.html(), + n = parseInt(h.replace(/[^0-9]/g), 10), + ap = h.replace(/[^apm]/ig), + f = $t.data('for'); // loses scope, so we use data-for - this.millisec_slider = $tp.find('#ui_tpicker_millisec_'+ dp_id).slider({ - orientation: "horizontal", - value: this.millisec, - min: o.millisecMin, - max: millisecMax, - step: o.stepMillisec, - slide: function(event, ui) { - tp_inst.millisec_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); + if (f === 'hour') { + if (ap.indexOf('p') !== -1 && n < 12) { + n += 12; + } + else { + if (ap.indexOf('a') !== -1 && n === 12) { + n = 0; + } + } + } + + tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n); - this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('').find("select"); - $.fn.append.apply(this.timezone_select, - $.map(o.timezoneList, function(val, idx) { - return $("