Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bearded Avenger committed Jun 24, 2015
2 parents c155a8d + e100121 commit 3d968c8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Yep! Just copy over the function from underscore-template.php (without the funct

== Changelog ==

= 0.9 =
* added some CSS classes wpls--empty and wpls--full to the custom target div to aid in custom theming
* added logic to prevent searching on escape or arrow keys

= 0.8 =
* added "dropdown" option mode for use in small spaces
* added "results_style" option for use in small spaces
Expand Down
33 changes: 29 additions & 4 deletions public/assets/js/wp-live-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
, api = WP_API_Settings.root
, timer

$( postList ).addClass('wpls--empty');

$( input ).on('keyup keypress', function ( e ) {

// clear the previous timer
Expand All @@ -46,27 +48,32 @@
// what if the user only types two characters?
if ( val.length == 2 && !$(helper).length ) {

$(input).after( helperSpan );
$( input ).after( helperSpan );

}

// if we have more than 3 characters
if ( val.length >= 3 || val.length >= 3 && 13 == key ) {

// dont run on escape or arrow keys
if( blacklistedKeys( key ) )
return false;

// show loader
$(loader).removeClass('wpls--hide').addClass('wpls--show');
$( loader ).removeClass('wpls--hide').addClass('wpls--show');

// remove any helpers
$( helper ).fadeOut().remove();

// remove the cose
destroyClose();
destroyClose()

// make the search request
$.getJSON( url, function( response ) {

// remove current list of posts
$(postList).children().remove();
$(postList).removeClass('wpls--full').addClass('wpls--empty')

// show results
$(results).parent().removeClass('wpls--hide').addClass('wpls--show');
Expand All @@ -85,6 +92,10 @@

} else {

// again, dont run on escape or arrow keys
if( blacklistedKeys( key ) )
return false;

// append close button
if ( !$( clearItem ).length ) {

Expand All @@ -97,7 +108,9 @@
// loop through each object
$.each( response, function ( i ) {

$(postList).append( itemTemplate( { post: response[i], settings: WP_API_Settings, excerpt: showExcerpt } ) );
$(postList).append( itemTemplate( { post: response[i], settings: WP_API_Settings, excerpt: showExcerpt } ) )
.removeClass('wpls--empty')
.addClass('wpls--full')

} );
}
Expand Down Expand Up @@ -143,9 +156,21 @@
$( postList ).children().remove();
$( input ).val('');
$( results ).parent().removeClass('wpls--show').addClass('wpls--hide');
$( postList ).removeClass('wpls--full').addClass('wpls--empty')
$( helper ).remove();
destroyClose()
}

/**
* Blacklisted keys - dont allow search on escape or arrow keys
* @since 0.9
*/
function blacklistedKeys( key ){

return 27 == key || 37 == key || 38 == key || 39 == key || 40 == key;

}

});

})( jQuery, Backbone, _, WP_API_Settings );
4 changes: 2 additions & 2 deletions wp-live-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: WP Live Search
* Plugin URI: http://nickhaskins.com
* Description: A super light-weight live search plugin that utilizes the WP REST API
* Version: 0.8
* Version: 0.9
* GitHub Plugin URI: https://github.com/bearded-avenger/wp-live-search
*/

Expand All @@ -20,7 +20,7 @@
}

// Set some constants
define('WP_LIVE_SEARCH_VERSION', '0.8');
define('WP_LIVE_SEARCH_VERSION', '0.9');
define('WP_LIVE_SEARCH_DIR', plugin_dir_path( __FILE__ ));
define('WP_LIVE_SEARCH_URL', plugins_url( '', __FILE__ ));

Expand Down

0 comments on commit 3d968c8

Please sign in to comment.