From 50e09f9c89d80889a798a9b1d126c87a90a96bc3 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 30 Jun 2011 17:00:20 +0200 Subject: [PATCH 1/2] Added support for multiple events at the same time. Before this fix, pasting text into a field with the mouse (right click + paste) didn't trigger the event. Some other plugins like clearableTextField (https://github.com/ono/clearable_text_field/) only trigger the "change" event which didn't refresh the search. --- jquery.quicksearch.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/jquery.quicksearch.js b/jquery.quicksearch.js index 7bd6f65..9e8db96 100644 --- a/jquery.quicksearch.js +++ b/jquery.quicksearch.js @@ -7,7 +7,7 @@ stripeRows: null, loader: null, noResults: '', - bind: 'keyup', + bind: ['keyup','input','mouseup','change'], onBefore: function () { return; }, @@ -109,13 +109,12 @@ jq_results = jq_results.not(options.noResults); } - var t = (typeof options.selector === "string") ? jq_results.find(options.selector) : $(target).not(options.noResults); - cache = t.map(function () { - return e.strip_html(this.innerHTML); - }); + cache = []; + rowcache = []; - rowcache = jq_results.map(function () { - return this; + jq_results.each(function () { + rowcache.push(this); + cache.push($(this).find(options.selector).text()); }); return this.go(); @@ -139,12 +138,25 @@ this.loader(false); return this.each(function () { - $(this).bind(options.bind, function () { + var self = $(this); + var handler = function (event) { + var oldVal = val; val = $(this).val(); - e.trigger(); - }); + if ( oldVal != val ) { + e.trigger(); + } + }; + + if ( typeof(options.bind) == "string" ) { + self.bind(options.bind, handler); + } + else { + options.bind.each(function(eventName){ + self.bind(eventName, handler); + }); + } }); }; -}(jQuery, this, document)); \ No newline at end of file +}(jQuery, this, document)); From 898db2b5d3ab7cf1d8d87865b40a9068adeac80d Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 30 Jun 2011 17:12:03 +0200 Subject: [PATCH 2/2] A shorter version of the event binding code. --- jquery.quicksearch.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/jquery.quicksearch.js b/jquery.quicksearch.js index 9e8db96..e340e4c 100644 --- a/jquery.quicksearch.js +++ b/jquery.quicksearch.js @@ -7,7 +7,7 @@ stripeRows: null, loader: null, noResults: '', - bind: ['keyup','input','mouseup','change'], + bind: 'keyup input mouseup change', onBefore: function () { return; }, @@ -147,14 +147,7 @@ } }; - if ( typeof(options.bind) == "string" ) { - self.bind(options.bind, handler); - } - else { - options.bind.each(function(eventName){ - self.bind(eventName, handler); - }); - } + self.bind(options.bind, handler); }); };