Permalink
Browse files

Merge pull request #39 from tankchintan/master

Added new APIs for initiating search programatically, get count of matched results and fix for sync-ing global "val".
  • Loading branch information...
2 parents f984f7f + 3ad9c10 commit 704426a8b9070960e80b68d0fc998c88a67a94a2 @riklomas committed Jan 18, 2012
Showing with 37 additions and 6 deletions.
  1. +37 −6 jquery.quicksearch.js
View
@@ -7,6 +7,7 @@
stripeRows: null,
loader: null,
noResults: '',
+ matchedResultsCount: 0,
bind: 'keyup',
onBefore: function () {
return;
@@ -35,15 +36,17 @@
this.go = function () {
- var i = 0,
- noresults = true,
- query = options.prepareQuery(val),
- val_empty = (val.replace(' ', '').length === 0);
+ var i = 0,
+ numMatchedRows = 0,
+ noresults = true,
+ query = options.prepareQuery(val),
+ val_empty = (val.replace(' ', '').length === 0);
for (var i = 0, len = rowcache.length; i < len; i++) {
if (val_empty || options.testQuery(query, cache[i], rowcache[i])) {
options.show.apply(rowcache[i]);
noresults = false;
+ numMatchedRows++;
} else {
options.hide.apply(rowcache[i]);
}
@@ -56,12 +59,29 @@
this.stripe();
}
+ this.matchedResultsCount = numMatchedRows;
this.loader(false);
options.onAfter();
return this;
};
+ /*
+ * External API so that users can perform search programatically.
+ * */
+ this.search = function (submittedVal) {
+ val = submittedVal;
+ e.trigger();
+ };
+
+ /*
+ * External API to get the number of matched results as seen in
+ * https://github.com/ruiz107/quicksearch/commit/f78dc440b42d95ce9caed1d087174dd4359982d6
+ * */
+ this.currentMatchedResults = function() {
+ return this.matchedResultsCount;
+ };
+
this.stripe = function () {
if (typeof options.stripeRows === "object" && options.stripeRows !== null)
@@ -117,6 +137,12 @@
rowcache = jq_results.map(function () {
return this;
});
+
+ /*
+ * Modified fix for sync-ing "val".
+ * Original fix https://github.com/michaellwest/quicksearch/commit/4ace4008d079298a01f97f885ba8fa956a9703d1
+ * */
+ val = val || this.val() || "";
return this.go();
};
@@ -139,12 +165,17 @@
this.loader(false);
return this.each(function () {
- $(this).bind(options.bind, function () {
+
+ /*
+ * Changed from .bind to .on.
+ * */
+ $(this).on(options.bind, function () {
+
val = $(this).val();
e.trigger();
});
});
};
-}(jQuery, this, document));
+}(jQuery, this, document));

2 comments on commit 704426a

@juanlanus

Rik, in line 172 the on() method fails because the page is pulling an old jQuery.

@jtawee
jtawee commented on 704426a Apr 2, 2013

Did anyone get the latest version of this to work? I get the same error juanlanus mentions above...failing on line 172.

Please sign in to comment.