/***********************************************************/
/*                    LiveFilter Plugin                    */
/*                      Version: 1.4                       */
/*                      Mike Merritt                       */
/*        https://github.com/mikemerritt/LiveFilter        */
/***********************************************************/

(function($){
  $.fn.liveFilter = function (settings) {

    // Default settings
    var defaults = {
      delay: 0,
      defaultText: 'Type to Filter:',
      resetText: 'Reset',
      noMatches: 'No Matches',
      fitlerTargetCustomDiv: 'div',
      hideDefault: false,
      addInputs: false,
      ignore: false,
      zebra: {
        enabled: false,
        baseColor: false,
        altColor: false
      }
    };

    // Overwrite default settings with user provided ones. Declare some vars.
    var options = $.extend(defaults, settings);
    var keyDelay, filter, child;

    // Cache our wrapper element and find our target list.
    var wrap = $(this);
    var filterTarget = wrap.find('ul, ol, table, div');

    // Add no matches text.
    wrap.append('<div class="nomatches">'+options.noMatches+'</div>');
    var nomatches = $('.nomatches');
    nomatches.hide();

    // Determine our child element type.
    if (filterTarget.is('ul') || filterTarget.is('ol')) {
      child = 'li';
    } else if (filterTarget.is('table')) {
      child = 'tbody tr';
    } else {
      child = options.fitlerTargetCustomDiv;
    }

    // Hide the list/table by default. If not being hidden apply zebra striping if needed.
    if (options.hideDefault === true) {
      filterTarget.find(child).hide();
    } else if (options.hideDefault === false && options.zebra.enabled != false) {
      zebraStriping();
    }

    // Add inputs if required
    if (options.addInputs === true) {
      var markup = '<input class="filter" type="text" value="" /><input class="reset" type="reset" value="' + options.resetText + '" />';
      wrap.prepend(markup);
    }

    // Used to reset our text input and show all items in the filtered list
    wrap.find('input[type="reset"]').on("click", function() {
      nomatches.hide();

      if (options.defaultText === false) {

        wrap.find('input[type="text"]').attr('value', '');

        if (options.hideDefault === false) {
          list.each(function(i) {
            $(this).show();
          });
        } else if (options.hideDefault === true) {
          list.each(function(i) {
            $(this).hide();
          });
        }

      } else {

        wrap.find('input[type="text"]').attr('value', options.defaultText);

        if (options.hideDefault === false) {
          list.each(function(i) {
            $(this).show();
          });
        } else if (options.hideDefault === true) {
          list.each(function(i) {
            $(this).hide();
          });
        }

      }
      return false;
    });

    // Used to set the default text of the text input if there is any
    if (options.defaultText != false) {

      var input = wrap.find('input[type="text"]');
      input.attr('value', options.defaultText);

      input.focus(function() {
        var curVal = $(this).attr('value');
        if (curVal === options.defaultText) {
          $(this).attr('value', '');
        }
      });

      input.blur(function() {
        var curVal = $(this).attr('value');
        if (curVal === '') {
          $(this).attr('value', options.defaultText);
        }
      });

    }

    // Cache list/table elements so we don't have to keep traversing the DOM.
    var list = filterTarget.find(child);

    // Keyup event - where the magic happens.
    wrap.find('input[type="text"]').on("keyup", function() {

      var input = $(this);
      clearTimeout(keyDelay);

      // Setting timeout for performance reasons.
      keyDelay = setTimeout(function () { 

        filter = input.val().toLowerCase();
        var visible = 0;
        var words = filter.split(' ');

        if (filter === '' && options.hideDefault === true) {
          list.each(function(i) {
            $(this).hide();
          })
        } else {
          // Iterate through list and show/hide the proper elements.
          list.each(function(i) {
            text = $(this).text().toLowerCase();
              // Non consecutive filtering
              for (var t = 0; t < words.length; t++) {
                if (text.indexOf(words[t]) < 0) {
                  var match = false;
                  break;
                } else {
                  var match = true;
                }
              }

              if (match === true) {
                visible ++;
                $(this).show();
              } else if (match === false) {
                $(this).hide();
              }
          });

          if (visible === 0) {
            nomatches.show();
          } else if (visible > 0) {
            nomatches.hide();
          }

          if (options.ignore != false) {
            options.ignore.show();
          }

          if(options.zebra.enabled != false) {
            zebraStriping();
          }
        }

        clearTimeout(keyDelay);
      }, options.delay);

    });

    // Used for zebra striping list/table.
    function zebraStriping() {
      filterTarget.find(child + ':visible:odd').css({ background: options.zebra.baseColor });
      filterTarget.find(child + ':visible:even').css({ background: options.zebra.altColor });
    }

  }
})(jQuery);

@@ -418,25 +418,24 @@
 settings) %7B%0A
-%0A
     // Defau
@@ -1081,17 +1081,16 @@
 , table,
- 
 div');%0A%0A
@@ -1292,24 +1292,117 @@
 ype.%0A    if 
+(options.fitlerTargetCustomDiv) %7B%0A      child = options.fitlerTargetCustomDiv;%0A    %7D else if 
 (filterTarge
@@ -1538,66 +1538,8 @@
    %7D
- else %7B%0A      child = options.fitlerTargetCustomDiv;%0A    %7D
 %0A%0A  
@@ -2941,24 +2941,25 @@
  %7D%0A%0A      %7D%0A
+%0A
       return
@@ -3224,32 +3224,36 @@
 %0A        var cur
+rent
 Val = $(this).at
@@ -3246,36 +3246,28 @@
 l = $(this).
-attr('value'
+val(
 );%0A        i
@@ -3264,32 +3264,36 @@
 %0A        if (cur
+rent
 Val === options.
@@ -3325,30 +3325,20 @@
 $(this).
-attr('value', 
+val(
 '');%0A   
@@ -3400,16 +3400,20 @@
  var cur
+rent
 Val = $(
@@ -3422,22 +3422,15 @@
 is).
-attr('value'
+val(
 );
+ 
 %0A   
@@ -3441,16 +3441,20 @@
  if (cur
+rent
 Val === 
@@ -3477,30 +3477,20 @@
 $(this).
-attr('value', 
+val(
 options.
@@ -3813,24 +3813,233 @@
 keyDelay);%0A%0A
+      // Add a class that the text has been processed%0A      if (input.val() !== '') %7B%0A        wrap.addClass('live-filter-processed');%0A      %7D else %7B%0A        wrap.removeClass('live-filter-processed');%0A      %7D%0A%0A
       // Set

Add class when contents have been processed