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

added time changed event (onSelectTime) #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions jquery.simple-dtpicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ <h4>Set the user event-handler (on* methods)</h4>
<li>"onShow" - Called when a picker has shown.</li>
<li>"onHide" - Called when a picker has hidden.</li>
<li>"onSelect" - Called when a picker date is clicked on and selected.</li>
<li>"onSelectTime" - Called when a time is clicked on and selected.</li>
</ul>
<p>
In normally, a picker has been shown/hidden by automatically when necessary.<br/>
Expand Down
21 changes: 16 additions & 5 deletions jquery.simple-dtpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@

/* Check a specified date */
var todayDate = new Date();


if (isFutureOnly) {
if ($picker.data("current")) {
Expand Down Expand Up @@ -981,7 +981,7 @@
var $input = $(this);
var handler = new PickerHandler($picker, $input);

// Call a event-hanlder for onSelect
// Call a event-handler for onSelect
var func = $picker.data('onSelect');
if (func != null) {
func(handler, targetDate);
Expand Down Expand Up @@ -1036,7 +1036,7 @@
var hour_ = minTime[0];
var min_ = minTime[1];

while( hour_*100+min_ < maxTime[0]*100+maxTime[1] ){
while (hour_*100+min_ < maxTime[0]*100+maxTime[1]) {

var $o = $('<div>');
var is_past_time = hour_ < todayDate.getHours() || (hour_ == todayDate.getHours() && min_ < todayDate.getMinutes());
Expand Down Expand Up @@ -1073,22 +1073,31 @@
if ($(this).hasClass('hover')) {
$(this).removeClass('hover');
}

$(this).addClass('active');

var $picker = getParentPickerObject($(this));
var date = getPickedDate($picker);
var hour = $(this).data("hour");
var min = $(this).data("min");

draw($picker, {
"isAnim": false,
"isOutputToInputObject": true
}, date.getFullYear(), date.getMonth(), date.getDate(), hour, min);

if ($picker.data("isInline") === false && $picker.data("closeOnSelected")){
if ($picker.data("isInline") === false && $picker.data("closeOnSelected")) {
// Close a picker
ActivePickerId = -1;
$picker.hide();
}

var func = $picker.data('onSelectTime');
if (func != null) {
var selectedDateWithTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), hour, min, 0, 0);
var stringTime = hour + ":" + min;
func(selectedDateWithTime, stringTime);
}
});

$o.hover(function() {
Expand Down Expand Up @@ -1190,6 +1199,7 @@
$picker.data('onShow', opt.onShow);
$picker.data('onHide', opt.onHide);
$picker.data('onSelect', opt.onSelect);
$picker.data('onSelectTime', opt.onSelectTime);
$picker.data('onInit', opt.onInit);
$picker.data('allowWdays', opt.allowWdays);
$picker.data('current', opt.current);
Expand Down Expand Up @@ -1336,6 +1346,7 @@
"onShow": null,
"onHide": null,
"onSelect": null,
"onSelectTime": null,
"allowWdays": null,
"amPmInTimeList": false,
"externalLocale": null
Expand Down Expand Up @@ -1614,7 +1625,7 @@
var $picker = $(PickerObjects[i]);
if ($picker.data('inputObjectId') != null && !$picker.data('isInline') && $picker.css('display') != 'none') {
/* if append input-field && float picker */

// Check overlapping of cursor and picker
if ($picker.is(':hover')) continue;

Expand Down