riklomas / quicksearch

A jQuery plugin for searching through tables, lists, etc quickly
http://www.lomalogue.com/jquery/quicksearch/
680 stars 261 forks source link

quicksearch overloads jQuery methods #10

Closed shadowhand closed 13 years ago

shadowhand commented 13 years ago

Right now it is impossible to do this:

var search = $('form input.search').quicksearch();
search.val('').trigger('keyup');

and have the search form reset, showing all rows.

The problem lies in the way that quicksearch uses this, which in the context of a plugin, refers to the matched element, not the $.fn.quicksearch class. To correct this, either use $.fn.quicksearch.func instead of this.func or simply func and disallow outside access.

shadowhand commented 13 years ago

To hack around resetting the form as in the above example, I had to rename jQuery.fn.quicksearch.trigger to jQuery.fn.quicksearch.activate.

shadowhand commented 13 years ago

Closed this by mistake... please reopen and delete this comment.

riklomas commented 13 years ago

This is intentional so that users can have access to internal functions, see the Ajax example on the documentation to see how it's used

shadowhand commented 13 years ago

My use case still stands. Once you apply quicksearch to an input, you can no longer use the jQuery.trigger method. A plugin should not overwrite existing methods. There are many ways to provide access to internal functions without polluting the jQuery namespace.

shadowhand commented 13 years ago

From the docs:

Under no circumstance should a single plugin ever claim more than one namespace in the jQuery.fn object.