Changeset 2780
- Timestamp:
- 03/22/2016 07:37:41 PM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/autocomplete.php
r2359 r2780 66 66 check_ajax_referer( 'autocomplete_nonce', 'nonce' ); 67 67 68 $parser_post_types = DevHub\get_parsed_post_types(); 69 $defaults = array( 70 's' => '', 71 'post_type' => $parser_post_types, 72 'posts' => array(), 73 ); 74 68 75 if ( !( isset( $_POST['data'] ) && $_POST['data'] ) ) { 69 wp_send_json_error( );76 wp_send_json_error( $defaults ); 70 77 } 71 78 72 79 // Parse the search form fields. 73 80 wp_parse_str( $_POST['data'], $form_data ); 81 $form_data = array_merge( $defaults, $form_data ); 74 82 75 if ( !isset( $form_data['post_type'] ) || !isset( $form_data['s'] ) ) { 76 wp_send_json_error(); 83 // No search query. 84 if ( empty( $form_data['s'] ) ) { 85 wp_send_json_error( $defaults ); 77 86 } 78 87 79 $post_types = array(); 80 $parser_post_types = DevHub\get_parsed_post_types(); 81 82 foreach ( $form_data['post_type'] as $post_type ) { 83 if ( in_array( $post_type , $parser_post_types ) ) { 84 $post_types[] = $post_type; 88 foreach ( $form_data['post_type'] as $key => $post_type ) { 89 if ( !in_array( $post_type , $parser_post_types ) ) { 90 unset( $form_data['post_type'][ $key ] ); 85 91 } 86 92 } 93 94 $post_types = !empty( $form_data['post_type'] ) ? $form_data['post_type'] : $parser_post_types; 87 95 88 96 $args = array( … … 97 105 $search = get_posts( $args ); 98 106 99 $form_data['posts'] = array();100 107 if ( !empty( $search ) ) { 101 $form_data['posts'] = wp_list_pluck( $search, 'post_title' ); 108 $titles = wp_list_pluck( $search, 'post_title' ); 109 $form_data['posts'] = array_values( array_unique( $titles ) ); 102 110 } 103 111 … … 105 113 } 106 114 107 108 115 } 109 116 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/autocomplete.js
r2359 r2780 19 19 var awesome = new Awesomplete( searchfield.get( 0 ), { 20 20 maxItems: 9999, 21 minChars: 3, 21 22 filter: function( text, input ) { 22 23 // Filter autocomplete matches … … 57 58 58 59 return false; 59 } 60 }, 60 61 } ); 61 62 … … 66 67 // if there are more than 2 characters 67 68 // and it's not already processing an Ajax request 68 if ( !processing && $( this ).val(). length > 2 ) {69 if ( !processing && $( this ).val().trim().length > 2 ) { 69 70 search = $( this ).val(); 70 71 autocomplete_update(); … … 93 94 } 94 95 95 if ( typeof response.data .posts=== 'undefined' ) {96 if ( typeof response.data === 'undefined' ) { 96 97 return false; 97 98 } -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/awesomplete.min.js
r2359 r2780 3 3 "off");this.input.setAttribute("aria-autocomplete","list");b=b||{};m.call(this,{minChars:2,maxItems:10,autoFirst:!1,filter:f.FILTER_CONTAINS,sort:f.SORT_BYLENGTH,item:function(a,b){var c=""===b?a:a.replace(RegExp(d.regExpEscape(b.trim()),"gi"),"<mark>$&</mark>");return d.create("li",{innerHTML:c,"aria-selected":"false"})},replace:function(a){this.input.value=a}},b);this.index=-1;this.container=d.create("div",{className:"awesomplete",around:a});this.ul=d.create("ul",{hidden:"hidden",inside:this.container}); 4 4 this.status=d.create("span",{className:"visually-hidden",role:"status","aria-live":"assertive","aria-relevant":"additions",inside:this.container});d.bind(this.input,{input:this.evaluate.bind(this),blur:this.close.bind(this),keydown:function(a){var b=a.keyCode;if(c.opened)if(13===b&&c.selected)a.preventDefault(),c.select();else if(27===b)c.close();else if(38===b||40===b)a.preventDefault(),c[38===b?"previous":"next"]()}});d.bind(this.input.form,{submit:this.close.bind(this)});d.bind(this.ul,{mousedown:function(a){var b= 5 a.target;if(b!==this){for(;b&&!/li/i.test(b.nodeName);)b=b.parentNode;b&&0===a.button&& c.select(b,a)}}});this.input.hasAttribute("list")?(this.list="#"+this.input.getAttribute("list"),this.input.removeAttribute("list")):this.list=this.input.getAttribute("data-list")||b.list||[];f.all.push(this)};f.prototype={set list(a){Array.isArray(a)?this._list=a:"string"===typeof a&&-1<a.indexOf(",")?this._list=a.split(/\s*,\s*/):(a=d(a))&&a.children&&(this._list=k.apply(a.children).map(function(a){return a.textContent.trim()}));5 a.target;if(b!==this){for(;b&&!/li/i.test(b.nodeName);)b=b.parentNode;b&&0===a.button&&(a.preventDefault(),c.select(b,a))}}});this.input.hasAttribute("list")?(this.list="#"+this.input.getAttribute("list"),this.input.removeAttribute("list")):this.list=this.input.getAttribute("data-list")||b.list||[];f.all.push(this)};f.prototype={set list(a){Array.isArray(a)?this._list=a:"string"===typeof a&&-1<a.indexOf(",")?this._list=a.split(/\s*,\s*/):(a=d(a))&&a.children&&(this._list=k.apply(a.children).map(function(a){return a.textContent.trim()})); 6 6 document.activeElement===this.input&&this.evaluate()},get selected(){return-1<this.index},get opened(){return this.ul&&null==this.ul.getAttribute("hidden")},close:function(){this.ul.setAttribute("hidden","");this.index=-1;d.fire(this.input,"awesomplete-close")},open:function(){this.ul.removeAttribute("hidden");this.autoFirst&&-1===this.index&&this["goto"](0);d.fire(this.input,"awesomplete-open")},next:function(){this["goto"](this.index<this.ul.children.length-1?this.index+1:-1)},previous:function(){var a= 7 7 this.ul.children.length;this["goto"](this.selected?this.index-1:a-1)},"goto":function(a){var b=this.ul.children;this.selected&&b[this.index].setAttribute("aria-selected","false");this.index=a;-1<a&&0<b.length&&(b[a].setAttribute("aria-selected","true"),this.status.textContent=b[a].textContent);d.fire(this.input,"awesomplete-highlight")},select:function(a,b){if(a=a||this.ul.children[this.index]){var c;d.fire(this.input,"awesomplete-select",{text:a.textContent,preventDefault:function(){c=!0},originalEvent:b});
Note: See TracChangeset
for help on using the changeset viewer.