Skip to content

Commit 10ce787

Browse files
committed
Bugfix click token logic
1 parent dbca884 commit 10ce787

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<br/>
1616
<ul>
1717
<li>All of the strftime() tokens are supported for formatting.</li>
18-
<li>All of the strftime() tokens are supported for user-interaction except for %z and %Z, for two reasons:. <ul><li>Changing the zone doesn't affect the time at all (an internal timestamp), only the display of the time.</li><li>Changing zones and the zone display properly requires having access to the proper tz_data, up-to-date DST boundary tules for the zone. Date() doesn't know about any of this- it exists in your system's locale only, and depending on your locale, your time zone changes depending on the selected time and date. That data can ALSO change over time. Date() doesn't know anything about that.</li><li>There is no workaround in Javascript for the DST-boundary locale problem without including the entire tz database and creating a custom Date() object (beyond the scope of this plugin) or W3C changing the spec for the Date() object and browsers to change locale in the browser window on-the-fly.</li><li><b>Note</b>: these problems are why most web programmers cheap out and put up the three Select boxes for choosing a date.</li></ul></li>
18+
<li>All of the strftime() tokens are supported for user-interaction except for %z and %Z, for two reasons:. <ul><li>Changing the zone doesn't affect the time at all (an internal timestamp), only the display of the time.</li><li>Changing zones and the zone display properly requires having access to the proper tz_data, up-to-date DST boundary tules for the zone. Date() doesn't know about any of this- it exists in your system's locale only, and depending on your locale, your time zone changes depending on the selected time and date. That data can ALSO change over time. Date() doesn't know anything about that.</li><li>There is no workaround in Javascript for the DST-boundary locale problem without including the entire tz database and creating a custom Date() object (beyond the scope of this plugin) or W3C changing the spec for the Date() object and browsers to change locale in the browser window on-the-fly.</li><li><b>Note</b>: these problems are why most web programmers cheap out and put up the three Select
19+
boxes for choosing a date.</li></ul></li>
1920
<li>Tokens in the format of exclaimation-character instead of percent-character are <b>non-interactive replacements</b>. These are tokens that will be replaced according to strftime() rules, but the user won't be able to interact with them.</li>
2021
<li>The input on this page is currently configuredas such: <b>Tab</b> advances tokens in an input, and after the last interactive token will advance to the next focusable input. <b>Enter</b> advances to the next focusable object (like tab normally does).</li>
2122
</ul>
@@ -32,7 +33,7 @@
3233
var tests = [
3334
[, {displayFormat:"%m/%d/%y %I:%M %p"}],
3435
["1330322400000",{displayFormat:"%m/%d/%y %I:%M %p"}],
35-
["1330322400000",{displayFormat:"%c",autoResize:true}],
36+
["1330322400000",{displayFormat:"!c",autoResize:true}],
3637
["1330322400000",{displayFormat:"%m/!d/%Y"}],
3738
["2/27/2012 03:00 PM",{displayFormat:"%m/%d/%y %I:%M %p"}]
3839
];

jquery.timeInput.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,8 @@ function strtodate (str, now) {
965965
for(var i=0; i<currentToken;i++) {
966966
currentCharIndex+=(data.tokens[i].r?utcdate("%"+data.tokens[i].v,data.ds,data.timezoneOffset).trim():data.tokens[i].v).length
967967
}
968+
if(currentToken <0 || currentToken >= data.tokens.length)
969+
return false;
968970
var tokenValue = data.tokens[i].v;
969971
var endCharIndex = currentCharIndex+(data.tokens[currentToken].r?utcdate("%"+data.tokens[currentToken].v,data.ds,data.timezoneOffset).trim():data.tokens[currentToken].v).length;
970972
setTimeout(function(){selectRange(data.element,currentCharIndex,endCharIndex)},0);
@@ -977,10 +979,15 @@ function strtodate (str, now) {
977979
var data = Self.data('timeInput');
978980

979981
/* first, increment to the first VALID interactive token */
980-
while( currentTokenIndex < data.tokens.length && !data.tokens[currentTokenIndex].i) {
982+
while( currentTokenIndex < data.tokens.length && !(data.tokens[currentTokenIndex].i)) {
981983
currentCharIndex+=(data.tokens[currentTokenIndex].r?utcdate("%"+data.tokens[currentTokenIndex].v,data.ds,data.timezoneOffset).trim():data.tokens[currentTokenIndex].v).length;
982984
currentTokenIndex++;
983985
}
986+
if(currentTokenIndex <0 || currentTokenIndex >= data.tokens.length) {
987+
// if nothing is selectable.
988+
return -1;
989+
}
990+
984991
// move the index to the end of the token
985992
currentCharIndex+=(data.tokens[currentTokenIndex].r?utcdate("%"+data.tokens[currentTokenIndex].v,data.ds,data.timezoneOffset).trim():data.tokens[currentTokenIndex].v).length;
986993

@@ -1000,7 +1007,6 @@ function strtodate (str, now) {
10001007
}
10011008
if(currentTokenIndex >= data.tokens.length)
10021009
currentTokenIndex=data.tokens.length-1;
1003-
10041010
return currentTokenIndex;
10051011
}
10061012

@@ -1159,6 +1165,12 @@ function strtodate (str, now) {
11591165
return (f === 'locale' ? _lc_time[m1] : f);
11601166
});
11611167
}
1168+
while (settings.displayFormat.match(/![cDFhnrRtTxX]/)) {
1169+
settings.displayFormat = settings.displayFormat.replace(/!([cDFhnrRtTxX])/g, function (m0, m1) {
1170+
var f = _aggregates[m1];
1171+
return (f === 'locale' ? _lc_time[m1] : f).replace(/%/g,'!');
1172+
});
1173+
}
11621174

11631175
/**
11641176
* The tokens are made up ov objects:

0 commit comments

Comments
 (0)