Skip to content
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

🐛 fix(timepicker): timepicker breaks when using with third party plugins. #78

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
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
54 changes: 28 additions & 26 deletions library/js/timepicker.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Copyright (c) 2016 Willington Vega; Licensed MIT, GPL
*/

// @edited replaced default timepicker name with HUI_timepicker.

(function (factory) {
if ( typeof module === 'object' && typeof module.exports === 'object' ) {
factory(require('jquery'), window, document);
Expand All @@ -24,7 +26,7 @@
if (arguments.length === 1) {
var date = arguments[0];
if (typeof date === 'string') {
date = $.fn.timepicker.parseTime(date);
date = $.fn.HUI_timepicker.parseTime(date);
}
return new Date(0, 0, 0, date.getHours(), date.getMinutes(), date.getSeconds());
} else if (arguments.length === 3) {
Expand All @@ -36,7 +38,7 @@
}
}

$.TimePicker = function() {
$.HUI_TimePicker = function() {
var widget = this;

widget.container = $('.hustle-timepicker');
Expand Down Expand Up @@ -69,15 +71,15 @@
}
};

$.TimePicker.count = 0;
$.TimePicker.instance = function() {
if (!$.TimePicker._instance) {
$.TimePicker._instance = new $.TimePicker();
$.HUI_TimePicker.count = 0;
$.HUI_TimePicker.instance = function() {
if (!$.HUI_TimePicker._instance) {
$.HUI_TimePicker._instance = new $.HUI_TimePicker();
}
return $.TimePicker._instance;
return $.HUI_TimePicker._instance;
};

$.TimePicker.prototype = {
$.HUI_TimePicker.prototype = {
// extracted from from jQuery UI Core
// http://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.core.js
keyCode: {
Expand Down Expand Up @@ -120,7 +122,7 @@
while(time < end) {
if (widget._isValidTime(i, time)) {
item = $('<li>').addClass('ui-menu-item').appendTo(ul);
$('<a>').text($.fn.timepicker.formatTime(i.options.timeFormat, time)).appendTo(item);
$('<a>').text($.fn.HUI_timepicker.formatTime(i.options.timeFormat, time)).appendTo(item);
item.data('time-value', time);
}
time = new Date(time.getTime() + i.options.interval * 60 * 1000);
Expand Down Expand Up @@ -234,7 +236,7 @@
} else if (i.options.defaultTime && i.options.defaultTime.getFullYear) {
i.setTime(normalize(i.options.defaultTime));
} else if (i.options.defaultTime) {
i.setTime($.fn.timepicker.parseTime(i.options.defaultTime));
i.setTime($.fn.HUI_timepicker.parseTime(i.options.defaultTime));
}
},

Expand Down Expand Up @@ -274,14 +276,14 @@
});
}).bind('change.timepicker', function() {
if (i.closed()) {
i.setTime($.fn.timepicker.parseTime(i.element.val()));
i.setTime($.fn.HUI_timepicker.parseTime(i.element.val()));
}
});
},

select: function(i, item) {
var widget = this, instance = i === false ? widget.instance : i;
widget.setTime(instance, $.fn.timepicker.parseTime(item.children('a').text()));
widget.setTime(instance, $.fn.HUI_timepicker.parseTime(item.children('a').text()));
widget.close(instance, true);
},

Expand Down Expand Up @@ -507,7 +509,7 @@
var item = $(this), time;

if ($.fn.jquery < '1.4.2') {
time = $.fn.timepicker.parseTime(item.find('a').text());
time = $.fn.HUI_timepicker.parseTime(item.find('a').text());
} else {
time = item.data('time-value');
}
Expand Down Expand Up @@ -553,17 +555,17 @@
//

parse: function(i, str) {
return $.fn.timepicker.parseTime(str);
return $.fn.HUI_timepicker.parseTime(str);
},

format: function(i, time, format) {
format = format || i.options.timeFormat;
return $.fn.timepicker.formatTime(format, time);
return $.fn.HUI_timepicker.formatTime(format, time);
},

getTime: function(i) {
var widget = this,
current = $.fn.timepicker.parseTime(i.element.val());
current = $.fn.HUI_timepicker.parseTime(i.element.val());

// if current value is not valid, we return null.
// stored Date object is ignored, because the current value
Expand Down Expand Up @@ -650,7 +652,7 @@
}
};

$.TimePicker.defaults = {
$.HUI_TimePicker.defaults = {
timeFormat: 'hh:mm p',
minHour: null,
minMinutes: null,
Expand All @@ -671,7 +673,7 @@
change: function(/*time*/) {}
};

$.TimePicker.methods = {
$.HUI_TimePicker.methods = {
chainable: [
'next',
'previous',
Expand All @@ -682,7 +684,7 @@
]
};

$.fn.timepicker = function(options) {
$.fn.HUI_timepicker = function(options) {
// support calling API methods using the following syntax:
// $(...).timepicker('parse', '11p');
if (typeof options === 'string') {
Expand All @@ -692,7 +694,7 @@
// chainable API methods
if (options === 'option' && arguments.length > 2) {
method = 'each';
} else if ($.inArray(options, $.TimePicker.methods.chainable) !== -1) {
} else if ($.inArray(options, $.HUI_TimePicker.methods.chainable) !== -1) {
method = 'each';
// API methods that return a value
} else {
Expand Down Expand Up @@ -721,17 +723,17 @@
return this.data('TimePicker');
}

var globals = $.extend({}, $.TimePicker.defaults, options);
var globals = $.extend({}, $.HUI_TimePicker.defaults, options);

return this.each(function() {
$.TimePicker.instance().register(this, globals);
$.HUI_TimePicker.instance().register(this, globals);
});
};

/**
* TODO: documentation
*/
$.fn.timepicker.formatTime = function(format, time) {
$.fn.HUI_timepicker.formatTime = function(format, time) {
var hours = time.getHours(),
hours12 = hours % 12,
minutes = time.getMinutes(),
Expand Down Expand Up @@ -794,7 +796,7 @@
* For a detailed list of supported formats check the unit tests at
* http://github.com/wvega/timepicker/tree/master/tests/
*/
$.fn.timepicker.parseTime = (function() {
$.fn.HUI_timepicker.parseTime = (function() {
var patterns = [
// 1, 12, 123, 1234, 12345, 123456
[/^(\d+)$/, '$1'],
Expand Down Expand Up @@ -875,9 +877,9 @@

if (h > 24) {
if (str.length >= 6) {
return $.fn.timepicker.parseTime(str.substr(0,5));
return $.fn.HUI_timepicker.parseTime(str.substr(0,5));
} else {
return $.fn.timepicker.parseTime(str + '0' + (am ? 'a' : '') + (pm ? 'p' : ''));
return $.fn.HUI_timepicker.parseTime(str + '0' + (am ? 'a' : '') + (pm ? 'p' : ''));
}
} else {
time.setHours(h, m, s);
Expand Down
2 changes: 1 addition & 1 deletion library/js/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const moduleId = container.data( 'id' );
const element = container.find( select );

element.timepicker({
element.HUI_timepicker({
timeFormat: ( '' !== element.data( 'time-format' ) ) ? element.data( 'time-format' ) : 'h:mm p',
interval: ( '' !== element.data( 'time-interval' ) ) ? element.data( 'time-interval' ) : 60,
minTime: '0',
Expand Down