X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/3ac9cb26acd9b7c5ba421dac123ba8f75b782bd2..7397e336b6f566b9425e17ab9a05c3698ea273e7:/wolnelektury/static/js/jquery.autocomplete.js
diff --git a/wolnelektury/static/js/jquery.autocomplete.js b/wolnelektury/static/js/jquery.autocomplete.js
index 9d12a29f2..4e425e8bd 100644
--- a/wolnelektury/static/js/jquery.autocomplete.js
+++ b/wolnelektury/static/js/jquery.autocomplete.js
@@ -10,6 +10,11 @@
* Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $
*/
+/*
+ * Modified by Radek Czajka, Fundacja Nowoczesna Polska, 2010-05-10:
+ * escape regex for word start checking in matchSubset
+ */
+
;(function($) {
$.fn.extend({
@@ -425,8 +430,22 @@ $.Autocompleter.defaults = {
width: 0,
multiple: false,
multipleSeparator: ", ",
+ regex_escape: function(term) {
+ term = term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1");
+ /* no polish diacritics; should be more locale-aware */
+ term = term.replace(/a/g, '[aÄ
]')
+ .replace(/c/g, '[cÄ]')
+ .replace(/e/g, '[eÄ]')
+ .replace(/l/g, '[lÅ]')
+ .replace(/n/g, '[nÅ]')
+ .replace(/o/g, '[oó]')
+ .replace(/s/g, '[sÅ]')
+ .replace(/z/g, '[zźż]');
+ return term;
+ },
highlight: function(value, term) {
- return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1");
+ term = $.Autocompleter.defaults.regex_escape(term);
+ return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1");
},
scroll: true,
scrollHeight: 180
@@ -442,7 +461,8 @@ $.Autocompleter.Cache = function(options) {
s = s.toLowerCase();
var i = s.indexOf(sub);
if (options.matchContains == "word"){
- i = s.toLowerCase().search("\\b" + sub.toLowerCase());
+ query = $.Autocompleter.defaults.regex_escape(sub.toLowerCase());
+ i = s.toLowerCase().search("\\b" + query);
}
if (i == -1) return false;
return i == 0 || options.matchContains;