From: Radek Czajka Date: Tue, 11 May 2010 07:55:01 +0000 (+0200) Subject: Fixed autocomplete. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/0cec4153452e7c8008f274b06d8d4fdeb234c3b4?ds=sidebyside Fixed autocomplete. Set autocomplete cache search setting to 'word'. jquery.autocomplete: escaping strings for regex. jquery.countdown: minor fix. --- diff --git a/apps/catalogue/forms.py b/apps/catalogue/forms.py index 4b600b639..b040ef911 100644 --- a/apps/catalogue/forms.py +++ b/apps/catalogue/forms.py @@ -18,7 +18,7 @@ class BookImportForm(forms.Form): class SearchForm(forms.Form): - q = JQueryAutoCompleteField('/katalog/tags/', {'minChars': 2, 'selectFirst': True, 'cacheLength': 50}) + q = JQueryAutoCompleteField('/katalog/tags/', {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"}) tags = forms.CharField(widget=forms.HiddenInput, required=False) def __init__(self, *args, **kwargs): diff --git a/wolnelektury/static/js/jquery.autocomplete.js b/wolnelektury/static/js/jquery.autocomplete.js index 9d12a29f2..7cdb359d5 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({ @@ -442,7 +447,7 @@ $.Autocompleter.Cache = function(options) { s = s.toLowerCase(); var i = s.indexOf(sub); if (options.matchContains == "word"){ - i = s.toLowerCase().search("\\b" + sub.toLowerCase()); + i = s.toLowerCase().search("\\b" + sub.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1").toLowerCase()); } if (i == -1) return false; return i == 0 || options.matchContains; diff --git a/wolnelektury/static/js/jquery.countdown-pl.js b/wolnelektury/static/js/jquery.countdown-pl.js index 34b805ac2..4d6d1d44c 100644 --- a/wolnelektury/static/js/jquery.countdown-pl.js +++ b/wolnelektury/static/js/jquery.countdown-pl.js @@ -7,7 +7,9 @@ labels: ['lat', 'miesięcy', 'tygodni', 'dni', 'godzin', 'minut', 'sekund'], labels1: ['rok', 'miesiąc', 'tydzień', 'dzień', 'godzina', 'minuta', 'sekunda'], labels2: ['lata', 'miesiące', 'tygodnie', 'dni', 'godziny', 'minuty', 'sekundy'], - compactLabels: ['l', 'm', 't', 'd'], compactLabels1: ['r', 'm', 't', 'd'], + compactLabels: ['l', 'm', 't', 'd'], + compactLabels1: ['r', 'm', 't', 'd'], + compactLabels2: ['l', 'm', 't', 'd'], timeSeparator: ':', isRTL: false, which: function(n){ return n==1 ? 1 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 0; diff --git a/wolnelektury/static/js/jquery.countdown.js b/wolnelektury/static/js/jquery.countdown.js index 5375ce815..11d550612 100644 --- a/wolnelektury/static/js/jquery.countdown.js +++ b/wolnelektury/static/js/jquery.countdown.js @@ -6,7 +6,7 @@ Please attribute the author if you use it. */ /* Modified by Radek Czajka, Fundacja Nowoczesna Polska (radoslaw.czajka(at)nowoczesnapolska.org.pl) */ - +w /* Display a countdown timer. Attach it with options like: $('div selector').countdown( @@ -471,7 +471,10 @@ $.extend(Countdown.prototype, { var timeSeparator = this._get(inst, 'timeSeparator'); var description = this._get(inst, 'description') || ''; var showCompact = function(period) { - var labelsNum = $.countdown._get(inst, 'compactLabels' + periods[period]); + var which = $.countdown._get(inst, 'which'); + if (which) { + var labelsNum = $.countdown._get(inst, 'compactLabels' + which(periods[period])); + } return (show[period] ? periods[period] + (labelsNum ? labelsNum[period] : labels[period]) + ' ' : ''); };