Whitespace and formatting corrections
Reuse jQuery obj for buttonPanel var statement consolidation Shortened default option code for $.fn.timepicker()
This commit is contained in:
parent
ba3d8a86bd
commit
e402be7982
77
jquery-ui-timepicker-addon.js
vendored
77
jquery-ui-timepicker-addon.js
vendored
|
@ -108,14 +108,17 @@ $.extend(Timepicker.prototype, {
|
||||||
order = this._getFormatPositions();
|
order = this._getFormatPositions();
|
||||||
|
|
||||||
if (!this._defaults.timeOnly) {
|
if (!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
|
// 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');
|
var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
|
||||||
regstr = '.{' + dp_dateFormat.length + ',}\\s+' + regstr;
|
regstr = '.{' + dp_dateFormat.length + ',}\\s+' + regstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (treg) {
|
if (treg) {
|
||||||
if (order.t !== -1)
|
if (order.t !== -1)
|
||||||
this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ? '' : (treg[order.t].charAt(0).toUpperCase() == 'A') ? 'AM' : 'PM').toUpperCase();
|
this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ?
|
||||||
|
'' :
|
||||||
|
(treg[order.t].charAt(0).toUpperCase() == 'A') ? 'AM' : 'PM').toUpperCase();
|
||||||
|
|
||||||
if (order.h !== -1) {
|
if (order.h !== -1) {
|
||||||
if (this.ampm == 'AM' && treg[order.h] == '12')
|
if (this.ampm == 'AM' && treg[order.h] == '12')
|
||||||
|
@ -166,11 +169,13 @@ $.extend(Timepicker.prototype, {
|
||||||
// Prevent displaying twice
|
// 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) {
|
||||||
var noDisplay = ' style="display:none;"',
|
var noDisplay = ' style="display:none;"',
|
||||||
html =
|
html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
|
||||||
'<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
|
'<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
|
||||||
'<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
|
((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
|
||||||
'<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' + ((o.showTime) ? '' : noDisplay) + '></dd>' +
|
'<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' +
|
||||||
'<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>',
|
((o.showTime) ? '' : noDisplay) + '></dd>' +
|
||||||
|
'<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' +
|
||||||
|
((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>',
|
||||||
hourGridSize = 0,
|
hourGridSize = 0,
|
||||||
minuteGridSize = 0,
|
minuteGridSize = 0,
|
||||||
secondGridSize = 0,
|
secondGridSize = 0,
|
||||||
|
@ -195,13 +200,16 @@ $.extend(Timepicker.prototype, {
|
||||||
|
|
||||||
html += '</tr></table></div>' +
|
html += '</tr></table></div>' +
|
||||||
'</dd>';
|
'</dd>';
|
||||||
} else html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '></dd>';
|
} else html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_id + '"' +
|
||||||
|
((o.showHour) ? '' : noDisplay) + '></dd>';
|
||||||
|
|
||||||
html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' + ((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>';
|
html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' +
|
||||||
|
((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>';
|
||||||
|
|
||||||
if (o.showMinute && o.minuteGrid > 0) {
|
if (o.showMinute && o.minuteGrid > 0) {
|
||||||
html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' +
|
html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' +
|
||||||
'<div id="ui_tpicker_minute_' + dp_id + '"' + ((o.showMinute) ? '' : noDisplay) + '></div>' +
|
'<div id="ui_tpicker_minute_' + dp_id + '"' +
|
||||||
|
((o.showMinute) ? '' : noDisplay) + '></div>' +
|
||||||
'<div style="padding-left: 1px"><table><tr>';
|
'<div style="padding-left: 1px"><table><tr>';
|
||||||
|
|
||||||
for (var m = 0; m < minMax; m += o.minuteGrid) {
|
for (var m = 0; m < minMax; m += o.minuteGrid) {
|
||||||
|
@ -211,13 +219,16 @@ $.extend(Timepicker.prototype, {
|
||||||
|
|
||||||
html += '</tr></table></div>' +
|
html += '</tr></table></div>' +
|
||||||
'</dd>';
|
'</dd>';
|
||||||
} else html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_id + '"' + ((o.showMinute) ? '' : noDisplay) + '></dd>';
|
} else html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_id + '"' +
|
||||||
|
((o.showMinute) ? '' : noDisplay) + '></dd>';
|
||||||
|
|
||||||
html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' + ((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>';
|
html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' +
|
||||||
|
((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>';
|
||||||
|
|
||||||
if (o.showSecond && o.secondGrid > 0) {
|
if (o.showSecond && o.secondGrid > 0) {
|
||||||
html += '<dd class="ui_tpicker_second ui_tpicker_second_' + o.secondGrid + '">' +
|
html += '<dd class="ui_tpicker_second ui_tpicker_second_' + o.secondGrid + '">' +
|
||||||
'<div id="ui_tpicker_second_' + dp_id + '"' + ((o.showSecond) ? '' : noDisplay) + '></div>' +
|
'<div id="ui_tpicker_second_' + dp_id + '"' +
|
||||||
|
((o.showSecond) ? '' : noDisplay) + '></div>' +
|
||||||
'<div style="padding-left: 1px"><table><tr>';
|
'<div style="padding-left: 1px"><table><tr>';
|
||||||
|
|
||||||
for (var s = 0; s < secMax; s += o.secondGrid) {
|
for (var s = 0; s < secMax; s += o.secondGrid) {
|
||||||
|
@ -227,7 +238,8 @@ $.extend(Timepicker.prototype, {
|
||||||
|
|
||||||
html += '</tr></table></div>' +
|
html += '</tr></table></div>' +
|
||||||
'</dd>';
|
'</dd>';
|
||||||
} else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' + ((o.showSecond) ? '' : noDisplay) + '></dd>';
|
} else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' +
|
||||||
|
((o.showSecond) ? '' : noDisplay) + '></dd>';
|
||||||
|
|
||||||
html += '</dl></div>';
|
html += '</dl></div>';
|
||||||
$tp = $(html);
|
$tp = $(html);
|
||||||
|
@ -348,8 +360,8 @@ $.extend(Timepicker.prototype, {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var buttonPanel = $dp.find('.ui-datepicker-buttonpane');
|
var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
|
||||||
if (buttonPanel.length > 0) $dp.find('.ui-datepicker-buttonpane').before($tp);
|
if (buttonPanel.length) $buttonPanel.before($tp);
|
||||||
else $dp.append($tp);
|
else $dp.append($tp);
|
||||||
|
|
||||||
this.$timeObj = $('#ui_tpicker_time_'+ dp_id);
|
this.$timeObj = $('#ui_tpicker_time_'+ dp_id);
|
||||||
|
@ -363,7 +375,7 @@ $.extend(Timepicker.prototype, {
|
||||||
},
|
},
|
||||||
|
|
||||||
//########################################################################
|
//########################################################################
|
||||||
// when a slider moves..
|
// when a slider moves...
|
||||||
// on time change is also called when the time is updated in the text field
|
// on time change is also called when the time is updated in the text field
|
||||||
//########################################################################
|
//########################################################################
|
||||||
_onTimeChange: function(force) {
|
_onTimeChange: function(force) {
|
||||||
|
@ -397,8 +409,8 @@ $.extend(Timepicker.prototype, {
|
||||||
// format the time all pretty...
|
// format the time all pretty...
|
||||||
//########################################################################
|
//########################################################################
|
||||||
_formatTime: function() {
|
_formatTime: function() {
|
||||||
var tmptime = this._defaults.timeFormat.toString();
|
var tmptime = this._defaults.timeFormat.toString(),
|
||||||
var hour12 = ((this.ampm == 'AM') ? (this.hour) : (this.hour % 12));
|
hour12 = ((this.ampm == 'AM') ? (this.hour) : (this.hour % 12));
|
||||||
hour12 = (Number(hour12) === 0) ? 12 : hour12;
|
hour12 = (Number(hour12) === 0) ? 12 : hour12;
|
||||||
|
|
||||||
if (this._defaults.ampm === true) {
|
if (this._defaults.ampm === true) {
|
||||||
|
@ -460,10 +472,10 @@ $.fn.extend({
|
||||||
// shorthand just to use timepicker..
|
// shorthand just to use timepicker..
|
||||||
//########################################################################
|
//########################################################################
|
||||||
timepicker: function(o) {
|
timepicker: function(o) {
|
||||||
|
o = o || {};
|
||||||
var tmp_args = arguments;
|
var tmp_args = arguments;
|
||||||
|
|
||||||
if(o === undefined) o = { timeOnly: true };
|
if (typeof o == 'object') o = $.extend(o, { timeOnly: true });
|
||||||
else if (typeof o == 'object') o = $.extend(o, { timeOnly: true });
|
|
||||||
|
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
$(this).datetimepicker(o, tmp_args[1], tmp_args[2], tmp_args[3], tmp_args[4]);
|
$(this).datetimepicker(o, tmp_args[1], tmp_args[2], tmp_args[3], tmp_args[4]);
|
||||||
|
@ -512,33 +524,28 @@ $.fn.extend({
|
||||||
tp_inst.second = tp_inst._defaults.second;
|
tp_inst.second = tp_inst._defaults.second;
|
||||||
tp_inst.ampm = '';
|
tp_inst.ampm = '';
|
||||||
tp_inst.$input = $(input);
|
tp_inst.$input = $(input);
|
||||||
if (o.altField) {
|
if (o.altField)
|
||||||
tp_inst.$altInput = $($.datepicker._get(dp_inst, 'altField'))
|
tp_inst.$altInput = $($.datepicker._get(dp_inst, 'altField'))
|
||||||
.css({ cursor: 'pointer' })
|
.css({ cursor: 'pointer' })
|
||||||
.focus(function(){
|
.focus(function(){
|
||||||
$input.trigger("focus");
|
$input.trigger("focus");
|
||||||
});
|
});
|
||||||
}
|
|
||||||
tp_inst.inst = dp_inst;
|
tp_inst.inst = dp_inst;
|
||||||
tp_inst._addTimePicker();
|
tp_inst._addTimePicker();
|
||||||
if ($.isFunction(o.beforeShow)) {
|
if ($.isFunction(o.beforeShow))
|
||||||
o.beforeShow(input, dp_inst);
|
o.beforeShow(input, dp_inst);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onChangeMonthYear: function(year, month, dp_inst) {
|
onChangeMonthYear: function(year, month, dp_inst) {
|
||||||
// Update the time as well : this prevents the time from disappearing from the $input field.
|
// Update the time as well : this prevents the time from disappearing from the $input field.
|
||||||
tp_inst._updateDateTime(dp_inst);
|
tp_inst._updateDateTime(dp_inst);
|
||||||
if ($.isFunction(o.onChangeMonthYear)) {
|
if ($.isFunction(o.onChangeMonthYear))
|
||||||
o.onChangeMonthYear(year, month, dp_inst);
|
o.onChangeMonthYear(year, month, dp_inst);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onClose: function(dateText, dp_inst) {
|
onClose: function(dateText, dp_inst) {
|
||||||
if(tp_inst.timeDefined === true && $input.val() != '') {
|
if (tp_inst.timeDefined === true && $input.val() != '')
|
||||||
tp_inst._updateDateTime(dp_inst);
|
tp_inst._updateDateTime(dp_inst);
|
||||||
}
|
if ($.isFunction(o.onClose))
|
||||||
if ($.isFunction(o.onClose)) {
|
|
||||||
o.onClose(dateText, dp_inst);
|
o.onClose(dateText, dp_inst);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
|
timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
|
||||||
});
|
});
|
||||||
|
@ -601,9 +608,9 @@ $.datepicker._doKeyPress = function(event) {
|
||||||
|
|
||||||
if (tp_inst) {
|
if (tp_inst) {
|
||||||
if ($.datepicker._get(inst, 'constrainInput')) {
|
if ($.datepicker._get(inst, 'constrainInput')) {
|
||||||
var dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
|
var dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
|
||||||
var chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
|
chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode),
|
||||||
var chrl = chr.toLowerCase();
|
chrl = chr.toLowerCase();
|
||||||
// keyCode == 58 => ":"
|
// keyCode == 58 => ":"
|
||||||
// keyCode == 32 => " "
|
// keyCode == 32 => " "
|
||||||
return event.ctrlKey || (chr < ' ' || !dateChars || dateChars.indexOf(chr) > -1 || event.keyCode == 58 || event.keyCode == 32 || chr == ':' || chr == ' ' || chrl == 'a' || chrl == 'p' || chrl == 'm');
|
return event.ctrlKey || (chr < ' ' || !dateChars || dateChars.indexOf(chr) > -1 || event.keyCode == 58 || event.keyCode == 32 || chr == ':' || chr == ' ' || chrl == 'a' || chrl == 'p' || chrl == 'm');
|
||||||
|
@ -696,7 +703,7 @@ $.datepicker._base_getDate = $.datepicker._getDate;
|
||||||
$.datepicker._getDate = function(inst) {
|
$.datepicker._getDate = function(inst) {
|
||||||
var tp_inst = $.datepicker._get(inst, 'timepicker');
|
var tp_inst = $.datepicker._get(inst, 'timepicker');
|
||||||
if (tp_inst)
|
if (tp_inst)
|
||||||
return startDate = (!inst.currentYear || (inst.input && inst.input.val() == '')) ?
|
return (!inst.currentYear || (inst.input && inst.input.val() == '')) ?
|
||||||
null :
|
null :
|
||||||
this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay, tp_inst.hour, tp_inst.minute, tp_inst.second));
|
this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay, tp_inst.hour, tp_inst.minute, tp_inst.second));
|
||||||
else return $.datepicker._base_getDate(inst);
|
else return $.datepicker._base_getDate(inst);
|
||||||
|
|
Loading…
Reference in a new issue