Ticket #542: 542.3.patch
File 542.3.patch, 7.9 KB (added by , 8 years ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/autocomplete.php
65 65 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 } 87 93 94 $post_types = !empty( $form_data['post_type'] ) ? $form_data['post_type'] : $parser_post_types; 95 88 96 $args = array( 89 97 'posts_per_page' => -1, 90 98 'post_type' => $post_types, … … 96 104 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 104 112 wp_send_json_success ( $form_data ); 105 113 } 106 114 107 108 115 } 109 116 110 $autocomplete = new DevHub_Search_Form_Autocomplete(); 111 No newline at end of file 117 $autocomplete = new DevHub_Search_Form_Autocomplete(); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/autocomplete.js
18 18 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 23 24 … … 56 57 } 57 58 58 59 return false; 59 } 60 }, 60 61 } ); 61 62 62 63 // On input event for the search field. … … 65 66 // Update the autocomlete list: 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(); 71 72 } … … 92 93 return false; 93 94 } 94 95 95 if ( typeof response.data .posts=== 'undefined' ) {96 if ( typeof response.data === 'undefined' ) { 96 97 return false; 97 98 } 98 99 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/awesomplete.min.js
2 2 (function(){function m(a,b){for(var c in a){var g=a[c],e=this.input.getAttribute("data-"+c.toLowerCase());this[c]="number"===typeof g?parseInt(e):!1===g?null!==e:g instanceof Function?null:e;this[c]||0===this[c]||(this[c]=c in b?b[c]:g)}}function d(a,b){return"string"===typeof a?(b||document).querySelector(a):a||null}function h(a,b){return k.call((b||document).querySelectorAll(a))}function l(){h("input.awesomplete").forEach(function(a){new f(a)})}var f=function(a,b){var c=this;this.input=d(a);this.input.setAttribute("autocomplete", 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}); 8 8 c||(this.replace(a.textContent),this.close(),d.fire(this.input,"awesomplete-selectcomplete"))}},evaluate:function(){var a=this,b=this.input.value;b.length>=this.minChars&&0<this._list.length?(this.index=-1,this.ul.innerHTML="",this._list.filter(function(c){return a.filter(c,b)}).sort(this.sort).every(function(c,d){a.ul.appendChild(a.item(c,b));return d<a.maxItems-1}),0===this.ul.children.length?this.close():this.open()):this.close()}};f.all=[];f.FILTER_CONTAINS=function(a,b){return RegExp(d.regExpEscape(b.trim()),