Compare commits

...

3 Commits
master ... dev

Author SHA1 Message Date
Trent Richardson 978cc0cb98 Merge pull request #318 from sarxos/dev
Remove unused variables, fix validation warnings
2012-02-15 05:06:39 -08:00
Bartosz Firyn e795b3e7a6 Remove unused variables, fix validation warnings 2012-02-15 12:57:10 +01:00
Trent Richardson 9b57a88e8c Update dev version 2012-02-11 17:44:20 -05:00
1 changed files with 54 additions and 60 deletions

View File

@ -1,14 +1,14 @@
/* /*
* jQuery timepicker addon * jQuery timepicker addon
* By: Trent Richardson [http://trentrichardson.com] * By: Trent Richardson [http://trentrichardson.com]
* Version 0.9.9 * Version 1.0.0-dev
* Last Modified: 02/05/2012 * Last Modified: 02/05/2012
* *
* Copyright 2012 Trent Richardson * Copyright 2012 Trent Richardson
* Dual licensed under the MIT and GPL licenses. * Dual licensed under the MIT and GPL licenses.
* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
* *
* HERES THE CSS: * HERES THE CSS:
* .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } * .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
* .ui-timepicker-div dl { text-align: left; } * .ui-timepicker-div dl { text-align: left; }
@ -20,7 +20,7 @@
(function($) { (function($) {
$.extend($.ui, { timepicker: { version: "0.9.9" } }); $.extend($.ui, { timepicker: { version: "1.0.0" } });
/* Time picker manager. /* Time picker manager.
Use the singleton instance of this class, $.timepicker, to interact with the time picker. Use the singleton instance of this class, $.timepicker, to interact with the time picker.
@ -133,7 +133,7 @@ $.extend(Timepicker.prototype, {
_newInst: function($input, o) { _newInst: function($input, o) {
var tp_inst = new Timepicker(), var tp_inst = new Timepicker(),
inlineSettings = {}; inlineSettings = {};
for (var attrName in this._defaults) { for (var attrName in this._defaults) {
var attrValue = $input.attr('time:' + attrName); var attrValue = $input.attr('time:' + attrName);
if (attrValue) { if (attrValue) {
@ -163,8 +163,8 @@ $.extend(Timepicker.prototype, {
}, },
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');
}); });
tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() }); 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() }); tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase(); });
if (tp_inst._defaults.timezoneList === null) { if (tp_inst._defaults.timezoneList === null) {
var timezoneList = []; var timezoneList = [];
@ -188,7 +188,7 @@ $.extend(Timepicker.prototype, {
tp_inst.$altInput = $(o.altField) tp_inst.$altInput = $(o.altField)
.css({ cursor: 'pointer' }) .css({ cursor: 'pointer' })
.focus(function(){ $input.trigger("focus"); }); .focus(function(){ $input.trigger("focus"); });
if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0) if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0)
{ {
tp_inst._defaults.minDate=new Date(); tp_inst._defaults.minDate=new Date();
@ -197,7 +197,7 @@ $.extend(Timepicker.prototype, {
{ {
tp_inst._defaults.maxDate=new Date(); tp_inst._defaults.maxDate=new Date();
} }
// datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
@ -215,7 +215,7 @@ $.extend(Timepicker.prototype, {
//######################################################################## //########################################################################
_addTimePicker: function(dp_inst) { _addTimePicker: function(dp_inst) {
var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ?
this.$input.val() + ' ' + this.$altInput.val() : this.$input.val() + ' ' + this.$altInput.val() :
this.$input.val(); this.$input.val();
this.timeDefined = this._parseTime(currDT); this.timeDefined = this._parseTime(currDT);
@ -249,7 +249,7 @@ $.extend(Timepicker.prototype, {
var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g");
regstr = '^.{' + dp_dateFormat.length + ',}?' + this._defaults.separator.replace(specials, "\\$&") + regstr; regstr = '^.{' + dp_dateFormat.length + ',}?' + this._defaults.separator.replace(specials, "\\$&") + regstr;
} }
treg = timeString.match(new RegExp(regstr, 'i')); treg = timeString.match(new RegExp(regstr, 'i'));
if (treg) { if (treg) {
@ -297,7 +297,7 @@ $.extend(Timepicker.prototype, {
} }
this.timezone = tz; this.timezone = tz;
} }
return true; return true;
} }
@ -314,7 +314,7 @@ $.extend(Timepicker.prototype, {
$.merge(markers, o.amNames); $.merge(markers, o.amNames);
if (o.pmNames) if (o.pmNames)
$.merge(markers, o.pmNames); $.merge(markers, o.pmNames);
markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&') }); markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); });
return '(' + markers.join('|') + ')?'; return '(' + markers.join('|') + ')?';
}, },
@ -364,7 +364,7 @@ $.extend(Timepicker.prototype, {
minuteGridSize = 0, minuteGridSize = 0,
secondGridSize = 0, secondGridSize = 0,
millisecGridSize = 0, millisecGridSize = 0,
size; size = null;
// Hours // Hours
html += '<dd class="ui_tpicker_hour"><div id="ui_tpicker_hour_' + dp_id + '"' + html += '<dd class="ui_tpicker_hour"><div id="ui_tpicker_hour_' + dp_id + '"' +
@ -472,7 +472,7 @@ $.extend(Timepicker.prototype, {
} }
}); });
// Updated by Peter Medeiros: // Updated by Peter Medeiros:
// - Pass in Event and UI instance into slide function // - Pass in Event and UI instance into slide function
this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({ this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({
@ -634,7 +634,7 @@ $.extend(Timepicker.prototype, {
this.minute_slider.bind('slidestop',onSelectDelegate); this.minute_slider.bind('slidestop',onSelectDelegate);
this.second_slider.bind('slidestop',onSelectDelegate); this.second_slider.bind('slidestop',onSelectDelegate);
this.millisec_slider.bind('slidestop',onSelectDelegate); this.millisec_slider.bind('slidestop',onSelectDelegate);
// slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/ // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
if (this._defaults.addSliderAccess){ if (this._defaults.addSliderAccess){
var sliderAccessArgs = this._defaults.sliderAccessArgs; var sliderAccessArgs = this._defaults.sliderAccessArgs;
@ -651,7 +651,7 @@ $.extend(Timepicker.prototype, {
oldMarginLeft = $g.css('marginLeft').toString().replace('%',''), oldMarginLeft = $g.css('marginLeft').toString().replace('%',''),
newWidth = oldWidth - sliderAccessWidth, newWidth = oldWidth - sliderAccessWidth,
newMarginLeft = ((oldMarginLeft * newWidth)/oldWidth) + '%'; newMarginLeft = ((oldMarginLeft * newWidth)/oldWidth) + '%';
$g.css({ width: newWidth, marginLeft: newMarginLeft }); $g.css({ width: newWidth, marginLeft: newMarginLeft });
}); });
} }
@ -659,7 +659,7 @@ $.extend(Timepicker.prototype, {
},0); },0);
} }
// end slideAccess integration // end slideAccess integration
} }
}, },
@ -770,7 +770,7 @@ $.extend(Timepicker.prototype, {
}, },
//######################################################################## //########################################################################
// when a slider moves, set the internal time... // when a slider moves, set the internal time...
// 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
@ -803,7 +803,7 @@ $.extend(Timepicker.prototype, {
|| (this.ampm.length > 0 || (this.ampm.length > 0
&& (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
|| timezone != this.timezone); || timezone != this.timezone);
if (hasChanged) { if (hasChanged) {
if (hour !== false)this.hour = hour; if (hour !== false)this.hour = hour;
@ -811,22 +811,22 @@ $.extend(Timepicker.prototype, {
if (second !== false) this.second = second; if (second !== false) this.second = second;
if (millisec !== false) this.millisec = millisec; if (millisec !== false) this.millisec = millisec;
if (timezone !== false) this.timezone = timezone; if (timezone !== false) this.timezone = timezone;
if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]); if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
this._limitMinMaxDateTime(this.inst, true); this._limitMinMaxDateTime(this.inst, true);
} }
if (o.ampm) this.ampm = ampm; if (o.ampm) this.ampm = ampm;
//this._formatTime(); //this._formatTime();
this.formattedTime = $.datepicker.formatTime(this._defaults.timeFormat, this, this._defaults); this.formattedTime = $.datepicker.formatTime(this._defaults.timeFormat, this, this._defaults);
if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix); if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix);
this.timeDefined = true; this.timeDefined = true;
if (hasChanged) this._updateDateTime(); if (hasChanged) this._updateDateTime();
}, },
//######################################################################## //########################################################################
// call custom onSelect. // call custom onSelect.
// bind to sliders slidestop, and grid click. // bind to sliders slidestop, and grid click.
//######################################################################## //########################################################################
_onSelectHandler: function() { _onSelectHandler: function() {
@ -845,7 +845,7 @@ $.extend(Timepicker.prototype, {
var tmptime = (format || this._defaults.timeFormat).toString(); var tmptime = (format || this._defaults.timeFormat).toString();
tmptime = $.datepicker.formatTime(tmptime, time, this._defaults); tmptime = $.datepicker.formatTime(tmptime, time, this._defaults);
if (arguments.length) return tmptime; if (arguments.length) return tmptime;
else this.formattedTime = tmptime; else this.formattedTime = tmptime;
}, },
@ -883,7 +883,7 @@ $.extend(Timepicker.prototype, {
} else { } else {
this.$input.val(formattedDateTime); this.$input.val(formattedDateTime);
} }
this.$input.trigger("change"); this.$input.trigger("change");
} }
@ -909,13 +909,12 @@ $.fn.extend({
//######################################################################## //########################################################################
datetimepicker: function(o) { datetimepicker: function(o) {
o = o || {}; o = o || {};
var $input = this,
tmp_args = arguments; tmp_args = arguments;
if (typeof(o) == 'string'){ if (typeof(o) == 'string'){
if(o == 'getDate') if(o == 'getDate')
return $.fn.datepicker.apply($(this[0]), tmp_args); return $.fn.datepicker.apply($(this[0]), tmp_args);
else else
return this.each(function() { return this.each(function() {
var $t = $(this); var $t = $(this);
$t.datepicker.apply($t, tmp_args); $t.datepicker.apply($t, tmp_args);
@ -930,7 +929,7 @@ $.fn.extend({
}); });
//######################################################################## //########################################################################
// format the time all pretty... // format the time all pretty...
// format = string format of the time // format = string format of the time
// time = a {}, not a Date() for timezones // time = a {}, not a Date() for timezones
// options = essentially the regional[].. amNames, pmNames, ampm // options = essentially the regional[].. amNames, pmNames, ampm
@ -939,7 +938,7 @@ $.datepicker.formatTime = function(format, time, options) {
options = options || {}; options = options || {};
options = $.extend($.timepicker._defaults, options); options = $.extend($.timepicker._defaults, options);
time = $.extend({hour:0, minute:0, second:0, millisec:0, timezone:'+0000'}, time); time = $.extend({hour:0, minute:0, second:0, millisec:0, timezone:'+0000'}, time);
var tmptime = format; var tmptime = format;
var ampmName = options['amNames'][0]; var ampmName = options['amNames'][0];
@ -975,7 +974,7 @@ $.datepicker.formatTime = function(format, time, options) {
tmptime = $.trim(tmptime); tmptime = $.trim(tmptime);
return tmptime; return tmptime;
} };
//######################################################################## //########################################################################
// the bad hack :/ override datepicker so it doesnt close on select // the bad hack :/ override datepicker so it doesnt close on select
@ -1015,9 +1014,9 @@ $.datepicker._updateDatepicker = function(inst) {
} }
if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) { if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
this._base_updateDatepicker(inst); this._base_updateDatepicker(inst);
// Reload the time control when changing something in the input text field. // Reload the time control when changing something in the input text field.
var tp_inst = this._get(inst, 'timepicker'); var tp_inst = this._get(inst, 'timepicker');
if(tp_inst) tp_inst._addTimePicker(inst); if(tp_inst) tp_inst._addTimePicker(inst);
@ -1055,7 +1054,7 @@ $.datepicker._doKeyPress = function(event) {
return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1); return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
} }
} }
return $.datepicker._base_doKeyPress(event); return $.datepicker._base_doKeyPress(event);
}; };
@ -1102,7 +1101,7 @@ $.datepicker._gotoToday = function(id) {
tp_inst.timezone_select.val(tzoffset); tp_inst.timezone_select.val(tzoffset);
} }
this._setTime(inst, now); this._setTime(inst, now);
$( '.ui-datepicker-today', $dp).click(); $( '.ui-datepicker-today', $dp).click();
}; };
//####################################################################################### //#######################################################################################
@ -1245,14 +1244,11 @@ $.datepicker.parseDate = function(format, value, settings) {
//####################################################################################### //#######################################################################################
// override formatDate to set date with time to the input // override formatDate to set date with time to the input
//####################################################################################### //#######################################################################################
$.datepicker._base_formatDate=$.datepicker._formatDate; $.datepicker._base_formatDate = $.datepicker._formatDate;
$.datepicker._formatDate = function(inst, day, month, year){ $.datepicker._formatDate = function(inst, day, month, year){
var tp_inst = this._get(inst, 'timepicker'); var tp_inst = this._get(inst, 'timepicker');
if(tp_inst) if(tp_inst) {
{ tp_inst._updateDateTime(inst);
if(day)
var b = this._base_formatDate(inst, day, month, year);
tp_inst._updateDateTime(inst);
return tp_inst.$input.val(); return tp_inst.$input.val();
} }
return this._base_formatDate(inst); return this._base_formatDate(inst);
@ -1266,16 +1262,16 @@ $.datepicker._optionDatepicker = function(target, name, value) {
var inst = this._getInst(target), var inst = this._getInst(target),
tp_inst = this._get(inst, 'timepicker'); tp_inst = this._get(inst, 'timepicker');
if (tp_inst) { if (tp_inst) {
var min,max,onselect; var min = null, max = null, onselect = null;
if (typeof name == 'string') { // if min/max was set with the string if (typeof name == 'string') { // if min/max was set with the string
if (name==='minDate' || name==='minDateTime' ) if (name === 'minDate' || name === 'minDateTime' )
min = value; min = value;
else if (name==='maxDate' || name==='maxDateTime') else if (name === 'maxDate' || name === 'maxDateTime')
max = value; max = value;
else if (name==='onSelect') else if (name === 'onSelect')
onselect=value; onselect = value;
} else if (typeof name == 'object') { //if min/max was set with the JSON } else if (typeof name == 'object') { //if min/max was set with the JSON
if(name.minDate) if (name.minDate)
min = name.minDate; min = name.minDate;
else if (name.minDateTime) else if (name.minDateTime)
min = name.minDateTime; min = name.minDateTime;
@ -1284,24 +1280,23 @@ $.datepicker._optionDatepicker = function(target, name, value) {
else if (name.maxDateTime) else if (name.maxDateTime)
max = name.maxDateTime; max = name.maxDateTime;
} }
if(min){ //if min was set if(min) { //if min was set
if(min==0) if (min == 0)
min=new Date(); min = new Date();
else else
min= new Date(min); min = new Date(min);
tp_inst._defaults.minDate = min; tp_inst._defaults.minDate = min;
tp_inst._defaults.minDateTime = min; tp_inst._defaults.minDateTime = min;
} else if (max){ //if max was set } else if (max) { //if max was set
if(max==0) if(max==0)
max=new Date(); max=new Date();
else else
max= new Date(max); max= new Date(max);
tp_inst._defaults.maxDate = max; tp_inst._defaults.maxDate = max;
tp_inst._defaults.maxDateTime = max; tp_inst._defaults.maxDateTime = max;
} } else if (onselect)
else if (onselect) tp_inst._defaults.onSelect = onselect;
tp_inst._defaults.onSelect=onselect;
} }
if (value === undefined) if (value === undefined)
return this._base_optionDatepicker(target, name); return this._base_optionDatepicker(target, name);
@ -1320,7 +1315,6 @@ function extendRemove(target, props) {
}; };
$.timepicker = new Timepicker(); // singleton instance $.timepicker = new Timepicker(); // singleton instance
$.timepicker.version = "0.9.9"; $.timepicker.version = "1.0.0";
})(jQuery); })(jQuery);