* 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({
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"), "<strong>$1</strong>");
+ term = $.Autocompleter.defaults.regex_escape(term);
+ return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
},
scroll: true,
scrollHeight: 180
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;