From 80152fd960da58dc744f4cca12aa937bb090f9d5 Mon Sep 17 00:00:00 2001 From: bicouy0 Date: Mon, 2 Jan 2012 10:47:51 +0100 Subject: [PATCH] make the code more explicit about attaching things to the select --- lib/ajax-chosen.js | 8 ++++---- lib/ajax-chosen.min.js | 8 ++++---- src/ajax-chosen.coffee | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/ajax-chosen.js b/lib/ajax-chosen.js index 5f8e354..1daeb23 100644 --- a/lib/ajax-chosen.js +++ b/lib/ajax-chosen.js @@ -20,15 +20,15 @@ https://github.com/bicouy0/ajax-chosen }; $.extend(defaultedOptions, options); defaultedOptions.chosenOptions.no_results_text = defaultedOptions.searchingText; - multiple = this.attr('multiple') != null; + select = this; + multiple = select.attr('multiple') != null; if (multiple) { inputSelector = ".search-field > input"; } else { inputSelector = ".chzn-search > input"; } - select = this; - this.chosen(defaultedOptions.chosenOptions); - return this.next('.chzn-container').find(inputSelector).bind('keyup', function(e) { + select.chosen(defaultedOptions.chosenOptions); + return select.next('.chzn-container').find(inputSelector).bind('keyup', function(e) { var search, _this = this; if (this.previousSearch) clearTimeout(this.previousSearch); diff --git a/lib/ajax-chosen.min.js b/lib/ajax-chosen.min.js index 57cc0e0..835bf37 100644 --- a/lib/ajax-chosen.min.js +++ b/lib/ajax-chosen.min.js @@ -1,4 +1,4 @@ -(function(){(function(a){return a.fn.ajaxChosen=function(y,z){var b,v,r,i;b={minLength:3,queryLimit:10,delay:100,chosenOptions:{},searchingText:"Searching...",noresultsText:"No results."};a.extend(b,y);b.chosenOptions.no_results_text=b.searchingText;v=(r=this.attr("multiple")!=null)?".search-field > input":".chzn-search > input";i=this;this.chosen(b.chosenOptions);return this.next(".chzn-container").find(v).bind("keyup",function(){var w=this;this.previousSearch&&clearTimeout(this.previousSearch); -return this.previousSearch=setTimeout(function(){var q,j,e,s,m;e=a(w);m=a.trim(e.attr("value"));s=(q=e.data("prevVal"))!=null?q:"";e.data("prevVal",m);q=function(){return(r?e.parent().parent().siblings():e.parent().parent()).find(".no-results").html(b.noresultsText+" '"+a(w).attr("value")+"'")};if(m.length");d.attr("value",o).html(c);return n.push(a(d))});g=function(o){var c,d;c=a(o);if(!(c.attr("selected")&&r))if(!(c.attr("value")===""&&c.html()===""&&!r))if(function(){var k,l,p;p=[];k=0;for(l=n.length;k");g.addClass("no-results");g.html(b.noresultsText+" '"+f+"'").attr("value","");i.append(g)}else i.change();i.trigger("liszt:updated");a(".no-results").removeClass("active-result");e.val(f);if(!a.isEmptyObject(t)){f=a.Event("keydown");f.which=40;e.trigger(f)}if(x)return x(t)}})},b.delay)})}})(jQuery)}).call(this); +(function(){(function(a){return a.fn.ajaxChosen=function(y,z){var b,v,r,e;b={minLength:3,queryLimit:10,delay:100,chosenOptions:{},searchingText:"Searching...",noresultsText:"No results."};a.extend(b,y);b.chosenOptions.no_results_text=b.searchingText;e=this;v=(r=e.attr("multiple")!=null)?".search-field > input":".chzn-search > input";e.chosen(b.chosenOptions);return e.next(".chzn-container").find(v).bind("keyup",function(){var w=this;this.previousSearch&&clearTimeout(this.previousSearch);return this.previousSearch= +setTimeout(function(){var q,j,f,s,m;f=a(w);m=a.trim(f.attr("value"));s=(q=f.data("prevVal"))!=null?q:"";f.data("prevVal",m);q=function(){return(r?f.parent().parent().siblings():f.parent().parent()).find(".no-results").html(b.noresultsText+" '"+a(w).attr("value")+"'")};if(m.length");d.attr("value",o).html(c);return n.push(a(d))});h=function(o){var c,d;c=a(o);if(!(c.attr("selected")&&r))if(!(c.attr("value")===""&&c.html()===""&&!r))if(function(){var k,l,p;p=[];k=0;for(l=n.length;k");h.addClass("no-results");h.html(b.noresultsText+" '"+g+"'").attr("value","");e.append(h)}else e.change();e.trigger("liszt:updated");a(".no-results").removeClass("active-result");f.val(g);if(!a.isEmptyObject(t)){g=a.Event("keydown");g.which=40;f.trigger(g)}if(x)return x(t)}})},b.delay)})}})(jQuery)}).call(this); diff --git a/src/ajax-chosen.coffee b/src/ajax-chosen.coffee index 45659e2..50aeab0 100644 --- a/src/ajax-chosen.coffee +++ b/src/ajax-chosen.coffee @@ -24,13 +24,16 @@ https://github.com/bicouy0/ajax-chosen #However, we need two states, searching #and no results. # - #TODO: you accidentally lose any user definied no_results_test + #TODO: you may accidentally lose any user definied no_results_test defaultedOptions.chosenOptions.no_results_text = defaultedOptions.searchingText + # grab a reference to the select box + select = this + # determining whether this allows # multiple results will affect both the selector # and the ways previously selected results are cleared (line 88) - multiple = this.attr('multiple')? + multiple = select.attr('multiple')? #the box where someone types has a different selector #based on the type @@ -39,15 +42,12 @@ https://github.com/bicouy0/ajax-chosen else inputSelector = ".chzn-search > input" - # grab a reference to the select box - select = this - - #initialize chosen - this.chosen(defaultedOptions.chosenOptions) + # initialize chosen + select.chosen(defaultedOptions.chosenOptions) # Now that chosen is loaded normally, we can attach # a keyup event to the input field. - this.next('.chzn-container') + select.next('.chzn-container') .find(inputSelector) .bind 'keyup', (e)->