diff --git a/jquery-ui-timepicker-addon.css b/jquery-ui-timepicker-addon.css new file mode 100644 index 0000000..19b889f --- /dev/null +++ b/jquery-ui-timepicker-addon.css @@ -0,0 +1,5 @@ +.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } +.ui-timepicker-div dl { text-align: left; } +.ui-timepicker-div dl dt { height: 25px; } +.ui-timepicker-div dl dd { margin: -25px 0 10px 65px; } +.ui-timepicker-div td { font-size: 90%; } diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js index 85c795c..c22a5ad 100644 --- a/jquery-ui-timepicker-addon.js +++ b/jquery-ui-timepicker-addon.js @@ -1,10 +1,10 @@ /* * jQuery timepicker addon * By: Trent Richardson [http://trentrichardson.com] -* Version 0.9.3 -* Last Modified: 02/05/2011 +* Version 0.9.4 +* Last Modified: 05/12/2011 * -* Copyright 2010 Trent Richardson +* Copyright 2011 Trent Richardson * Dual licensed under the MIT and GPL licenses. * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt @@ -19,7 +19,7 @@ (function($) { -$.extend($.ui, { timepicker: { version: "0.9.3" } }); +$.extend($.ui, { timepicker: { version: "0.9.4" } }); /* Time picker manager. Use the singleton instance of this class, $.timepicker, to interact with the time picker. @@ -37,7 +37,8 @@ function Timepicker() { timeText: 'Time', hourText: 'Hour', minuteText: 'Minute', - secondText: 'Second' + secondText: 'Second', + timezoneText: 'Time Zone' }; this._defaults = { // Global defaults for all the datetime picker instances showButtonPanel: true, @@ -45,6 +46,7 @@ function Timepicker() { showHour: true, showMinute: true, showSecond: false, + showTimezone: false, showTime: true, stepHour: 0.05, stepMinute: 0.05, @@ -52,6 +54,7 @@ function Timepicker() { hour: 0, minute: 0, second: 0, + timezone: '+0000', hourMin: 0, minuteMin: 0, secondMin: 0, @@ -59,14 +62,18 @@ function Timepicker() { minuteMax: 59, secondMax: 59, minDateTime: null, - maxDateTime: null, + maxDateTime: null, hourGrid: 0, minuteGrid: 0, secondGrid: 0, alwaysSetTime: true, separator: ' ', altFieldTimeOnly: true, - showTimepicker: true + showTimepicker: true, + timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600", + "-0500", "-0400", "-0300", "-0200", "-0100", "+0000", + "+0100", "+0200", "+0300", "+0400", "+0500", "+0600", + "+0700", "+0800", "+0900", "+1000", "+1100", "+1200"] }; $.extend(this._defaults, this.regional['']); } @@ -79,9 +86,11 @@ $.extend(Timepicker.prototype, { hour_slider: null, minute_slider: null, second_slider: null, + timezone_select: null, hour: 0, minute: 0, second: 0, + timezone: '+0000', hourMinOriginal: null, minuteMinOriginal: null, secondMinOriginal: null, @@ -92,6 +101,10 @@ $.extend(Timepicker.prototype, { formattedDate: '', formattedTime: '', formattedDateTime: '', + timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600", + "-0500", "-0400", "-0300", "-0200", "-0100", "+0000", + "+0100", "+0200", "+0300", "+0400", "+0500", "+0600", + "+0700", "+0800", "+0900", "+1000", "+1100", "+1200"], /* Override the default settings for all instances of the time picker. @param settings object - the new settings to use as defaults (anonymous object) @@ -107,14 +120,7 @@ $.extend(Timepicker.prototype, { _newInst: function($input, o) { var tp_inst = new Timepicker(), inlineSettings = {}; - - tp_inst.hour = tp_inst._defaults.hour; - tp_inst.minute = tp_inst._defaults.minute; - tp_inst.second = tp_inst._defaults.second; - tp_inst.ampm = ''; - tp_inst.$input = $input; - for (var attrName in this._defaults) { var attrValue = $input.attr('time:' + attrName); if (attrValue) { @@ -126,7 +132,7 @@ $.extend(Timepicker.prototype, { } } tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, { - beforeShow: function(input, dp_inst) { + beforeShow: function(input, dp_inst) { if ($.isFunction(o.beforeShow)) o.beforeShow(input, dp_inst, tp_inst); }, @@ -134,17 +140,23 @@ $.extend(Timepicker.prototype, { // 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(year, month, dp_inst, tp_inst); + 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(dateText, dp_inst, tp_inst); + 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.hour = tp_inst._defaults.hour; + tp_inst.minute = tp_inst._defaults.minute; + tp_inst.second = tp_inst._defaults.second; + tp_inst.ampm = ''; + tp_inst.$input = $input; + if (o.altField) tp_inst.$altInput = $(o.altField) .css({ cursor: 'pointer' }) @@ -185,6 +197,7 @@ $.extend(Timepicker.prototype, { .replace(/m{1,2}/ig, '(\\d?\\d)') .replace(/s{1,2}/ig, '(\\d?\\d)') .replace(/t{1,2}/ig, '(am|pm|a|p)?') + .replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?') .replace(/\s/g, '\\s?') + '$', order = this._getFormatPositions(), treg; @@ -195,9 +208,11 @@ $.extend(Timepicker.prototype, { // 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'); - regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator + regstr; + // 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) { @@ -216,6 +231,7 @@ $.extend(Timepicker.prototype, { if (order.m !== -1) this.minute = Number(treg[order.m]); if (order.s !== -1) this.second = Number(treg[order.s]); + if (order.z !== -1) this.timezone = treg[order.z]; return true; @@ -227,8 +243,8 @@ $.extend(Timepicker.prototype, { // 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}|t{1,2})/g), - orders = { h: -1, m: -1, s: -1, t: -1 }; + var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|t{1,2}|z)/g), + orders = { h: -1, m: -1, s: -1, t: -1, z: -1 }; if (finds) for (var i = 0; i < finds.length; i++) @@ -328,6 +344,11 @@ $.extend(Timepicker.prototype, { ''; } else html += '
'; + + html += '
' + o.timezoneText + '
'; + html += '
'; html += ''; $tp = $(html); @@ -379,6 +400,20 @@ $.extend(Timepicker.prototype, { tp_inst._onTimeChange(); } }); + + + 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 $("