Skip to content

Commit

Permalink
if no value run fetchPosts, put behind a delay so we dont run excessi…
Browse files Browse the repository at this point in the history
…vely

ref #73
  • Loading branch information
Bearded Avenger committed May 29, 2015
1 parent 3bedc74 commit 316857e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
31 changes: 21 additions & 10 deletions public/assets/js/lasso.js
Expand Up @@ -13271,28 +13271,39 @@ jQuery(document).ready(function($){

});

}).on('keyup','.lasso--search input',function(){ // live search - @since 0.9.5
}).on('keyup','.lasso--search input',function(e){ // live search - @since 0.9.5

var val = $(this).val()
, url = api+'/posts?filter[s]='+val

if ( val.length >= 4 ) {
setTimeout(function(){

$(postList).prepend( loader );
if ( val.length >= 3 ) {

$.getJSON( url, function( response ) {
$(postList).prepend( loader );

$(postList).children().remove()
$.getJSON( url, function( response ) {

$.each( response, function ( i ) {
$(postList).children().remove()

$(postList).prepend( postTemplate( { post: response[i], settings: WP_API_Settings } ) );
$.each( response, function ( i ) {

} );
$(postList).prepend( postTemplate( { post: response[i], settings: WP_API_Settings } ) );

});
} );

}
});

}

if ( val == '' ) {

$(postList).children().remove()

fetchPosts('post')
}

}, 500 );

})

Expand Down
2 changes: 1 addition & 1 deletion public/assets/js/lasso.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/lasso.min.js

Large diffs are not rendered by default.

31 changes: 21 additions & 10 deletions public/assets/js/source/all-posts.js
Expand Up @@ -226,28 +226,39 @@

});

}).on('keyup','.lasso--search input',function(){ // live search - @since 0.9.5
}).on('keyup','.lasso--search input',function(e){ // live search - @since 0.9.5

var val = $(this).val()
, url = api+'/posts?filter[s]='+val

if ( val.length >= 4 ) {
setTimeout(function(){

$(postList).prepend( loader );
if ( val.length >= 3 ) {

$.getJSON( url, function( response ) {
$(postList).prepend( loader );

$(postList).children().remove()
$.getJSON( url, function( response ) {

$.each( response, function ( i ) {
$(postList).children().remove()

$(postList).prepend( postTemplate( { post: response[i], settings: WP_API_Settings } ) );
$.each( response, function ( i ) {

} );
$(postList).prepend( postTemplate( { post: response[i], settings: WP_API_Settings } ) );

});
} );

}
});

}

if ( val == '' ) {

$(postList).children().remove()

fetchPosts('post')
}

}, 500 );

})

Expand Down

0 comments on commit 316857e

Please sign in to comment.