Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved noResults option to accept jquery dom elements in addition to string identifiers #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,29 @@ the form and input are not build by the script any more.

## Options

* #### delay
* **delay**
Delay of trigger in milliseconds
* #### selector
* **selector**
A query selector on sibling elements to test
* #### stripeRows
* **stripeRows**
An array of class names to go on each row
* #### loader
* **loader**
A query selector to find a loading element
* #### noResults
* **noResults**
A query selector to show if there's no results for the search
* #### bind
* **bind**
Event that the trigger is tied to
* #### onBefore
* **onBefore**
Function to call before trigger is called
* #### onAfter
* **onAfter**
Function to call after trigger is called
* #### show
* **show**
Function that will add styles to matched elements
* #### hide
* **hide**
Function that will add styles to unmatched elements
* #### prepareQuery
* **prepareQuery**
Function that transforms text from input_selector into query used by 'testQuery' function
* #### testQuery
* **testQuery**
Function that tells if a given item should be hidden
It takes 3 arguments:
- query prepared by 'prepareQuery'
Expand Down Expand Up @@ -156,4 +156,4 @@ Thanks to [Seth F.][thelizardreborn] for fixes and [Krzysiek Goj][goj] for the
[github_follow]: http://github.com/users/follow?target=riklomas
[twitter_follow]: http://twitter.com/riklomas
[thelizardreborn]: http://github.com/thelizardreborn
[goj]: http://github.com/goj
[goj]: http://github.com/goj
35 changes: 24 additions & 11 deletions jquery.quicksearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
this.matchedResultsCount = numMatchedRows;
this.loader(false);
options.onAfter();

return this;
};

Expand Down Expand Up @@ -104,13 +103,22 @@
};

this.results = function (bool) {
if (typeof options.noResults === "string" && options.noResults !== "") {

if (options.noResults) {

var noResultsEl = options.noResults;

if (typeof options.noResults === "string") {
noResultsEl = $(options.noResults);
}

if (bool) {
$(options.noResults).hide();
noResultsEl.hide();
} else {
$(options.noResults).show();
noResultsEl.show();
}
}

return this;
};

Expand All @@ -121,15 +129,16 @@
return this;
};

this.cache = function () {
this.cache = function (doRedraw) {

jq_results = $(target);
doRedraw = (typeof doRedraw === "undefined") ? true : doRedraw;

if (typeof options.noResults === "string" && options.noResults !== "") {
jq_results = jq_results.not(options.noResults);
}
jq_results = options.noResults ? $(target).not(options.noResults) : $(target);

var t = (typeof options.selector === "string") ? jq_results.find(options.selector) : $(target).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);
});
Expand All @@ -144,7 +153,11 @@
* */
val = val || this.val() || "";

return this.go();
if (doRedraw) {
this.go();
}

return this;
};

this.trigger = function () {
Expand Down