WordPress/wp-admin/js/tags-suggest.min.js
Adam Silverstein 86434ebca4 Taxonomy: Use REST API for ajax tag search.
Deprecate wp_ajax_ajax_tag_search and switch to using the REST API when searching tags in the tags meta box.

Props nacin, chriscct7, afercia, swissspidy, jnylen0, rmccue, ryelle.
Fixes #38922.


Built from https://develop.svn.wordpress.org/trunk@42614


git-svn-id: http://core.svn.wordpress.org/trunk@42443 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-01-30 00:17:31 +00:00

1 line
2.1 KiB
JavaScript

!function(a){function b(a){return a.split(new RegExp(d+"\\s*"))}function c(a){return b(a).pop()}if("undefined"!=typeof window.tagsSuggestL10n&&"undefined"!=typeof window.uiAutocompleteL10n){var d=window.tagsSuggestL10n.tagDelimiter||",";a.fn.wpTagsSuggest=function(e){var f,g,h=a(this);e=e||{};var i=e.taxonomy||h.attr("data-wp-taxonomy")||"post_tag";return delete e.taxonomy,e=a.extend({source:function(b,d){var e;return g===b.term?void d(f):(e=c(b.term),a.get(window.tagsSuggestL10n.restURL,{_fields:["id","name"],taxonomy:i,search:e}).always(function(){h.removeClass("ui-autocomplete-loading")}).done(function(a){f=a,d(a)}),void(g=b.term))},focus:function(a,b){h.attr("aria-activedescendant","wp-tags-autocomplete-"+b.item.id),a.preventDefault()},select:function(c,e){var f=b(h.val());return f.pop(),f.push(e.item.name,""),h.val(f.join(d+" ")),a.ui.keyCode.TAB===c.keyCode?(window.wp.a11y.speak(window.tagsSuggestL10n.termSelected,"assertive"),c.preventDefault()):a.ui.keyCode.ENTER===c.keyCode&&(c.preventDefault(),c.stopPropagation()),!1},open:function(){h.attr("aria-expanded","true")},close:function(){h.attr("aria-expanded","false")},minLength:window.tagsSuggestL10n.minChars,position:{my:"left top+2",at:"left bottom",collision:"none"},messages:{noResults:window.uiAutocompleteL10n.noResults,results:function(a){return a>1?window.uiAutocompleteL10n.manyResults.replace("%d",a):window.uiAutocompleteL10n.oneResult}}},e),h.on("keydown",function(){h.removeAttr("aria-activedescendant")}).autocomplete(e).autocomplete("instance")._renderItem=function(b,c){return a('<li role="option" id="wp-tags-autocomplete-'+c.id+'">').text(c.name).appendTo(b)},h.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":h.autocomplete("widget").attr("id")}).on("focus",function(){var a=b(h.val()).pop();a&&h.autocomplete("search")}).autocomplete("widget").addClass("wp-tags-autocomplete").attr("role","listbox").removeAttr("tabindex").on("menufocus",function(a,b){b.item.attr("aria-selected","true")}).on("menublur",function(){a(this).find('[aria-selected="true"]').removeAttr("aria-selected")}),this}}}(jQuery);