Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("#filter").unbind("keyup");
- Search = function() {
- var _search = this;
- this.fullList = $(".front-page-post").clone();
- this.container = $(".recent-posts");
- this.typing = false;
- this.inputField = $("#filter");
- this.masonry = false;
- jQuery('.recent-posts').masonry({
- 'itemSelector' : '.front-page-post',
- 'isFitWidth': true
- });
- this.restore = function(callMason) {
- _search.container.empty();
- //_search.masonry.remove( $(".front-page-post") );
- _search.container.append(_search.fullList);
- //if (callMason===true) {_search.container.masonry();}
- }
- /*
- $.getScript("http://masonry.desandro.com/masonry.pkgd.min.js", function() {
- console.log("initialized masonry");
- //_search.masonry = new Masonry( document.querySelector('.masonry') );
- _search.handleSearch();
- });
- */
- this.filter = function(keyword) {
- _search.restore();
- $(".front-page-post").each(function(){
- if ($(this).text().search(new RegExp(keyword, "i")) < 0) {
- $(this).remove();
- }
- });
- setTimeout(function(){
- //_search.masonry.appended( $(".front-page-post") );
- //_search.masonry.layout();
- jQuery('.recent-posts').masonry('reload');
- }
- , 150);
- }
- this.handleSearch = function() {
- _search.inputField.keyup(function(evt){
- clearTimeout(_search.typing);
- _search.typing = setTimeout(function() {
- console.log("searching for:", _search.inputField.val());
- _search.filter( _search.inputField.val() );
- }, 500);
- })
- }
- }
- s = new Search();
- s.handleSearch();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement