Skip to content
Open
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
26 changes: 23 additions & 3 deletions jquery.timePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@
if ($tpDiv.is(":visible")) {
return false;
}

var clickOutListener=function(e) {
var contains=false;
$(e.target).parents().each(function() { contains|=(this===$tpDiv.first().get()); return contains; });
contains|=(this===elm);
if (!contains) {
hidePicker($tpDiv);
}

};
$tpDiv.data("clickOutListener", clickOutListener);
$(document).delegate("*", "click", clickOutListener);

$("li", $tpDiv).removeClass(selectedClass);

// Position
Expand Down Expand Up @@ -120,7 +133,7 @@
// Hide timepicker on blur
$(elm).blur(function() {
if (!tpOver) {
$tpDiv.hide();
hidePicker($tpDiv);
}
});
// Keypress doesn't repeat on Safari for non-text keys.
Expand Down Expand Up @@ -182,7 +195,7 @@
return false;
break;
case 27: // Esc
$tpDiv.hide();
hidePicker($tpDiv);
return false;
break;
}
Expand Down Expand Up @@ -217,6 +230,13 @@

// Private functions.

function hidePicker($tpDiv) {
var listener=$tpDiv.data("clickOutListener");
$(document).undelegate("*", "click", listener);
$tpDiv.removeData("clickOutListener");
$tpDiv.hide();
}

function setTimeVal(elm, sel, $tpDiv, settings) {
// Update input field
elm.value = $(sel).text();
Expand All @@ -227,7 +247,7 @@
elm.focus();
}
// Hide picker
$tpDiv.hide();
hidePicker($tpDiv);
}

function formatTime(time, settings) {
Expand Down