Skip to content

Dev #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 28, 2012
Merged

Dev #325

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 61 additions & 61 deletions jquery-ui-timepicker-addon.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* jQuery timepicker addon
* By: Trent Richardson [http://trentrichardson.com]
* Version 0.9.9
* Version 1.0.0-dev
* 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; }
Expand All @@ -20,7 +20,13 @@

(function($) {

$.extend($.ui, { timepicker: { version: "0.9.9" } });
// Prevent "Uncaught RangeError: Maximum call stack size exceeded"
$.ui.timepicker = $.ui.timepicker || {};
if ($.ui.timepicker.version) {
return;
}

$.extend($.ui, { timepicker: { version: "1.0.0" } });

/* Time picker manager.
Use the singleton instance of this class, $.timepicker, to interact with the time picker.
Expand Down Expand Up @@ -133,7 +139,7 @@ $.extend(Timepicker.prototype, {
_newInst: function($input, o) {
var tp_inst = new Timepicker(),
inlineSettings = {};

for (var attrName in this._defaults) {
var attrValue = $input.attr('time:' + attrName);
if (attrValue) {
Expand Down Expand Up @@ -163,8 +169,8 @@ $.extend(Timepicker.prototype, {
},
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() });
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 = [];
Expand All @@ -188,7 +194,7 @@ $.extend(Timepicker.prototype, {
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();
Expand All @@ -197,7 +203,7 @@ $.extend(Timepicker.prototype, {
{
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());
Expand All @@ -215,7 +221,7 @@ $.extend(Timepicker.prototype, {
//########################################################################
_addTimePicker: function(dp_inst) {
var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ?
this.$input.val() + ' ' + this.$altInput.val() :
this.$input.val() + ' ' + this.$altInput.val() :
this.$input.val();

this.timeDefined = this._parseTime(currDT);
Expand Down Expand Up @@ -249,7 +255,7 @@ $.extend(Timepicker.prototype, {
var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g");
regstr = '^.{' + dp_dateFormat.length + ',}?' + this._defaults.separator.replace(specials, "\\$&") + regstr;
}

treg = timeString.match(new RegExp(regstr, 'i'));

if (treg) {
Expand Down Expand Up @@ -297,7 +303,7 @@ $.extend(Timepicker.prototype, {
}
this.timezone = tz;
}

return true;

}
Expand All @@ -308,13 +314,13 @@ $.extend(Timepicker.prototype, {
// pattern for standard and localized AM/PM markers
//########################################################################
_getPatternAmpm: function() {
var markers = [];
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, '\\$&') });
markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); });
return '(' + markers.join('|') + ')?';
},

Expand Down Expand Up @@ -364,7 +370,7 @@ $.extend(Timepicker.prototype, {
minuteGridSize = 0,
secondGridSize = 0,
millisecGridSize = 0,
size;
size = null;

// Hours
html += '<dd class="ui_tpicker_hour"><div id="ui_tpicker_hour_' + dp_id + '"' +
Expand Down Expand Up @@ -472,7 +478,7 @@ $.extend(Timepicker.prototype, {
}
});


// Updated by Peter Medeiros:
// - Pass in Event and UI instance into slide function
this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({
Expand Down Expand Up @@ -634,7 +640,7 @@ $.extend(Timepicker.prototype, {
this.minute_slider.bind('slidestop',onSelectDelegate);
this.second_slider.bind('slidestop',onSelectDelegate);
this.millisec_slider.bind('slidestop',onSelectDelegate);

// slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
if (this._defaults.addSliderAccess){
var sliderAccessArgs = this._defaults.sliderAccessArgs;
Expand All @@ -651,15 +657,15 @@ $.extend(Timepicker.prototype, {
oldMarginLeft = $g.css('marginLeft').toString().replace('%',''),
newWidth = oldWidth - sliderAccessWidth,
newMarginLeft = ((oldMarginLeft * newWidth)/oldWidth) + '%';

$g.css({ width: newWidth, marginLeft: newMarginLeft });
});
}
}
},0);
}
// end slideAccess integration

}
},

Expand Down Expand Up @@ -770,7 +776,7 @@ $.extend(Timepicker.prototype, {

},


//########################################################################
// when a slider moves, set the internal time...
// on time change is also called when the time is updated in the text field
Expand Down Expand Up @@ -803,30 +809,30 @@ $.extend(Timepicker.prototype, {
|| (this.ampm.length > 0
&& (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
|| timezone != this.timezone);

if (hasChanged) {

if (hour !== false)this.hour = hour;
if (minute !== false) this.minute = minute;
if (second !== false) this.second = second;
if (millisec !== false) this.millisec = millisec;
if (timezone !== false) this.timezone = timezone;

if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);

this._limitMinMaxDateTime(this.inst, true);
}
if (o.ampm) this.ampm = ampm;

//this._formatTime();
this.formattedTime = $.datepicker.formatTime(this._defaults.timeFormat, this, this._defaults);
if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix);
this.timeDefined = true;
if (hasChanged) this._updateDateTime();
},

//########################################################################
// call custom onSelect.
// call custom onSelect.
// bind to sliders slidestop, and grid click.
//########################################################################
_onSelectHandler: function() {
Expand All @@ -845,7 +851,7 @@ $.extend(Timepicker.prototype, {
var tmptime = (format || this._defaults.timeFormat).toString();

tmptime = $.datepicker.formatTime(tmptime, time, this._defaults);

if (arguments.length) return tmptime;
else this.formattedTime = tmptime;
},
Expand Down Expand Up @@ -883,7 +889,7 @@ $.extend(Timepicker.prototype, {
} else {
this.$input.val(formattedDateTime);
}

this.$input.trigger("change");
}

Expand All @@ -909,13 +915,12 @@ $.fn.extend({
//########################################################################
datetimepicker: function(o) {
o = o || {};
var $input = this,
tmp_args = arguments;

if (typeof(o) == 'string'){
if(o == 'getDate')
if(o == 'getDate')
return $.fn.datepicker.apply($(this[0]), tmp_args);
else
else
return this.each(function() {
var $t = $(this);
$t.datepicker.apply($t, tmp_args);
Expand All @@ -930,7 +935,7 @@ $.fn.extend({
});

//########################################################################
// format the time all pretty...
// format the time all pretty...
// format = string format of the time
// time = a {}, not a Date() for timezones
// options = essentially the regional[].. amNames, pmNames, ampm
Expand All @@ -939,7 +944,7 @@ $.datepicker.formatTime = function(format, time, options) {
options = options || {};
options = $.extend($.timepicker._defaults, options);
time = $.extend({hour:0, minute:0, second:0, millisec:0, timezone:'+0000'}, time);

var tmptime = format;
var ampmName = options['amNames'][0];

Expand Down Expand Up @@ -975,7 +980,7 @@ $.datepicker.formatTime = function(format, time, options) {

tmptime = $.trim(tmptime);
return tmptime;
}
};

//########################################################################
// the bad hack :/ override datepicker so it doesnt close on select
Expand Down Expand Up @@ -1015,9 +1020,9 @@ $.datepicker._updateDatepicker = function(inst) {
}

if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {

this._base_updateDatepicker(inst);

// Reload the time control when changing something in the input text field.
var tp_inst = this._get(inst, 'timepicker');
if(tp_inst) tp_inst._addTimePicker(inst);
Expand Down Expand Up @@ -1055,7 +1060,7 @@ $.datepicker._doKeyPress = function(event) {
return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
}
}

return $.datepicker._base_doKeyPress(event);
};

Expand Down Expand Up @@ -1102,7 +1107,7 @@ $.datepicker._gotoToday = function(id) {
tp_inst.timezone_select.val(tzoffset);
}
this._setTime(inst, now);
$( '.ui-datepicker-today', $dp).click();
$( '.ui-datepicker-today', $dp).click();
};

//#######################################################################################
Expand Down Expand Up @@ -1245,14 +1250,11 @@ $.datepicker.parseDate = function(format, value, settings) {
//#######################################################################################
// 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){
var tp_inst = this._get(inst, 'timepicker');
if(tp_inst)
{
if(day)
var b = this._base_formatDate(inst, day, month, year);
tp_inst._updateDateTime(inst);
if(tp_inst) {
tp_inst._updateDateTime(inst);
return tp_inst.$input.val();
}
return this._base_formatDate(inst);
Expand All @@ -1266,16 +1268,16 @@ $.datepicker._optionDatepicker = function(target, name, value) {
var inst = this._getInst(target),
tp_inst = this._get(inst, 'timepicker');
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 (name==='minDate' || name==='minDateTime' )
if (name === 'minDate' || name === 'minDateTime' )
min = value;
else if (name==='maxDate' || name==='maxDateTime')
else if (name === 'maxDate' || name === 'maxDateTime')
max = value;
else if (name==='onSelect')
onselect=value;
else if (name === 'onSelect')
onselect = value;
} else if (typeof name == 'object') { //if min/max was set with the JSON
if(name.minDate)
if (name.minDate)
min = name.minDate;
else if (name.minDateTime)
min = name.minDateTime;
Expand All @@ -1284,24 +1286,23 @@ $.datepicker._optionDatepicker = function(target, name, value) {
else if (name.maxDateTime)
max = name.maxDateTime;
}
if(min){ //if min was set
if(min==0)
min=new Date();
if(min) { //if min was set
if (min == 0)
min = new Date();
else
min= new Date(min);
min = new Date(min);

tp_inst._defaults.minDate = min;
tp_inst._defaults.minDateTime = min;
} else if (max){ //if max was set
} else if (max) { //if max was set
if(max==0)
max=new Date();
else
max= new Date(max);
tp_inst._defaults.maxDate = max;
tp_inst._defaults.maxDateTime = max;
}
else if (onselect)
tp_inst._defaults.onSelect=onselect;
} else if (onselect)
tp_inst._defaults.onSelect = onselect;
}
if (value === undefined)
return this._base_optionDatepicker(target, name);
Expand All @@ -1320,7 +1321,6 @@ function extendRemove(target, props) {
};

$.timepicker = new Timepicker(); // singleton instance
$.timepicker.version = "0.9.9";
$.timepicker.version = "1.0.0";

})(jQuery);