livesearch - Jquery live search: fire with button? -
livesearch - Jquery live search: fire with button? -
i found this fiddle functions how want on page, except need search occur when user clicks search button (which utilize help adding) or hits come in key - not while typing.
here's code:
//live search $('.filter-bar #search').search('.filter-results li', function(on) { on.all(function(results) { var size = results ? results.size() : 0 $('.filter-results-count').text(size + ' results'); }); on.reset(function() { $('.no-filter-results').hide(); $('.filter-results li').show(); }); on.empty(function() { $('.no-filter-results').show(); $('.filter-results li').hide(); }); on.results(function(results) { $('.no-filter-results').hide(); $('.filter-results li').hide(); results.show(); }); });
the next step making search not case sensitive , business relationship type-o's. (could utilize quick silver or liquid metal or that?)
if modify fiddle solve best me understand.
there library added makes search possible. i've edited original code. please utilize code below! search when press come in key. rest still same.
(function($) { var search = function(block) { this.callbacks = {}; block(this); } search.prototype.all = function(fn) { this.callbacks.all = fn; } search.prototype.reset = function(fn) { this.callbacks.reset = fn; } search.prototype.empty = function(fn) { this.callbacks.empty = fn; } search.prototype.results = function(fn) { this.callbacks.results = fn; } function query(selector) { if (val = this.val()) { homecoming $(selector + ':contains("' + val + '")');; } else { homecoming false; } } $.fn.search = function search(selector, block) { var search = new search(block); var callbacks = search.callbacks; function perform() { if (result = query.call($(this), selector)) { callbacks.all && callbacks.all.call(this, result); var method = result.size() > 0 ? 'results' : 'empty'; homecoming callbacks[method] && callbacks[method].call(this, result); } else { callbacks.all && callbacks.all.call(this, $(selector)); homecoming callbacks.reset && callbacks.reset.call(this); }; } $(this).live('keypress', function(e){ if( e.which == 13) perform(); }); } })(jquery);
jquery livesearch
Comments
Post a Comment