Sha256: 321f5f97562d9f56f59b07fbe0814b9a70678bbb36f7c813a37d57668fd22dd7

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

// https://github.com/nakajima/jquery-livesearch
(function($) {
  $.extend($.expr[':'], {
    'containsi': function(elem, i, match, array) {
      return $(elem).text().toLowerCase()
        .indexOf((match[3] || "").toLowerCase()) >= 0;
    }
  });

  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()) {
      return $(selector + ':containsi("' + val + '")');
    } else {
      return 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';
        return callbacks[method] && callbacks[method].call(this, result);
      } else {
        callbacks.all && callbacks.all.call(this, $(selector));
        return callbacks.reset && callbacks.reset.call(this);
      };
    }

    $(this).on('keypress', perform);
    $(this).on('keydown', perform);
    $(this).on('keyup', perform);
    $(this).on('blur', perform);
  }
})(jQuery);

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cardboard_cms-0.3.1 vendor/assets/javascripts/cardboard/jquery.livesearch.js
cardboard_cms-0.2.2 vendor/assets/javascripts/cardboard/jquery.livesearch.js
cardboard_cms-0.2.1 vendor/assets/javascripts/cardboard/jquery.livesearch.js
cardboard_cms-0.1.8 vendor/assets/javascripts/cardboard/jquery.livesearch.js
cardboard_cms-0.1.6 vendor/assets/javascripts/cardboard/jquery.livesearch.js
cardboard_cms-0.1.4 vendor/assets/javascripts/cardboard/jquery.livesearch.js