diff options
author | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-05-05 05:06:27 +0900 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-05-04 17:00:40 -0400 |
commit | f9faa0ab5fb2b9f332de93fd9d8fb97e9957ff6d (patch) | |
tree | 96c1d8898a61622fe3d51f5859be837cb96b7a57 /ui/jquery.ui.datepicker.js | |
parent | 0d0addee1621f231a6f8b9bc33c087f70cd5628b (diff) | |
download | jquery-ui-f9faa0ab5fb2b9f332de93fd9d8fb97e9957ff6d.tar.gz jquery-ui-f9faa0ab5fb2b9f332de93fd9d8fb97e9957ff6d.zip |
Datepicker: Greedy matching in month name. Fixed #7062 - $.datepicker.parseDate does not work for some locale date strings.
(cherry picked from commit a891e81e06c7ce491ae9058aea2fa7fbd51eddb6)
Diffstat (limited to 'ui/jquery.ui.datepicker.js')
-rw-r--r-- | ui/jquery.ui.datepicker.js | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/ui/jquery.ui.datepicker.js b/ui/jquery.ui.datepicker.js index d6419e2e3..fe24d695a 100644 --- a/ui/jquery.ui.datepicker.js +++ b/ui/jquery.ui.datepicker.js @@ -992,14 +992,24 @@ $.extend(Datepicker.prototype, { }; // Extract a name from the string value and convert to an index var getName = function(match, shortNames, longNames) { - var names = (lookAhead(match) ? longNames : shortNames); - for (var i = 0; i < names.length; i++) { - if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) { - iValue += names[i].length; - return i + 1; + var names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) { + return [ [k, v] ]; + }).sort(function (a, b) { + return -(a[1].length - b[1].length); + }); + var index = -1; + $.each(names, function (i, pair) { + var name = pair[1]; + if (value.substr(iValue, name.length).toLowerCase() == name.toLowerCase()) { + index = pair[0]; + iValue += name.length; + return false; } - } - throw 'Unknown name at position ' + iValue; + }); + if (index != -1) + return index + 1; + else + throw 'Unknown name at position ' + iValue; }; // Confirm that a literal character matches the string value var checkLiteral = function() { |