Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. function someFunction(text) {
  2. $('.class').each(function() {
  3. var $this = $(this);
  4. if ($this.text().match(text)) {
  5. $this.addClass('found');
  6. } else {
  7. $this.removeClass('found');
  8. }
  9. });
  10. }
  11.  
  12. $('input[type=text]').keyup(function() {
  13. someFunction($(this).val());
  14. });
  15.  
  16. function someFunction(text) {
  17. $('.class').removeClass('found').filter(':contains("' + text + '")').addClass('found');
  18. }
  19.  
  20. var timer;
  21. $('input[type=text]').keyup(function() {
  22. clearTimeout(timer);
  23. timer = setTimeout(function() {
  24. someFunction(this.value);
  25. }, 100);
  26. });
  27.  
  28. var $elements = $('.class');
  29. function someFunction(text) {
  30. $elements.removeClass('found').filter(':contains("' + text + '")').addClass('found');
  31. }
  32.  
  33. var timer;
  34. $('input[type=text]').keyup(function() {
  35. clearTimeout(timer);
  36. timer = setTimeout(function() {
  37. someFunction(this.value);
  38. }, 100);
  39. });
  40.  
  41. function someFunction(text) {
  42. $('.class').each(function() {
  43. var $this = $(this);
  44. if ($this.text().match(text)) {
  45. $this.addClass('found');
  46. } else {
  47. $this.removeClass('found');
  48. }
  49.  
  50. });
  51. return false;
  52. }
  53.  
  54. window.lastValue = null;
  55.  
  56. window.cachedElements = null;
  57.  
  58. window.updateCachedElements = function(){ cachedElements = $('.class'); };
  59.  
  60. function someFunction() {
  61. cachedElements.each(function() {
  62. var $this = $(this);
  63. if ($this.text().match(lastValue)) {
  64. $this.addClass('found');
  65. } else {
  66. $this.removeClass('found');
  67. }
  68. });
  69. }
  70.  
  71. $('input[type=text]').keyup(function() {
  72. if(cachedElements === null) {
  73. updateCachedElements();
  74. }
  75.  
  76. lastValue = $(this).val()
  77.  
  78. someFunction();
  79. });
  80.  
  81. setInterval(function(){ updateCachedElements(); someFunction(); }, 500);
  82.  
  83. someFunction = debounce(someFunction, 100);
  84.  
  85. _.debounce = function(func, wait, immediate) {
  86. var timeout, args, context, timestamp, result;
  87.  
  88. var later = function() {
  89. var last = (Date.now || new Date().getTime()) - timestamp;
  90.  
  91. if (last < wait && last >= 0) {
  92. timeout = setTimeout(later, wait - last);
  93. } else {
  94. timeout = null;
  95. if (!immediate) {
  96. result = func.apply(context, args);
  97. if (!timeout) context = args = null;
  98. }
  99. }
  100. };
  101.  
  102. return function() {
  103. context = this;
  104. args = arguments;
  105. timestamp = _.now();
  106. var callNow = immediate && !timeout;
  107. if (!timeout) timeout = setTimeout(later, wait);
  108. if (callNow) {
  109. result = func.apply(context, args);
  110. context = args = null;
  111. }
  112.  
  113. return result;
  114. };
  115. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement