Advertisement
rainerpl

For stack overflow

Oct 30th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. $("#filter").unbind("keyup");
  3. Search = function() {
  4.     var _search    = this;
  5.     this.fullList  = $(".front-page-post").clone();
  6.     this.container = $(".recent-posts");
  7.     this.typing = false;
  8.     this.inputField = $("#filter");
  9.     this.masonry = false;
  10.    
  11.     jQuery('.recent-posts').masonry({
  12.         'itemSelector' : '.front-page-post',
  13.         'isFitWidth': true
  14.     });
  15.    
  16.     this.restore = function(callMason) {
  17.         _search.container.empty();
  18.         //_search.masonry.remove( $(".front-page-post") );
  19.         _search.container.append(_search.fullList);
  20.         //if (callMason===true) {_search.container.masonry();}
  21.     }
  22.     /*
  23.     $.getScript("http://masonry.desandro.com/masonry.pkgd.min.js", function() {
  24.             console.log("initialized masonry");
  25.             //_search.masonry = new Masonry( document.querySelector('.masonry')  );
  26.             _search.handleSearch();
  27.     });
  28.     */
  29.     this.filter = function(keyword) {
  30.         _search.restore();
  31.         $(".front-page-post").each(function(){
  32.             if ($(this).text().search(new RegExp(keyword, "i")) < 0) {
  33.                 $(this).remove();
  34.             }
  35.         });
  36.         setTimeout(function(){
  37.                 //_search.masonry.appended( $(".front-page-post") );
  38.                 //_search.masonry.layout();
  39.                 jQuery('.recent-posts').masonry('reload');
  40.             }
  41.         , 150);
  42.        
  43.     }
  44.    
  45.     this.handleSearch = function() {
  46.         _search.inputField.keyup(function(evt){
  47.             clearTimeout(_search.typing);
  48.             _search.typing = setTimeout(function() {
  49.                 console.log("searching for:", _search.inputField.val());
  50.                 _search.filter( _search.inputField.val() );
  51.             }, 500);
  52.         })
  53.     }
  54. }
  55.  
  56. s = new Search();
  57. s.handleSearch();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement