diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9b2a085
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/vendor/
+# generated
+release/
diff --git a/cmb-field-post-search-ajax.php b/cmb-field-post-search-ajax.php
index 12b366e..fe8fb8c 100644
--- a/cmb-field-post-search-ajax.php
+++ b/cmb-field-post-search-ajax.php
@@ -13,8 +13,8 @@
/**
* Class MAG_CMB2_Field_Post_Search_Ajax
*/
-if( ! class_exists( 'MAG_CMB2_Field_Post_Search_Ajax' ) ) {
-
+if ( ! class_exists( 'MAG_CMB2_Field_Post_Search_Ajax' ) ) {
+
class MAG_CMB2_Field_Post_Search_Ajax {
/**
@@ -39,61 +39,66 @@ public function __construct() {
/**
* Render field
*/
- public function render( $field, $value, $object_id, $object_type, $field_type ) {
+ public function render( $field, $value, $object_id, $object_type, $field_type ) {
$this->setup_admin_scripts();
$field_name = $field->_name();
- if($field->args( 'limit' ) > 1){
+ if ( 1 !== $field->args( 'limit' ) ) {
echo '
';
- if( isset($value) && !empty($value) ){
- if( !is_array($value) ){ $value = array($value); }
- foreach($value as $val){
- $handle = ($field->args( 'sortable' )) ? '' : '';
- if( $field->args( 'object_type' ) == 'user' ){
- $guid = get_edit_user_link($val);
- $user = get_userdata($val);
- $title = $user->display_name;
- }
- else{
- $guid = get_edit_post_link($val);
- $title = get_the_title($val);
+ if ( isset( $value ) && ! empty( $value ) ) {
+ if ( ! is_array( $value ) ) {
+ $value = array( $value );
+ }
+ foreach ( $value as $val ) {
+ $handle = ( $field->args( 'sortable' ) ) ? '' : '';
+ if ( 'user' === $field->args( 'object_type' ) ) {
+ $guid = get_edit_user_link( $val );
+ $user = get_userdata( $val );
+ $title = $user->display_name;
+ } else {
+ $guid = get_edit_post_link( $val );
+ $title = get_the_title( $val );
}
- echo '- '.$handle.''.$title.'
';
+ echo '- ' . $handle . '' . $title . '
';
}
}
- echo '
';
+ echo '';
$field_value = '';
- }
- else{
- if(is_array($value)){ $value = $value[0]; }
- if( $field->args( 'object_type' ) == 'user' ){
- $field_value = ($value ? get_userdata($value)->display_name : '');
+ } else {
+ if ( is_array( $value ) ) {
+ $value = $value[0];
}
- else{
- $field_value = ($value ? get_the_title($value) : '');
+ if ( 'user' === $field->args( 'object_type' ) ) {
+ $field_value = ( $value ? get_userdata( $value )->display_name : '' );
+ } else {
+ $field_value = ( $value ? get_the_title( $value ) : '' );
}
- echo $field_type->input( array(
- 'type' => 'hidden',
- 'name' => $field_name . '_results',
- 'value' => $value,
- 'desc' => false
- ) );
+ echo $field_type->input(
+ array(
+ 'type' => 'hidden',
+ 'name' => $field_name . '_results',
+ 'value' => $value,
+ 'desc' => false,
+ )
+ );
}
- echo $field_type->input( array(
- 'type' => 'text',
- 'name' => $field_name,
- 'id' => $field_name,
- 'class' => 'cmb-post-search-ajax',
- 'value' => $field_value,
- 'desc' => false,
- 'data-limit' => $field->args( 'limit' ) ? $field->args( 'limit' ) : '1',
- 'data-sortable' => $field->args( 'sortable' ) ? $field->args( 'sortable' ) : '0',
- 'data-object' => $field->args( 'object_type' ) ? $field->args( 'object_type' ) : 'post',
- 'data-queryargs'=> $field->args( 'query_args' ) ? htmlspecialchars( json_encode( $field->args( 'query_args' ) ), ENT_QUOTES, 'UTF-8' ) : ''
- ) );
-
- echo '';
+ echo $field_type->input(
+ array(
+ 'type' => 'text',
+ 'name' => $field_name,
+ 'id' => $field_name,
+ 'class' => 'cmb-post-search-ajax',
+ 'value' => $field_value,
+ 'desc' => false,
+ 'data-limit' => $field->args( 'limit' ) ? $field->args( 'limit' ) : '1',
+ 'data-sortable' => $field->args( 'sortable' ) ? $field->args( 'sortable' ) : '0',
+ 'data-object' => $field->args( 'object_type' ) ? $field->args( 'object_type' ) : 'post',
+ 'data-queryargs' => $field->args( 'query_args' ) ? htmlspecialchars( json_encode( $field->args( 'query_args' ) ), ENT_QUOTES, 'UTF-8' ) : '',
+ )
+ );
+
+ echo '';
$field_type->_desc( true, true );
@@ -104,17 +109,16 @@ public function render( $field, $value, $object_id, $object_type, $field_type )
*/
public function sanitize( $override_value, $value, $object_id, $field_args ) {
$fid = $field_args['id'];
- if( !empty( $field_args['render_row_cb'][0]->data_to_save[$fid.'_results'] ) ){
- $value = $field_args['render_row_cb'][0]->data_to_save[$fid.'_results'];
- }
- else{
+ if ( ! empty( $field_args['render_row_cb'][0]->data_to_save[ $fid . '_results' ] ) ) {
+ $value = $field_args['render_row_cb'][0]->data_to_save[ $fid . '_results' ];
+ } else {
$value = false;
}
return $value;
}
/**
- * Defines the url which is used to load local resources. Based on, and uses,
+ * Defines the url which is used to load local resources. Based on, and uses,
* the CMB2_Utils class from the CMB2 library.
*/
public static function url( $path = '' ) {
@@ -129,7 +133,7 @@ public static function url( $path = '' ) {
/**
* Use CMB2_Utils to gather the url from cmb2_fpsa_dir
- */
+ */
$cmb2_fpsa_url = CMB2_Utils::get_url_from_dir( $cmb2_fpsa_dir );
/**
@@ -145,12 +149,16 @@ public static function url( $path = '' ) {
*/
public function setup_admin_scripts() {
- wp_register_script( 'jquery-autocomplete', self::url( 'js/jquery.autocomplete.min.js' ), array( 'jquery' ), self::VERSION );
+ wp_register_script( 'jquery-autocomplete', self::url( 'js/jquery.autocomplete.min.js' ), array( 'jquery' ), '1.4.10' );
wp_register_script( 'mag-post-search-ajax', self::url( 'js/mag-post-search-ajax.js' ), array( 'jquery', 'jquery-autocomplete', 'jquery-ui-sortable' ), self::VERSION );
- wp_localize_script( 'mag-post-search-ajax', 'psa', array(
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
- 'nonce' => wp_create_nonce( 'mag_cmb_post_search_ajax_get_results' )
- ) );
+ wp_localize_script(
+ 'mag-post-search-ajax',
+ 'psa',
+ array(
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
+ 'nonce' => wp_create_nonce( 'mag_cmb_post_search_ajax_get_results' ),
+ )
+ );
wp_enqueue_script( 'mag-post-search-ajax' );
wp_enqueue_style( 'mag-post-search-ajax', self::url( 'css/mag-post-search-ajax.css' ), array(), self::VERSION );
@@ -163,45 +171,51 @@ public function cmb_post_search_ajax_get_results() {
$nonce = $_POST['psacheck'];
if ( ! wp_verify_nonce( $nonce, 'mag_cmb_post_search_ajax_get_results' ) ) {
die( json_encode( array( 'error' => __( 'Error : Unauthorized action' ) ) ) );
- }
- else {
- $args = json_decode(stripslashes(htmlspecialchars_decode($_POST['query_args'])), true);
- $args['s'] = $_POST['query'];
- $datas = array();
- if( $_POST['object'] == 'user' ){
- $args['search'] = '*'.esc_attr($_POST['query']).'*';
- $users = new WP_User_Query( $args );
- $results = $users->get_results();
- if (!empty($results)) {
- foreach( $results as $result ){
- $user_info = get_userdata($result->ID);
+ } else {
+ $args = json_decode( stripslashes( htmlspecialchars_decode( $_POST['query_args'] ) ), true );
+ $args['s'] = $_POST['query'];
+ $datas = array();
+ if ( 'user' === $_POST['object'] ) {
+ $args['search'] = '*' . esc_attr( $_POST['query'] ) . '*';
+ $users = new WP_User_Query( $args );
+ $results = $users->get_results();
+ if ( ! empty( $results ) ) {
+ foreach ( $results as $result ) {
+ $user_info = get_userdata( $result->ID );
// Define filter "mag_cmb_post_search_ajax_result" to allow customize ajax results.
- $datas[] = apply_filters( 'mag_cmb_post_search_ajax_result', array(
- 'value' => $user_info->display_name,
- 'data' => $result->ID,
- 'guid' => get_edit_user_link($result->ID)
- ) );
+ $datas[] = apply_filters(
+ 'mag_cmb_post_search_ajax_result',
+ array(
+ 'value' => $user_info->display_name,
+ 'data' => $result->ID,
+ 'guid' => get_edit_user_link( $result->ID ),
+ )
+ );
}
}
- }else{
- $results = new WP_Query( $args );
+ } else {
+ $results = new WP_Query( $args );
if ( $results->have_posts() ) :
- while ( $results->have_posts() ) : $results->the_post();
+ while ( $results->have_posts() ) :
+ $results->the_post();
// Define filter "mag_cmb_post_search_ajax_result" to allow customize ajax results.
- $datas[] = apply_filters( 'mag_cmb_post_search_ajax_result', array(
- 'value' => get_the_title(),
- 'data' => get_the_ID(),
- 'guid' => get_edit_post_link()
- ) );
+ $datas[] = apply_filters(
+ 'mag_cmb_post_search_ajax_result',
+ array(
+ 'value' => get_the_title(),
+ 'data' => get_the_ID(),
+ 'guid' => get_edit_post_link(),
+ )
+ );
endwhile;
- endif;
- }
+ endif;
+ }
wp_reset_postdata();
- die( json_encode( $datas ) );
+ die( json_encode( $datas ) );
}
}
}
-
+
}
$mag_cmb2_field_post_search_ajax = new MAG_CMB2_Field_Post_Search_Ajax();
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..12cd4c3
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,19 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "5d5b5762022d834e4cb8b6b249e56bbb",
+ "packages": [],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": {
+ "php": ">5.2.4"
+ },
+ "platform-dev": []
+}
diff --git a/example-field-setup.php b/example-field-setup.php
index 765d149..750b1fd 100644
--- a/example-field-setup.php
+++ b/example-field-setup.php
@@ -9,73 +9,82 @@
* @return array
*/
function cmb2_post_search_ajax_metaboxes_example() {
-
- $example_meta = new_cmb2_box( array(
- 'id' => 'cmb2_post_search_ajax_field',
- 'title' => __( 'Related Posts', 'cmb2' ),
- 'object_types' => array( 'post' ), // Post type
- 'context' => 'normal',
- 'priority' => 'high',
- 'show_names' => true, // Show field names on the left
- ) );
-
- $example_meta->add_field( array(
- 'name' => __( 'Example Multiple', 'cmb2' ),
- 'id' => 'cmb2_post_search_ajax_demo_multiple',
- 'type' => 'post_search_ajax',
- 'desc' => __( '(Start typing post title)', 'cmb2' ),
- // Optional :
- 'limit' => 10, // Limit selection to X items only (default 1)
- 'sortable' => true, // Allow selected items to be sortable (default false)
- 'query_args' => array(
- 'post_type' => array( 'post' ),
- 'post_status' => array( 'publish' ),
- 'posts_per_page' => -1
+ $example_meta = new_cmb2_box(
+ array(
+ 'id' => 'cmb2_post_search_ajax_field',
+ 'title' => __( 'Related Posts', 'cmb2' ),
+ 'object_types' => array( 'post' ), // Post type
+ 'context' => 'normal',
+ 'priority' => 'high',
+ 'show_names' => true, // Show field names on the left
)
- ) );
-
- $example_meta->add_field( array(
- 'name' => __( 'Example Single', 'cmb2' ),
- 'id' => 'cmb2_post_search_ajax_demo_single',
- 'type' => 'post_search_ajax',
- 'desc' => __( '(Start typing post title)', 'cmb2' ),
- // Optional :
- 'limit' => 1, // Limit selection to X items only (default 1)
- 'sortable' => false, // Allow selected items to be sortable (default false)
- 'query_args' => array(
- 'post_type' => array( 'post' ),
- 'post_status' => array( 'publish' ),
- 'posts_per_page' => -1
+ );
+
+ $example_meta->add_field(
+ array(
+ 'name' => __( 'Example Multiple', 'cmb2' ),
+ 'id' => 'cmb2_post_search_ajax_demo_multiple',
+ 'type' => 'post_search_ajax',
+ 'desc' => __( '(Start typing post title)', 'cmb2' ),
+ // Optional :
+ 'limit' => 10, // Limit selection to X items only (default 1)
+ 'sortable' => true, // Allow selected items to be sortable (default false)
+ 'query_args' => array(
+ 'post_type' => array( 'post' ),
+ 'post_status' => array( 'publish' ),
+ 'posts_per_page' => -1,
+ ),
+ )
+ );
+
+ $example_meta->add_field(
+ array(
+ 'name' => __( 'Example Single', 'cmb2' ),
+ 'id' => 'cmb2_post_search_ajax_demo_single',
+ 'type' => 'post_search_ajax',
+ 'desc' => __( '(Start typing post title)', 'cmb2' ),
+ // Optional :
+ 'limit' => 1, // Limit selection to X items only (default 1)
+ 'sortable' => false, // Allow selected items to be sortable (default false)
+ 'query_args' => array(
+ 'post_type' => array( 'post' ),
+ 'post_status' => array( 'publish' ),
+ 'posts_per_page' => -1,
+ ),
)
- ) );
+ );
- $example_meta->add_field( array(
- 'name' => __( 'Test user multiple', 'cmb2' ),
- 'id' => 'cmb2_post_search_ajax_demo_user_multiple',
- 'type' => 'post_search_ajax',
- 'desc' => __( '(Start typing post title)', 'cmb2' ),
- // Optional :
- 'limit' => 10, // Limit selection to X items only (default 1)
- 'sortable' => true, // Allow selected items to be sortable (default false)
- 'object_type' => 'user', // Define queried object type (Available : post, user, term - Default : post)
- 'query_args' => array(
- 'blog_id' => '1',
+ $example_meta->add_field(
+ array(
+ 'name' => __( 'Test user multiple', 'cmb2' ),
+ 'id' => 'cmb2_post_search_ajax_demo_user_multiple',
+ 'type' => 'post_search_ajax',
+ 'desc' => __( '(Start typing post title)', 'cmb2' ),
+ // Optional :
+ 'limit' => 10, // Limit selection to X items only (default 1)
+ 'sortable' => true, // Allow selected items to be sortable (default false)
+ 'object_type' => 'user', // Define queried object type (Available : post, user, term - Default : post)
+ 'query_args' => array(
+ 'blog_id' => '1',
+ ),
)
- ) );
+ );
- $example_meta->add_field( array(
- 'name' => __( 'Test user single', 'cmb2' ),
- 'id' => 'cmb2_post_search_ajax_demo_user_single',
- 'type' => 'post_search_ajax',
- 'desc' => __( '(Start typing post title)', 'cmb2' ),
- // Optional :
- 'limit' => 1, // Limit selection to X items only (default 1)
- 'sortable' => false, // Allow selected items to be sortable (default false)
- 'object_type' => 'user', // Define queried object type (Available : post, user, term - Default : post)
- 'query_args' => array(
- 'role' => 'Administrator'
+ $example_meta->add_field(
+ array(
+ 'name' => __( 'Test user single', 'cmb2' ),
+ 'id' => 'cmb2_post_search_ajax_demo_user_single',
+ 'type' => 'post_search_ajax',
+ 'desc' => __( '(Start typing post title)', 'cmb2' ),
+ // Optional :
+ 'limit' => 1, // Limit selection to X items only (default 1)
+ 'sortable' => false, // Allow selected items to be sortable (default false)
+ 'object_type' => 'user', // Define queried object type (Available : post, user, term - Default : post)
+ 'query_args' => array(
+ 'role' => 'Administrator',
+ ),
)
- ) );
-
+ );
+
}
add_action( 'cmb2_init', 'cmb2_post_search_ajax_metaboxes_example' );
diff --git a/js/jquery.autocomplete.min.js b/js/jquery.autocomplete.min.js
index 4536430..b0d55e3 100755
--- a/js/jquery.autocomplete.min.js
+++ b/js/jquery.autocomplete.min.js
@@ -1,8 +1,8 @@
/**
-* Ajax Autocomplete for jQuery, version 1.2.27
-* (c) 2014 Tomas Kirda
+* Ajax Autocomplete for jQuery, version 1.4.10
+* (c) 2017 Tomas Kirda
*
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
*/
-!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports&&"function"==typeof require?require("jquery"):jQuery)}(function(a){"use strict";function b(c,d){var e=a.noop,f=this,g={ajaxSettings:{},autoSelectFirst:!1,appendTo:document.body,serviceUrl:null,lookup:null,onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},formatResult:b.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,onSearchStart:e,onSearchComplete:e,onSearchError:e,preserveInput:!1,containerClass:"autocomplete-suggestions",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:function(a,b,c){return-1!==a.value.toLowerCase().indexOf(c)},paramName:"query",transformResult:function(b){return"string"==typeof b?a.parseJSON(b):b},showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1};f.element=c,f.el=a(c),f.suggestions=[],f.badQueries=[],f.selectedIndex=-1,f.currentValue=f.element.value,f.intervalId=0,f.cachedResponse={},f.onChangeInterval=null,f.onChange=null,f.isLocal=!1,f.suggestionsContainer=null,f.noSuggestionsContainer=null,f.options=a.extend({},g,d),f.classes={selected:"autocomplete-selected",suggestion:"autocomplete-suggestion"},f.hint=null,f.hintValue="",f.selection=null,f.initialize(),f.setOptions(d)}var c=function(){return{escapeRegExChars:function(a){return a.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},createNode:function(a){var b=document.createElement("div");return b.className=a,b.style.position="absolute",b.style.display="none",b}}}(),d={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40};b.utils=c,a.Autocomplete=b,b.formatResult=function(a,b){if(!b)return a.value;var d="("+c.escapeRegExChars(b)+")";return a.value.replace(new RegExp(d,"gi"),"$1").replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/<(\/?strong)>/g,"<$1>")},b.prototype={killerFn:null,initialize:function(){var c,d=this,e="."+d.classes.suggestion,f=d.classes.selected,g=d.options;d.element.setAttribute("autocomplete","off"),d.killerFn=function(b){a(b.target).closest("."+d.options.containerClass).length||(d.killSuggestions(),d.disableKillerFn())},d.noSuggestionsContainer=a('').html(this.options.noSuggestionNotice).get(0),d.suggestionsContainer=b.utils.createNode(g.containerClass),c=a(d.suggestionsContainer),c.appendTo(g.appendTo),"auto"!==g.width&&c.css("width",g.width),c.on("mouseover.autocomplete",e,function(){d.activate(a(this).data("index"))}),c.on("mouseout.autocomplete",function(){d.selectedIndex=-1,c.children("."+f).removeClass(f)}),c.on("click.autocomplete",e,function(){return d.select(a(this).data("index")),!1}),d.fixPositionCapture=function(){d.visible&&d.fixPosition()},a(window).on("resize.autocomplete",d.fixPositionCapture),d.el.on("keydown.autocomplete",function(a){d.onKeyPress(a)}),d.el.on("keyup.autocomplete",function(a){d.onKeyUp(a)}),d.el.on("blur.autocomplete",function(){d.onBlur()}),d.el.on("focus.autocomplete",function(){d.onFocus()}),d.el.on("change.autocomplete",function(a){d.onKeyUp(a)}),d.el.on("input.autocomplete",function(a){d.onKeyUp(a)})},onFocus:function(){var a=this;a.fixPosition(),a.el.val().length>=a.options.minChars&&a.onValueChange()},onBlur:function(){this.enableKillerFn()},abortAjax:function(){var a=this;a.currentRequest&&(a.currentRequest.abort(),a.currentRequest=null)},setOptions:function(b){var c=this,d=c.options;a.extend(d,b),c.isLocal=a.isArray(d.lookup),c.isLocal&&(d.lookup=c.verifySuggestionsFormat(d.lookup)),d.orientation=c.validateOrientation(d.orientation,"bottom"),a(c.suggestionsContainer).css({"max-height":d.maxHeight+"px",width:d.width+"px","z-index":d.zIndex})},clearCache:function(){this.cachedResponse={},this.badQueries=[]},clear:function(){this.clearCache(),this.currentValue="",this.suggestions=[]},disable:function(){var a=this;a.disabled=!0,clearInterval(a.onChangeInterval),a.abortAjax()},enable:function(){this.disabled=!1},fixPosition:function(){var b=this,c=a(b.suggestionsContainer),d=c.parent().get(0);if(d===document.body||b.options.forceFixPosition){var e=b.options.orientation,f=c.outerHeight(),g=b.el.outerHeight(),h=b.el.offset(),i={top:h.top,left:h.left};if("auto"===e){var j=a(window).height(),k=a(window).scrollTop(),l=-k+h.top-f,m=k+j-(h.top+g+f);e=Math.max(l,m)===l?"top":"bottom"}if("top"===e?i.top+=-f:i.top+=g,d!==document.body){var n,o=c.css("opacity");b.visible||c.css("opacity",0).show(),n=c.offsetParent().offset(),i.top-=n.top,i.left-=n.left,b.visible||c.css("opacity",o).hide()}"auto"===b.options.width&&(i.width=b.el.outerWidth()+"px"),c.css(i)}},enableKillerFn:function(){var b=this;a(document).on("click.autocomplete",b.killerFn)},disableKillerFn:function(){var b=this;a(document).off("click.autocomplete",b.killerFn)},killSuggestions:function(){var a=this;a.stopKillSuggestions(),a.intervalId=window.setInterval(function(){a.visible&&(a.options.preserveInput||a.el.val(a.currentValue),a.hide()),a.stopKillSuggestions()},50)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var a,b=this,c=b.el.val().length,d=b.element.selectionStart;return"number"==typeof d?d===c:document.selection?(a=document.selection.createRange(),a.moveStart("character",-c),c===a.text.length):!0},onKeyPress:function(a){var b=this;if(!b.disabled&&!b.visible&&a.which===d.DOWN&&b.currentValue)return void b.suggest();if(!b.disabled&&b.visible){switch(a.which){case d.ESC:b.el.val(b.currentValue),b.hide();break;case d.RIGHT:if(b.hint&&b.options.onHint&&b.isCursorAtEnd()){b.selectHint();break}return;case d.TAB:if(b.hint&&b.options.onHint)return void b.selectHint();if(-1===b.selectedIndex)return void b.hide();if(b.select(b.selectedIndex),b.options.tabDisabled===!1)return;break;case d.RETURN:if(-1===b.selectedIndex)return void b.hide();b.select(b.selectedIndex);break;case d.UP:b.moveUp();break;case d.DOWN:b.moveDown();break;default:return}a.stopImmediatePropagation(),a.preventDefault()}},onKeyUp:function(a){var b=this;if(!b.disabled){switch(a.which){case d.UP:case d.DOWN:return}clearInterval(b.onChangeInterval),b.currentValue!==b.el.val()&&(b.findBestHint(),b.options.deferRequestBy>0?b.onChangeInterval=setInterval(function(){b.onValueChange()},b.options.deferRequestBy):b.onValueChange())}},onValueChange:function(){var b=this,c=b.options,d=b.el.val(),e=b.getQuery(d);return b.selection&&b.currentValue!==e&&(b.selection=null,(c.onInvalidateSelection||a.noop).call(b.element)),clearInterval(b.onChangeInterval),b.currentValue=d,b.selectedIndex=-1,c.triggerSelectOnValidInput&&b.isExactMatch(e)?void b.select(0):void(e.lengthh&&(c.suggestions=c.suggestions.slice(0,h)),c},getSuggestions:function(b){var c,d,e,f,g=this,h=g.options,i=h.serviceUrl;if(h.params[h.paramName]=b,d=h.ignoreParams?null:h.params,h.onSearchStart.call(g.element,h.params)!==!1){if(a.isFunction(h.lookup))return void h.lookup(b,function(a){g.suggestions=a.suggestions,g.suggest(),h.onSearchComplete.call(g.element,b,a.suggestions)});g.isLocal?c=g.getSuggestionsLocal(b):(a.isFunction(i)&&(i=i.call(g.element,b)),e=i+"?"+a.param(d||{}),c=g.cachedResponse[e]),c&&a.isArray(c.suggestions)?(g.suggestions=c.suggestions,g.suggest(),h.onSearchComplete.call(g.element,b,c.suggestions)):g.isBadQuery(b)?h.onSearchComplete.call(g.element,b,[]):(g.abortAjax(),f={url:i,data:d,type:h.type,dataType:h.dataType},a.extend(f,h.ajaxSettings),g.currentRequest=a.ajax(f).done(function(a){var c;g.currentRequest=null,c=h.transformResult(a,b),g.processResponse(c,b,e),h.onSearchComplete.call(g.element,b,c.suggestions)}).fail(function(a,c,d){h.onSearchError.call(g.element,b,a,c,d)}))}},isBadQuery:function(a){if(!this.options.preventBadQueries)return!1;for(var b=this.badQueries,c=b.length;c--;)if(0===a.indexOf(b[c]))return!0;return!1},hide:function(){var b=this,c=a(b.suggestionsContainer);a.isFunction(b.options.onHide)&&b.visible&&b.options.onHide.call(b.element,c),b.visible=!1,b.selectedIndex=-1,clearInterval(b.onChangeInterval),a(b.suggestionsContainer).hide(),b.signalHint(null)},suggest:function(){if(!this.suggestions.length)return void(this.options.showNoSuggestionNotice?this.noSuggestions():this.hide());var b,c=this,d=c.options,e=d.groupBy,f=d.formatResult,g=c.getQuery(c.currentValue),h=c.classes.suggestion,i=c.classes.selected,j=a(c.suggestionsContainer),k=a(c.noSuggestionsContainer),l=d.beforeRender,m="",n=function(a,c){var d=a.data[e];return b===d?"":(b=d,''+b+"
")};return d.triggerSelectOnValidInput&&c.isExactMatch(g)?void c.select(0):(a.each(c.suggestions,function(a,b){e&&(m+=n(b,g,a)),m+=''+f(b,g,a)+"
"}),this.adjustContainerWidth(),k.detach(),j.html(m),a.isFunction(l)&&l.call(c.element,j,c.suggestions),c.fixPosition(),j.show(),d.autoSelectFirst&&(c.selectedIndex=0,j.scrollTop(0),j.children("."+h).first().addClass(i)),c.visible=!0,void c.findBestHint())},noSuggestions:function(){var b=this,c=a(b.suggestionsContainer),d=a(b.noSuggestionsContainer);this.adjustContainerWidth(),d.detach(),c.empty(),c.append(d),b.fixPosition(),c.show(),b.visible=!0},adjustContainerWidth:function(){var b,c=this,d=c.options,e=a(c.suggestionsContainer);"auto"===d.width&&(b=c.el.outerWidth(),e.css("width",b>0?b:300))},findBestHint:function(){var b=this,c=b.el.val().toLowerCase(),d=null;c&&(a.each(b.suggestions,function(a,b){var e=0===b.value.toLowerCase().indexOf(c);return e&&(d=b),!e}),b.signalHint(d))},signalHint:function(b){var c="",d=this;b&&(c=d.currentValue+b.value.substr(d.currentValue.length)),d.hintValue!==c&&(d.hintValue=c,d.hint=b,(this.options.onHint||a.noop)(c))},verifySuggestionsFormat:function(b){return b.length&&"string"==typeof b[0]?a.map(b,function(a){return{value:a,data:null}}):b},validateOrientation:function(b,c){return b=a.trim(b||"").toLowerCase(),-1===a.inArray(b,["auto","bottom","top"])&&(b=c),b},processResponse:function(a,b,c){var d=this,e=d.options;a.suggestions=d.verifySuggestionsFormat(a.suggestions),e.noCache||(d.cachedResponse[c]=a,e.preventBadQueries&&!a.suggestions.length&&d.badQueries.push(b)),b===d.getQuery(d.currentValue)&&(d.suggestions=a.suggestions,d.suggest())},activate:function(b){var c,d=this,e=d.classes.selected,f=a(d.suggestionsContainer),g=f.find("."+d.classes.suggestion);return f.find("."+e).removeClass(e),d.selectedIndex=b,-1!==d.selectedIndex&&g.length>d.selectedIndex?(c=g.get(d.selectedIndex),a(c).addClass(e),c):null},selectHint:function(){var b=this,c=a.inArray(b.hint,b.suggestions);b.select(c)},select:function(a){var b=this;b.hide(),b.onSelect(a),b.disableKillerFn()},moveUp:function(){var b=this;if(-1!==b.selectedIndex)return 0===b.selectedIndex?(a(b.suggestionsContainer).children().first().removeClass(b.classes.selected),b.selectedIndex=-1,b.el.val(b.currentValue),void b.findBestHint()):void b.adjustScroll(b.selectedIndex-1)},moveDown:function(){var a=this;a.selectedIndex!==a.suggestions.length-1&&a.adjustScroll(a.selectedIndex+1)},adjustScroll:function(b){var c=this,d=c.activate(b);if(d){var e,f,g,h=a(d).outerHeight();e=d.offsetTop,f=a(c.suggestionsContainer).scrollTop(),g=f+c.options.maxHeight-h,f>e?a(c.suggestionsContainer).scrollTop(e):e>g&&a(c.suggestionsContainer).scrollTop(e-c.options.maxHeight+h),c.options.preserveInput||c.el.val(c.getValue(c.suggestions[b].value)),c.signalHint(null)}},onSelect:function(b){var c=this,d=c.options.onSelect,e=c.suggestions[b];c.currentValue=c.getValue(e.value),c.currentValue===c.el.val()||c.options.preserveInput||c.el.val(c.currentValue),c.signalHint(null),c.suggestions=[],c.selection=e,a.isFunction(d)&&d.call(c.element,e)},getValue:function(a){var b,c,d=this,e=d.options.delimiter;return e?(b=d.currentValue,c=b.split(e),1===c.length?a:b.substr(0,b.length-c[c.length-1].length)+a):a},dispose:function(){var b=this;b.el.off(".autocomplete").removeData("autocomplete"),b.disableKillerFn(),a(window).off("resize.autocomplete",b.fixPositionCapture),a(b.suggestionsContainer).remove()}},a.fn.autocomplete=a.fn.devbridgeAutocomplete=function(c,d){var e="autocomplete";return arguments.length?this.each(function(){var f=a(this),g=f.data(e);"string"==typeof c?g&&"function"==typeof g[c]&&g[c](d):(g&&g.dispose&&g.dispose(),g=new b(this,c),f.data(e,g))}):this.first().data(e)}});
\ No newline at end of file
+!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports&&"function"==typeof require?require("jquery"):jQuery)}(function(a){"use strict";function b(c,d){var e=this;e.element=c,e.el=a(c),e.suggestions=[],e.badQueries=[],e.selectedIndex=-1,e.currentValue=e.element.value,e.timeoutId=null,e.cachedResponse={},e.onChangeTimeout=null,e.onChange=null,e.isLocal=!1,e.suggestionsContainer=null,e.noSuggestionsContainer=null,e.options=a.extend(!0,{},b.defaults,d),e.classes={selected:"autocomplete-selected",suggestion:"autocomplete-suggestion"},e.hint=null,e.hintValue="",e.selection=null,e.initialize(),e.setOptions(d)}function c(a,b,c){return a.value.toLowerCase().indexOf(c)!==-1}function d(b){return"string"==typeof b?a.parseJSON(b):b}function e(a,b){if(!b)return a.value;var c="("+g.escapeRegExChars(b)+")";return a.value.replace(new RegExp(c,"gi"),"$1").replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/<(\/?strong)>/g,"<$1>")}function f(a,b){return''+b+"
"}var g=function(){return{escapeRegExChars:function(a){return a.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},createNode:function(a){var b=document.createElement("div");return b.className=a,b.style.position="absolute",b.style.display="none",b}}}(),h={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40},i=a.noop;b.utils=g,a.Autocomplete=b,b.defaults={ajaxSettings:{},autoSelectFirst:!1,appendTo:"body",serviceUrl:null,lookup:null,onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},formatResult:e,formatGroup:f,delimiter:null,zIndex:9999,type:"GET",noCache:!1,onSearchStart:i,onSearchComplete:i,onSearchError:i,preserveInput:!1,containerClass:"autocomplete-suggestions",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:c,paramName:"query",transformResult:d,showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1},b.prototype={initialize:function(){var c,d=this,e="."+d.classes.suggestion,f=d.classes.selected,g=d.options;d.element.setAttribute("autocomplete","off"),d.noSuggestionsContainer=a('').html(this.options.noSuggestionNotice).get(0),d.suggestionsContainer=b.utils.createNode(g.containerClass),c=a(d.suggestionsContainer),c.appendTo(g.appendTo||"body"),"auto"!==g.width&&c.css("width",g.width),c.on("mouseover.autocomplete",e,function(){d.activate(a(this).data("index"))}),c.on("mouseout.autocomplete",function(){d.selectedIndex=-1,c.children("."+f).removeClass(f)}),c.on("click.autocomplete",e,function(){d.select(a(this).data("index"))}),c.on("click.autocomplete",function(){clearTimeout(d.blurTimeoutId)}),d.fixPositionCapture=function(){d.visible&&d.fixPosition()},a(window).on("resize.autocomplete",d.fixPositionCapture),d.el.on("keydown.autocomplete",function(a){d.onKeyPress(a)}),d.el.on("keyup.autocomplete",function(a){d.onKeyUp(a)}),d.el.on("blur.autocomplete",function(){d.onBlur()}),d.el.on("focus.autocomplete",function(){d.onFocus()}),d.el.on("change.autocomplete",function(a){d.onKeyUp(a)}),d.el.on("input.autocomplete",function(a){d.onKeyUp(a)})},onFocus:function(){var a=this;a.fixPosition(),a.el.val().length>=a.options.minChars&&a.onValueChange()},onBlur:function(){var b=this,c=b.options,d=b.el.val(),e=b.getQuery(d);b.blurTimeoutId=setTimeout(function(){b.hide(),b.selection&&b.currentValue!==e&&(c.onInvalidateSelection||a.noop).call(b.element)},200)},abortAjax:function(){var a=this;a.currentRequest&&(a.currentRequest.abort(),a.currentRequest=null)},setOptions:function(b){var c=this,d=a.extend({},c.options,b);c.isLocal=Array.isArray(d.lookup),c.isLocal&&(d.lookup=c.verifySuggestionsFormat(d.lookup)),d.orientation=c.validateOrientation(d.orientation,"bottom"),a(c.suggestionsContainer).css({"max-height":d.maxHeight+"px",width:d.width+"px","z-index":d.zIndex}),this.options=d},clearCache:function(){this.cachedResponse={},this.badQueries=[]},clear:function(){this.clearCache(),this.currentValue="",this.suggestions=[]},disable:function(){var a=this;a.disabled=!0,clearTimeout(a.onChangeTimeout),a.abortAjax()},enable:function(){this.disabled=!1},fixPosition:function(){var b=this,c=a(b.suggestionsContainer),d=c.parent().get(0);if(d===document.body||b.options.forceFixPosition){var e=b.options.orientation,f=c.outerHeight(),g=b.el.outerHeight(),h=b.el.offset(),i={top:h.top,left:h.left};if("auto"===e){var j=a(window).height(),k=a(window).scrollTop(),l=-k+h.top-f,m=k+j-(h.top+g+f);e=Math.max(l,m)===l?"top":"bottom"}if("top"===e?i.top+=-f:i.top+=g,d!==document.body){var n,o=c.css("opacity");b.visible||c.css("opacity",0).show(),n=c.offsetParent().offset(),i.top-=n.top,i.top+=d.scrollTop,i.left-=n.left,b.visible||c.css("opacity",o).hide()}"auto"===b.options.width&&(i.width=b.el.outerWidth()+"px"),c.css(i)}},isCursorAtEnd:function(){var a,b=this,c=b.el.val().length,d=b.element.selectionStart;return"number"==typeof d?d===c:!document.selection||(a=document.selection.createRange(),a.moveStart("character",-c),c===a.text.length)},onKeyPress:function(a){var b=this;if(!b.disabled&&!b.visible&&a.which===h.DOWN&&b.currentValue)return void b.suggest();if(!b.disabled&&b.visible){switch(a.which){case h.ESC:b.el.val(b.currentValue),b.hide();break;case h.RIGHT:if(b.hint&&b.options.onHint&&b.isCursorAtEnd()){b.selectHint();break}return;case h.TAB:if(b.hint&&b.options.onHint)return void b.selectHint();if(b.selectedIndex===-1)return void b.hide();if(b.select(b.selectedIndex),b.options.tabDisabled===!1)return;break;case h.RETURN:if(b.selectedIndex===-1)return void b.hide();b.select(b.selectedIndex);break;case h.UP:b.moveUp();break;case h.DOWN:b.moveDown();break;default:return}a.stopImmediatePropagation(),a.preventDefault()}},onKeyUp:function(a){var b=this;if(!b.disabled){switch(a.which){case h.UP:case h.DOWN:return}clearTimeout(b.onChangeTimeout),b.currentValue!==b.el.val()&&(b.findBestHint(),b.options.deferRequestBy>0?b.onChangeTimeout=setTimeout(function(){b.onValueChange()},b.options.deferRequestBy):b.onValueChange())}},onValueChange:function(){if(this.ignoreValueChange)return void(this.ignoreValueChange=!1);var b=this,c=b.options,d=b.el.val(),e=b.getQuery(d);return b.selection&&b.currentValue!==e&&(b.selection=null,(c.onInvalidateSelection||a.noop).call(b.element)),clearTimeout(b.onChangeTimeout),b.currentValue=d,b.selectedIndex=-1,c.triggerSelectOnValidInput&&b.isExactMatch(e)?void b.select(0):void(e.lengthh&&(c.suggestions=c.suggestions.slice(0,h)),c},getSuggestions:function(b){var c,d,e,f,g=this,h=g.options,i=h.serviceUrl;if(h.params[h.paramName]=b,h.onSearchStart.call(g.element,h.params)!==!1){if(d=h.ignoreParams?null:h.params,a.isFunction(h.lookup))return void h.lookup(b,function(a){g.suggestions=a.suggestions,g.suggest(),h.onSearchComplete.call(g.element,b,a.suggestions)});g.isLocal?c=g.getSuggestionsLocal(b):(a.isFunction(i)&&(i=i.call(g.element,b)),e=i+"?"+a.param(d||{}),c=g.cachedResponse[e]),c&&Array.isArray(c.suggestions)?(g.suggestions=c.suggestions,g.suggest(),h.onSearchComplete.call(g.element,b,c.suggestions)):g.isBadQuery(b)?h.onSearchComplete.call(g.element,b,[]):(g.abortAjax(),f={url:i,data:d,type:h.type,dataType:h.dataType},a.extend(f,h.ajaxSettings),g.currentRequest=a.ajax(f).done(function(a){var c;g.currentRequest=null,c=h.transformResult(a,b),g.processResponse(c,b,e),h.onSearchComplete.call(g.element,b,c.suggestions)}).fail(function(a,c,d){h.onSearchError.call(g.element,b,a,c,d)}))}},isBadQuery:function(a){if(!this.options.preventBadQueries)return!1;for(var b=this.badQueries,c=b.length;c--;)if(0===a.indexOf(b[c]))return!0;return!1},hide:function(){var b=this,c=a(b.suggestionsContainer);a.isFunction(b.options.onHide)&&b.visible&&b.options.onHide.call(b.element,c),b.visible=!1,b.selectedIndex=-1,clearTimeout(b.onChangeTimeout),a(b.suggestionsContainer).hide(),b.signalHint(null)},suggest:function(){if(!this.suggestions.length)return void(this.options.showNoSuggestionNotice?this.noSuggestions():this.hide());var b,c=this,d=c.options,e=d.groupBy,f=d.formatResult,g=c.getQuery(c.currentValue),h=c.classes.suggestion,i=c.classes.selected,j=a(c.suggestionsContainer),k=a(c.noSuggestionsContainer),l=d.beforeRender,m="",n=function(a,c){var f=a.data[e];return b===f?"":(b=f,d.formatGroup(a,b))};return d.triggerSelectOnValidInput&&c.isExactMatch(g)?void c.select(0):(a.each(c.suggestions,function(a,b){e&&(m+=n(b,g,a)),m+=''+f(b,g,a)+"
"}),this.adjustContainerWidth(),k.detach(),j.html(m),a.isFunction(l)&&l.call(c.element,j,c.suggestions),c.fixPosition(),j.show(),d.autoSelectFirst&&(c.selectedIndex=0,j.scrollTop(0),j.children("."+h).first().addClass(i)),c.visible=!0,void c.findBestHint())},noSuggestions:function(){var b=this,c=b.options.beforeRender,d=a(b.suggestionsContainer),e=a(b.noSuggestionsContainer);this.adjustContainerWidth(),e.detach(),d.empty(),d.append(e),a.isFunction(c)&&c.call(b.element,d,b.suggestions),b.fixPosition(),d.show(),b.visible=!0},adjustContainerWidth:function(){var b,c=this,d=c.options,e=a(c.suggestionsContainer);"auto"===d.width?(b=c.el.outerWidth(),e.css("width",b>0?b:300)):"flex"===d.width&&e.css("width","")},findBestHint:function(){var b=this,c=b.el.val().toLowerCase(),d=null;c&&(a.each(b.suggestions,function(a,b){var e=0===b.value.toLowerCase().indexOf(c);return e&&(d=b),!e}),b.signalHint(d))},signalHint:function(b){var c="",d=this;b&&(c=d.currentValue+b.value.substr(d.currentValue.length)),d.hintValue!==c&&(d.hintValue=c,d.hint=b,(this.options.onHint||a.noop)(c))},verifySuggestionsFormat:function(b){return b.length&&"string"==typeof b[0]?a.map(b,function(a){return{value:a,data:null}}):b},validateOrientation:function(b,c){return b=a.trim(b||"").toLowerCase(),a.inArray(b,["auto","bottom","top"])===-1&&(b=c),b},processResponse:function(a,b,c){var d=this,e=d.options;a.suggestions=d.verifySuggestionsFormat(a.suggestions),e.noCache||(d.cachedResponse[c]=a,e.preventBadQueries&&!a.suggestions.length&&d.badQueries.push(b)),b===d.getQuery(d.currentValue)&&(d.suggestions=a.suggestions,d.suggest())},activate:function(b){var c,d=this,e=d.classes.selected,f=a(d.suggestionsContainer),g=f.find("."+d.classes.suggestion);return f.find("."+e).removeClass(e),d.selectedIndex=b,d.selectedIndex!==-1&&g.length>d.selectedIndex?(c=g.get(d.selectedIndex),a(c).addClass(e),c):null},selectHint:function(){var b=this,c=a.inArray(b.hint,b.suggestions);b.select(c)},select:function(a){var b=this;b.hide(),b.onSelect(a)},moveUp:function(){var b=this;if(b.selectedIndex!==-1)return 0===b.selectedIndex?(a(b.suggestionsContainer).children("."+b.classes.suggestion).first().removeClass(b.classes.selected),b.selectedIndex=-1,b.ignoreValueChange=!1,b.el.val(b.currentValue),void b.findBestHint()):void b.adjustScroll(b.selectedIndex-1)},moveDown:function(){var a=this;a.selectedIndex!==a.suggestions.length-1&&a.adjustScroll(a.selectedIndex+1)},adjustScroll:function(b){var c=this,d=c.activate(b);if(d){var e,f,g,h=a(d).outerHeight();e=d.offsetTop,f=a(c.suggestionsContainer).scrollTop(),g=f+c.options.maxHeight-h,eg&&a(c.suggestionsContainer).scrollTop(e-c.options.maxHeight+h),c.options.preserveInput||(c.ignoreValueChange=!0,c.el.val(c.getValue(c.suggestions[b].value))),c.signalHint(null)}},onSelect:function(b){var c=this,d=c.options.onSelect,e=c.suggestions[b];c.currentValue=c.getValue(e.value),c.currentValue===c.el.val()||c.options.preserveInput||c.el.val(c.currentValue),c.signalHint(null),c.suggestions=[],c.selection=e,a.isFunction(d)&&d.call(c.element,e)},getValue:function(a){var b,c,d=this,e=d.options.delimiter;return e?(b=d.currentValue,c=b.split(e),1===c.length?a:b.substr(0,b.length-c[c.length-1].length)+a):a},dispose:function(){var b=this;b.el.off(".autocomplete").removeData("autocomplete"),a(window).off("resize.autocomplete",b.fixPositionCapture),a(b.suggestionsContainer).remove()}},a.fn.devbridgeAutocomplete=function(c,d){var e="autocomplete";return arguments.length?this.each(function(){var f=a(this),g=f.data(e);"string"==typeof c?g&&"function"==typeof g[c]&&g[c](d):(g&&g.dispose&&g.dispose(),g=new b(this,c),f.data(e,g))}):this.first().data(e)},a.fn.autocomplete||(a.fn.autocomplete=a.fn.devbridgeAutocomplete)});
\ No newline at end of file
diff --git a/js/mag-post-search-ajax.js b/js/mag-post-search-ajax.js
index 540cf78..5ecf09c 100644
--- a/js/mag-post-search-ajax.js
+++ b/js/mag-post-search-ajax.js
@@ -49,7 +49,7 @@
var lid = $(this).attr('id') + '_results';
var limit = $(this).attr('data-limit');
var sortable = $(this).attr('data-sortable');
- if( limit > 1 ){
+ if( 1 !== limit ){
var handle = (sortable == 1) ? '' : '';
$('#'+lid).append(''+handle+''+suggestion.value+'');
$(this).val('');