Guest User

Untitled

a guest
Jun 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. (function($){
  2. $.fn.showFilter = function(selectors, criteria, options) {
  3. this.data("lastVal", this.val());
  4. var id = 1;
  5. while($(".showFilter"+id).length > 0) id++;
  6. this.addClass(".showFilter"+id);
  7. var input = this;
  8. var filterInput = function(input) { return $.trim(input).toLowerCase().replace(/\s+/, " ") }
  9. var test = function() {
  10. var c = criteria($(this));
  11. var filters = $(this).data("showFilter");
  12. if (!filters) filters = $(this).data("showFilter", {}).data("showFilter");
  13. for (i in filters) if (filters[i] && i !== id) return;
  14. var terms = filterInput(input.val()).split(/\s+/);
  15. var matched = false;
  16. for (i in c) {
  17. var matches = true;
  18. for (j in terms) if (!(c[i].toLowerCase().indexOf(terms[j]) > -1)) matches = false;
  19. if (matches) matched = true;
  20. }
  21. if (matched) {
  22. filters[id] = false;
  23. $(this).show();
  24. }
  25. else {
  26. filters[id] = true;
  27. $(this).hide();
  28. }
  29. }
  30. var filter = function() {
  31. if (filterInput($(this).val()) === filterInput($(this).data("lastVal"))) return;
  32. alert();
  33. $(this).data("lastVal", $(this).val());
  34. $(selectors).each(test);
  35. }
  36. this.bind("keyup keydown input change paste", filter);
  37. };
  38. })(jQuery);
Add Comment
Please, Sign In to add comment