Make WordPress Core

Ticket #43871: admin-bar.diff

File admin-bar.diff, 8.9 KB (added by manuelaugustin, 7 years ago)
  • src/wp-includes/js/admin-bar.js

    diff --git src/wp-includes/js/admin-bar.js src/wp-includes/js/admin-bar.js
    index 10d2954..d8d9fbb 100644
    if ( typeof(jQuery) != 'undefined' ) { 
    1010        jQuery(document).ready(function($){
    1111                var adminbar = $('#wpadminbar'), refresh, touchOpen, touchClose, disableHoverIntent = false;
    1212
    13                 refresh = function(i, el){ // force the browser to refresh the tabbing index
     13                /**
     14                 * Forces the browser to refresh the tabbing index.
     15                 *
     16                 * @since 3.5.0
     17                 *
     18                 * @param  {integer} i The index of the HTML element to remove the tab index from.
     19                 * @param {HTMLElement} el The HTML element to remove the tab index from.
     20                 *
     21                 * @returns {void}
     22                 */
     23                refresh = function(i, el){
    1424                        var node = $(el), tab = node.attr('tabindex');
    1525                        if ( tab )
    1626                                node.attr('tabindex', '0').attr('tabindex', tab);
    1727                };
    1828
     29                /**
     30                 * Adds or removes the hover class on touch.
     31                 *
     32                 * @since 3.5.0
     33                 *
     34                 * @param {bool} unbind If true removes the wp-mobile-hover class.
     35                 *
     36                 * @returns {void}
     37                 */
    1938                touchOpen = function(unbind) {
    2039                        adminbar.find('li.menupop').on('click.wp-mobile-hover', function(e) {
    2140                                var el = $(this);
    if ( typeof(jQuery) != 'undefined' ) { 
    4362                        });
    4463                };
    4564
     65                /**
     66                 * Removes the hover class if clicked or touched outside the adminbar.
     67                 *
     68                 * @since 3.5.0
     69                 *
     70                 * @returns {void}
     71                 */
    4672                touchClose = function() {
    4773                        var mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
    4874                        // close any open drop-downs when the click/touch is not on the toolbar
    if ( typeof(jQuery) != 'undefined' ) { 
    5480
    5581                adminbar.removeClass('nojq').removeClass('nojs');
    5682
     83                // If clicked on the adminbar add the hoverclass, if clicked outside it remove it.
    5784                if ( 'ontouchstart' in window ) {
    5885                        adminbar.on('touchstart', function(){
    5986                                touchOpen(true);
    if ( typeof(jQuery) != 'undefined' ) { 
    6592                        touchClose();
    6693                }
    6794
     95                // Adds or remove the hover class based on the hover intent.
    6896                adminbar.find('li.menupop').hoverIntent({
    6997                        over: function() {
    7098                                if ( disableHoverIntent )
    if ( typeof(jQuery) != 'undefined' ) { 
    83111                        interval: 100
    84112                });
    85113
     114                // Prevents the toolbar from covering up content when a hash is present in the URL.
    86115                if ( window.location.hash )
    87116                        window.scrollBy( 0, -32 );
    88117
     118                /**
     119                 * Adds selected class to shortlink in admin bar.
     120                 *
     121                 * Removes the selected class from the parents of the selected shortlink-input.
     122                 *
     123                 * @since 3.5.0
     124                 *
     125                 * @param {event} e The click event.
     126                 *
     127                 * @returns {void}
     128                 **/
    89129                $('#wp-admin-bar-get-shortlink').click(function(e){
    90130                        e.preventDefault();
    91131                        $(this).addClass('selected').children('.shortlink-input').blur(function(){
    if ( typeof(jQuery) != 'undefined' ) { 
    93133                        }).focus().select();
    94134                });
    95135
     136                /**
     137                 * It removes the hoverclass if the enter key is pressed.
     138                 *
     139                 * Makes sure the tab index is refreshed by refreshing each ab-item
     140                 * and its children.
     141                 *
     142                 * @since 3.5.0
     143                 *
     144                 * @param {event} e The keydown event.
     145                 *
     146                 * @returns {void}
     147                 */
    96148                $('#wpadminbar li.menupop > .ab-item').bind('keydown.adminbar', function(e){
     149                        // Key code 13 is the enter key.
    97150                        if ( e.which != 13 )
    98151                                return;
    99152
    if ( typeof(jQuery) != 'undefined' ) { 
    116169                        target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
    117170                }).each(refresh);
    118171
     172                /**
     173                 * Removes the hover class when the escape key is pressed.
     174                 *
     175                 * Makes sure the tab index is refreshed by refreshing each ab-item
     176                 * and its children.
     177                 *
     178                 * @since 3.5.0
     179                 *
     180                 * @param {event} e The keydown event.
     181                 *
     182                 * @returns {void}
     183                 */
    119184                $('#wpadminbar .ab-item').bind('keydown.adminbar', function(e){
     185                        // Key code 27 is the escape key.
    120186                        if ( e.which != 27 )
    121187                                return;
    122188
    if ( typeof(jQuery) != 'undefined' ) { 
    129195                        target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);
    130196                });
    131197
     198                /**
     199                 * Scrolls to top of page by clicking the adminbar.
     200                 *
     201                 * @since 4.3.0
     202                 *
     203                 * @param {event} e The click event.
     204                 *
     205                 * @returns {void}
     206                 */
    132207                adminbar.click( function(e) {
    133208                        if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' ) {
    134209                                return;
    if ( typeof(jQuery) != 'undefined' ) { 
    139214                        e.preventDefault();
    140215                });
    141216
    142                 // fix focus bug in WebKit
     217                /**
     218                 * Sets the focus on an element with a href attribute.
     219                 *
     220                 * The timeout is used to fix a focus bug in WebKit.
     221                 *
     222                 * @since 3.5.0
     223                 *
     224                 * @param {event} e The keydown event.
     225                 *
     226                 * @returns {void}
     227                 */
    143228                $('.screen-reader-shortcut').keydown( function(e) {
    144229                        var id, ua;
    145230
    if ( typeof(jQuery) != 'undefined' ) { 
    158243                });
    159244
    160245                $( '#adminbar-search' ).on({
     246                        /**
     247                         * Adds the adminbar-focused class on focus.
     248                         *
     249                         * @since 4.2.0
     250                         *
     251                         * @returns {void}
     252                         */
    161253                        focus: function() {
    162254                                $( '#adminbarsearch' ).addClass( 'adminbar-focused' );
     255                        /**
     256                         * Remove the adminbar-focused class on blur.
     257                         *
     258                         * @since 4.2.0
     259                         *
     260                         * @returns {void}
     261                         */
    163262                        }, blur: function() {
    164263                                $( '#adminbarsearch' ).removeClass( 'adminbar-focused' );
    165264                        }
    166265                } );
    167266
    168                 // Empty sessionStorage on logging out
    169267                if ( 'sessionStorage' in window ) {
     268            /**
     269                         * Empties sessionStorage on logging out.
     270                         *
     271                         * @since 3.6.0
     272                         *
     273                         * @returns {void}
     274             */
    170275                        $('#wp-admin-bar-logout a').click( function() {
    171276                                try {
    172277                                        for ( var key in sessionStorage ) {
    if ( typeof(jQuery) != 'undefined' ) { 
    184289                }
    185290        });
    186291} else {
     292    /**
     293         * Wrapper function for the adminbar that's used if jQuery isn't available.
     294         *
     295         * @since 3.5.0
     296         *
     297         * @param {Object} d The document object.
     298         * @param {Object} w The window object.
     299         *
     300         * @returns {void}
     301     */
    187302        (function(d, w) {
     303        /**
     304                 * Adds an event listener to an object.
     305                 *
     306                 * @since 3.5.0
     307                 *
     308         * @param {Object} obj The object to add the event listener to.
     309         * @param {string} type The type of event.
     310         * @param {function} fn The function to bind to the event listener.
     311                 *
     312                 * @returns {void}
     313         */
    188314                var addEvent = function( obj, type, fn ) {
    189315                        if ( obj.addEventListener )
    190316                                obj.addEventListener(type, fn, false);
    if ( typeof(jQuery) != 'undefined' ) { 
    195321                aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],
    196322                rselected = new RegExp('\\bselected\\b', 'g'),
    197323
    198                 /**
    199                  * Get the timeout ID of the given element
     324            /**
     325                 * Gets the timeout ID of the given element.
     326                 *
     327                 * @since 3.5.0
     328                 *
     329                 * @param {HTMLElement} el The HTML element.
     330             *
     331                 * @returns {number|boolean} The ID value of the timer that is set or false.
    200332                 */
    201333                getTOID = function(el) {
    202334                        var i = q.length;
    if ( typeof(jQuery) != 'undefined' ) { 
    207339                        return false;
    208340                },
    209341
     342            /**
     343                 * Adds the hoverclass to menu items.
     344                 *
     345                 * @since 3.5.0
     346                 *
     347                 * @param {HTMLElement} t The HTML element.
     348                 *
     349                 * @returns {void}
     350                 */
    210351                addHoverClass = function(t) {
    211352                        var i, id, inA, hovering, ul, li,
    212353                                ancestors = [],
    213354                                ancestorLength = 0;
    214355
     356                        // aB is adminbar. d is document.
    215357                        while ( t && t != aB && t != d ) {
    216358                                if ( 'LI' == t.nodeName.toUpperCase() ) {
    217359                                        ancestors[ ancestors.length ] = t;
    if ( typeof(jQuery) != 'undefined' ) { 
    224366                                t = t.parentNode;
    225367                        }
    226368
    227                         // Remove any selected classes.
     369                        // Removes any selected classes.
    228370                        if ( hovering && hovering.parentNode ) {
    229371                                ul = hovering.parentNode;
    230372                                if ( ul && 'UL' == ul.nodeName.toUpperCase() ) {
    if ( typeof(jQuery) != 'undefined' ) { 
    237379                                }
    238380                        }
    239381
    240                         /* remove the hover class for any objects not in the immediate element's ancestry */
     382                        // Removes the hover class for any objects not in the immediate element's ancestry.
    241383                        i = q.length;
    242384                        while ( i-- ) {
    243385                                inA = false;
    if ( typeof(jQuery) != 'undefined' ) { 
    252394                        }
    253395                },
    254396
     397                /**
     398                         * Removes the hoverclass from menu items.
     399                         *
     400                         * @since 3.5.0
     401                         *
     402                         * @param {HTMLElement} t The HTML element.
     403                         *
     404                         * @returns {void}
     405                         */
    255406                removeHoverClass = function(t) {
    256407                        while ( t && t != aB && t != d ) {
    257408                                if ( 'LI' == t.nodeName.toUpperCase() ) {
    if ( typeof(jQuery) != 'undefined' ) { 
    266417                        }
    267418                },
    268419
     420                /**
     421                 * Handles the click on a shortlink in the adminbar.
     422                 *
     423                 * @since 3.5.0
     424                 *
     425                 * @param {HTMLElement} e The HTML element.
     426                 *
     427                 * @returns {boolean}
     428                 */
    269429                clickShortlink = function(e) {
    270430                        var i, l, node,
    271431                                t = e.target || e.srcElement;
    if ( typeof(jQuery) != 'undefined' ) { 
    304464                        return false;
    305465                },
    306466
     467                /**
     468                 * Scrolls to the top of the page.
     469                 *
     470                 * @since 3.5.0
     471                 *
     472                 * @param {HTMLElement} t The HTML element.
     473                 *
     474                 * @returns {void}
     475                 */
    307476                scrollToTop = function(t) {
    308477                        var distance, speed, step, steps, timer, speed_step;
    309478