Make WordPress Core

Ticket #33902: 33902.3.patch

File 33902.3.patch, 15.4 KB (added by azaozz, 7 years ago)
  • src/wp-admin/includes/class-wp-posts-list-table.php

     
    15501550        <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
    15511551
    15521552        <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
    1553                 <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
     1553                <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) :
     1554                        $taxonomy_name = esc_attr( $taxonomy->name );
     1555       
     1556                        ?>
    15541557                        <label class="inline-edit-tags">
    15551558                                <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
    1556                                 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
     1559                                <textarea data-wp-taxonomy="<?php echo $taxonomy_name; ?>" cols="22" rows="1" name="tax_input[<?php echo $taxonomy_name; ?>]" class="tax_input_<?php echo $taxonomy_name; ?>"></textarea>
    15571560                        </label>
    15581561                <?php endif; ?>
    15591562
  • src/wp-admin/includes/meta-boxes.php

     
    431431        <?php if ( $user_can_assign_terms ) : ?>
    432432        <div class="ajaxtag hide-if-no-js">
    433433                <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
    434                 <p><input type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" aria-describedby="new-tag-<?php echo $tax_name; ?>-desc" value="" />
     434                <p><input data-wp-taxonomy="<?php echo $tax_name; ?>" type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" aria-describedby="new-tag-<?php echo $tax_name; ?>-desc" value="" />
    435435                <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" /></p>
    436436        </div>
    437437        <p class="howto" id="new-tag-<?php echo $tax_name; ?>-desc"><?php echo $taxonomy->labels->separate_items_with_commas; ?></p>
  • src/wp-admin/js/inline-edit-post.js

     
    114114
    115115                // enable autocomplete for tags
    116116                if ( 'post' === type ) {
    117                         // support multi taxonomies?
    118                         tax = 'post_tag';
    119                         $('tr.inline-editor textarea[name="tax_input['+tax+']"]').suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma } );
     117                        $( 'tr.inline-editor textarea[data-wp-taxonomy]' ).each( function ( i, element ) {
     118                                $( element ).wpTagsSuggest();
     119                        } );
    120120                }
    121121                $('html, body').animate( { scrollTop: 0 }, 'fast' );
    122122        },
     
    196196                                textarea.val(terms);
    197197                        }
    198198
    199                         textarea.suggest( ajaxurl + '?action=ajax-tag-search&tax=' + taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma } );
     199                        textarea.wpTagsSuggest();
    200200                });
    201201
    202202                // handle the post status
  • src/wp-admin/js/tags-box.js

     
    44var tagBox, array_unique_noempty;
    55
    66( function( $ ) {
     7        var tagDelimiter = ( window.tagsSuggestL10n && window.tagsSuggestL10n.tagDelimiter ) || ',';
     8
    79        // Return an array with any duplicate, whitespace or empty values removed
    810        array_unique_noempty = function( array ) {
    911                var out = [];
     
    2022        };
    2123
    2224        tagBox = {
    23                 clean : function(tags) {
    24                         var comma = window.tagsBoxL10n.tagDelimiter;
    25                         if ( ',' !== comma )
    26                                 tags = tags.replace(new RegExp(comma, 'g'), ',');
     25                clean : function( tags ) {
     26                        if ( ',' !== tagDelimiter ) {
     27                                tags = tags.replace( new RegExp( tagDelimiter, 'g' ), ',' );
     28                        }
     29
    2730                        tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
    28                         if ( ',' !== comma )
    29                                 tags = tags.replace(/,/g, comma);
     31
     32                        if ( ',' !== tagDelimiter ) {
     33                                tags = tags.replace( /,/g, tagDelimiter );
     34                        }
     35
    3036                        return tags;
    3137                },
    3238
     
    3541                                num = id.split('-check-num-')[1],
    3642                                taxbox = $(el).closest('.tagsdiv'),
    3743                                thetags = taxbox.find('.the-tags'),
    38                                 comma = window.tagsBoxL10n.tagDelimiter,
    39                                 current_tags = thetags.val().split( comma ),
     44                                current_tags = thetags.val().split( tagDelimiter ),
    4045                                new_tags = [];
    4146
    4247                        delete current_tags[num];
     
    4853                                }
    4954                        });
    5055
    51                         thetags.val( this.clean( new_tags.join( comma ) ) );
     56                        thetags.val( this.clean( new_tags.join( tagDelimiter ) ) );
    5257
    5358                        this.quickClicks( taxbox );
    5459                        return false;
     
    6570
    6671                        disabled = thetags.prop('disabled');
    6772
    68                         current_tags = thetags.val().split( window.tagsBoxL10n.tagDelimiter );
     73                        current_tags = thetags.val().split( tagDelimiter );
    6974                        tagchecklist.empty();
    7075
    7176                        $.each( current_tags, function( key, val ) {
     
    106111                flushTags : function( el, a, f ) {
    107112                        var tagsval, newtags, text,
    108113                                tags = $( '.the-tags', el ),
    109                                 newtag = $( 'input.newtag', el ),
    110                                 comma = window.tagsBoxL10n.tagDelimiter;
     114                                newtag = $( 'input.newtag', el );
    111115
    112116                        a = a || false;
    113117
     
    118122                        }
    119123
    120124                        tagsval = tags.val();
    121                         newtags = tagsval ? tagsval + comma + text : text;
     125                        newtags = tagsval ? tagsval + tagDelimiter + text : text;
    122126
    123127                        newtags = this.clean( newtags );
    124                         newtags = array_unique_noempty( newtags.split( comma ) ).join( comma );
     128                        newtags = array_unique_noempty( newtags.split( tagDelimiter ) ).join( tagDelimiter );
    125129                        tags.val( newtags );
    126130                        this.quickClicks( el );
    127131
     
    153157                },
    154158
    155159                init : function() {
    156                         var t = this, ajaxtag = $('div.ajaxtag');
     160                        var t = this;
     161                        var ajaxtag = $('div.ajaxtag');
    157162
    158163                        $('.tagsdiv').each( function() {
    159                                 tagBox.quickClicks(this);
     164                                tagBox.quickClicks( this );
    160165                        });
    161166
    162                         $('.tagadd', ajaxtag).click(function(){
    163                                 t.flushTags( $(this).closest('.tagsdiv') );
     167                        $( '.tagadd', ajaxtag ).click( function() {
     168                                tagBox.flushTags( $( this ).closest( '.tagsdiv' ) );
    164169                        });
    165170
    166                         $('input.newtag', ajaxtag).keyup(function(e){
    167                                 if ( 13 == e.which ) {
    168                                         tagBox.flushTags( $(this).closest('.tagsdiv') );
    169                                         return false;
     171                        $( 'input.newtag', ajaxtag ).keyup( function( event ) {
     172                                if ( 13 == event.which ) {
     173                                        tagBox.flushTags( $( this ).closest( '.tagsdiv' ) );
     174                                        event.preventDefault();
     175                                        event.stopPropagation();
    170176                                }
    171                         }).keypress(function(e){
    172                                 if ( 13 == e.which ) {
    173                                         e.preventDefault();
    174                                         return false;
     177                        }).keypress( function( event ) {
     178                                if ( 13 == event.which ) {
     179                                        event.preventDefault();
     180                                        event.stopPropagation();
    175181                                }
    176                         }).each( function() {
    177                                 var tax = $(this).closest('div.tagsdiv').attr('id');
    178                                 $(this).suggest(
    179                                         ajaxurl + '?action=ajax-tag-search&tax=' + tax,
    180                                         { delay: 500, minchars: 2, multiple: true, multipleSep: window.tagsBoxL10n.tagDelimiter }
    181                                 );
     182                        }).each( function( i, element ) {
     183                                $( element ).wpTagsSuggest();
    182184                        });
    183185
    184186                        // save tags on post save/publish
  • src/wp-admin/js/tags-suggest.js

     
     1( function( $ ) {
     2        var tempID = 0;
     3        var separator = ( window.tagsSuggestL10n && window.tagsSuggestL10n.tagDelimiter ) || ',';
     4
     5        function split( val ) {
     6                return val.split( new RegExp( separator + '\\s*' ) );
     7        }
     8
     9        function getLast( term ) {
     10                return split( term ).pop();
     11        }
     12
     13        $.fn.wpTagsSuggest = function( options ) {
     14                var cache;
     15                var last;
     16                var $element = $( this );
     17
     18                options = options || {};
     19               
     20                var taxonomy = options.taxonomy || $element.attr( 'data-wp-taxonomy' ) || 'post_tag';
     21               
     22                delete( options.taxonomy );
     23
     24                options = $.extend( {
     25                        source: function( request, response ) {                         
     26                                var term;
     27
     28                                if ( last === request.term ) {
     29                                        response( cache );
     30                                        return;
     31                                }
     32
     33                                term = getLast( request.term );
     34
     35                                $.get( window.ajaxurl, {
     36                                        action: 'ajax-tag-search',
     37                                        tax: taxonomy,
     38                                        q: term
     39                                } ).always( function() {
     40                                        $element.removeClass( 'ui-autocomplete-loading' ); // UI fails to remove this sometimes?
     41                                } ).done( function( data ) {
     42                                        var value;
     43                                        var terms = [];
     44
     45                                        if ( data ) {
     46                                                data = data.split( '\n' );
     47
     48                                                for ( value in data ) {
     49                                                        var id = ++tempID;
     50
     51                                                        terms.push({
     52                                                                id: id,
     53                                                                name: data[value]
     54                                                        });
     55                                                }
     56
     57                                                cache = terms;
     58                                                response( terms );
     59                                        } else {
     60                                                response( terms );
     61                                        }
     62                                } );
     63
     64                                last = request.term;
     65                        },
     66                        focus: function( event, ui ) {
     67                                $element.attr( 'aria-activedescendant', 'wp-tags-autocomplete-' + ui.item.id );
     68
     69                                // Don't empty the input field when using the arrow keys to
     70                                // highlight items. See api.jqueryui.com/autocomplete/#event-focus
     71                                event.preventDefault();
     72                        },
     73                        select: function( event, ui ) {
     74                                var tags = split( $element.val() );
     75                                // Remove the last user input.
     76                                tags.pop();
     77                                // Append the new tag and an empty element to get one more separator at the end.
     78                                tags.push( ui.item.name, '' );
     79
     80                                $element.val( tags.join( separator + ' ' ) );
     81
     82                                if ( 9 === event.keyCode && typeof window.uiAutocompleteL10n !== 'undefined' ) {
     83                                        // Audible confirmation message when a tag has been selected.
     84                                        speak( window.uiAutocompleteL10n.itemSelected );
     85                                }
     86
     87                                return false;
     88                        },
     89                        open: function() {
     90                                $element.attr( 'aria-expanded', 'true' );
     91                        },
     92                        close: function() {
     93                                $element.attr( 'aria-expanded', 'false' );
     94                        },
     95                        minLength: 2,
     96                        position: {
     97                                my: 'left top+2'
     98                        },
     99                        messages: {
     100                                noResults: ( typeof window.uiAutocompleteL10n !== 'undefined' ) ? window.uiAutocompleteL10n.noResults : '',
     101                                results: function( number ) {
     102                                        if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
     103                                                if ( number > 1 ) {
     104                                                        return window.uiAutocompleteL10n.manyResults.replace( '%d', number );
     105                                                }
     106
     107                                                return window.uiAutocompleteL10n.oneResult;
     108                                        }
     109                                }
     110                        }
     111                }, options );
     112
     113                $element.on( 'keydown', function() {
     114                        $element.removeAttr( 'aria-activedescendant' );
     115                } )
     116                .autocomplete( options )
     117                .autocomplete( 'instance' )._renderItem = function( ul, item ) {
     118                        return $( '<li role="option" id="wp-tags-autocomplete-' + item.id + '">' )
     119                                .text( item.name )
     120                                .appendTo( ul );
     121                };
     122
     123                $element.attr( {
     124                        'role': 'combobox',
     125                        'aria-autocomplete': 'list',
     126                        'aria-expanded': 'false',
     127                        'aria-owns': $element.autocomplete( 'widget' ).attr( 'id' )
     128                } )
     129                .on( 'focus', function() {
     130                        var inputValue = split( $element.val() ).pop();
     131
     132                        // Don't trigger a search if the field is empty.
     133                        // Also, avoids screen readers announce `No search results`.
     134                        if ( inputValue ) {
     135                                $element.autocomplete( 'search' );
     136                        }
     137                } )
     138                // Returns a jQuery object containing the menu element.
     139                .autocomplete( 'widget' )
     140                        .addClass( 'wplink-autocomplete' )
     141                        .attr( 'role', 'listbox' )
     142                        .removeAttr( 'tabindex' ) // Remove the `tabindex=0` attribute added by jQuery UI.
     143
     144                        // Looks like Safari and VoiceOver need an `aria-selected` attribute. See ticket #33301.
     145                        // The `menufocus` and `menublur` events are the same events used to add and remove
     146                        // the `ui-state-focus` CSS class on the menu items. See jQuery UI Menu Widget.
     147                        .on( 'menufocus', function( event, ui ) {
     148                                ui.item.attr( 'aria-selected', 'true' );
     149                        })
     150                        .on( 'menublur', function() {
     151                                // The `menublur` event returns an object where the item is `null`
     152                                // so we need to find the active item with other means.
     153                                $( this ).find( '[aria-selected="true"]' ).removeAttr( 'aria-selected' );
     154                        });
     155                       
     156                return this;
     157        }
     158
     159}( jQuery ) );
  • src/wp-includes/script-loader.php

    Property changes on: src/wp-admin/js/tags-suggest.js
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    234234                'oneResult' => __( '1 result found. Use up and down arrow keys to navigate.' ),
    235235                /* translators: %d: Number of results found when using jQuery UI Autocomplete */
    236236                'manyResults' => __( '%d results found. Use up and down arrow keys to navigate.' ),
     237                'itemSelected' => __( 'Item selected.' ),
    237238        ) );
    238239
    239240        // deprecated, not used in core, most functionality is included in jQuery 1.3
     
    241242
    242243        // jQuery plugins
    243244        $scripts->add( 'jquery-color', "/wp-includes/js/jquery/jquery.color.min.js", array('jquery'), '2.1.1', 1 );
    244         $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array('jquery'), '1.1-20110113', 1 );
    245245        $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m', 1 );
    246246        $scripts->add( 'jquery-query', "/wp-includes/js/jquery/jquery.query.js", array('jquery'), '2.1.7', 1 );
    247247        $scripts->add( 'jquery-serialize-object', "/wp-includes/js/jquery/jquery.serialize-object.js", array('jquery'), '0.2', 1 );
     
    249249        $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), false, 1 );
    250250        $scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 );
    251251
     252        // Not used any more, registered for backwards compatibility.
     253        $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array('jquery'), '1.1-20110113', 1 );
     254
    252255        // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
    253256        // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
    254257        $scripts->add( 'imagesloaded', "/wp-includes/js/imagesloaded.min.js", array(), '3.2.0', 1 );
     
    523526                        'postBoxEmptyString' => __( 'Drag boxes here' ),
    524527                ) );
    525528
    526                 $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'suggest' ), false, 1 );
    527                 did_action( 'init' ) && $scripts->localize( 'tags-box', 'tagsBoxL10n', array(
     529                $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 );
     530
     531                $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
     532                did_action( 'init' ) && $scripts->localize( 'tags-suggest', 'tagsSuggestL10n', array(
    528533                        'tagDelimiter' => _x( ',', 'tag delimiter' ),
    529534                ) );
    530535
     
    584589
    585590                $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone', 'wp-a11y' ), false, 1 );
    586591
    587                 $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest', 'wp-a11y' ), false, 1 );
     592                $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'tags-suggest', 'wp-a11y' ), false, 1 );
    588593                did_action( 'init' ) && $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
    589594                        'error'      => __( 'Error while saving the changes.' ),
    590595                        'ntdeltitle' => __( 'Remove From Bulk Edit' ),