Make WordPress Core

Timestamp:
11/16/2018 12:13:32 AM (6 years ago)
Author:
allancole
Message:

Updating Twenty Nineteen, our new default theme for 2019, set for 5.0.

This update changes the following:

  • Improve menu UI to support keyboard navigation in both directions
  • Improve more-menu-link visibility when no menu items are hidden
  • Improve text-selection custom colors for better contrast and legibility
  • Improve support for sticky toolbars in the editor
  • Improve table element fonts
  • Add .button class support
  • Remove translation escaping
  • Fix menu JS to prevent unused touched event listeners
  • Fix duplicate more-menu-link issue on selective refresh in the customizer
  • Fix editor font-weights for headings
  • Fix search form input style
  • Fix nested blockquote styles
  • Fix download block button style when download text stretches more than one line
  • Fix audio block centering issue
  • Fix align-full blocks in the editor so they don’t create horizontal scrollbars
  • Fix editor to prevent Gutenberg's meta boxes area from overlapping the content

Initial development occurred on GitHub. See: https://github.com/WordPress/twentynineteen

Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, aaronjorbin, ntwb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins12, peterwilsoncc, DannyCooper, WPprodigy, siriokun, briannaorg, 00travelgirl00, shahjehanali1, ianbelanger79, nadim1992, Ismail-elkorchi, nativeinside, iamchetanp, grappler, ocean90, joshfeck, frankew, abdulwahab610, mendezcode, eliorivero, melchoyce, jasmussen, laurelfulford, mdawaffe, kraftbj, dereksmart, naokomc, mayukojpn, enodekciw, chetansatasiya, ketuchetan, atanas-angelov-dev, carolinan, sharazghouri, artisan-asad, mukeshpanchal27, mukesh27, burhandodhy, @crunnells, aryaprakasa, tlxo, themeroots, whizbangik, yingles, tlxo, youthkee, brentswisher, smy315, ahmadawais, desi-developer, 2ndkauboy, mor10.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-content/themes/twentynineteen/js/touch-keyboard-navigation.js

    r43892 r43904  
    77(function() {
    88
    9     // Debounce
     9    /**
     10     * Debounce
     11     *
     12     * @param {Function} func
     13     * @param {number} wait
     14     * @param {boolean} immediate
     15     */
    1016    function debounce(func, wait, immediate) {
    1117        'use strict';
     
    3743    }
    3844
    39     // Add Class
     45    /**
     46     * Add class
     47     *
     48     * @param {Object} el
     49     * @param {string} cls
     50     */
    4051    function addClass(el, cls) {
    4152        if ( ! el.className.match( '(?:^|\\s)' + cls + '(?!\\S)') ) {
     
    4455    }
    4556
    46     // Delete Class
     57    /**
     58     * Delete class
     59     *
     60     * @param {Object} el
     61     * @param {string} cls
     62     */
    4763    function deleteClass(el, cls) {
    4864        el.className = el.className.replace( new RegExp( '(?:^|\\s)' + cls + '(?!\\S)' ),'' );
    4965    }
    5066
    51     // Has Class?
     67    /**
     68     * Has class?
     69     *
     70     * @param {Object} el
     71     * @param {string} cls
     72     *
     73     * @returns {boolean} Has class
     74     */
    5275    function hasClass(el, cls) {
    5376
     
    5780    }
    5881
    59     // Toggle Aria Expanded state for screenreaders
     82    /**
     83     * Toggle Aria Expanded state for screenreaders
     84     *
     85     * @param {Object} ariaItem
     86     */
    6087    function toggleAriaExpandedState( ariaItem ) {
    6188        'use strict';
     
    7299    }
    73100
    74     // Open sub-menu
     101    /**
     102     * Open sub-menu
     103     *
     104     * @param {Object} currentSubMenu
     105     */
    75106    function openSubMenu( currentSubMenu ) {
    76107        'use strict';
     
    85116    }
    86117
    87     // Close sub-menu
     118    /**
     119     * Close sub-menu
     120     *
     121     * @param {Object} currentSubMenu
     122     */
    88123    function closeSubMenu( currentSubMenu ) {
    89124        'use strict';
     
    117152    }
    118153
    119     // Find first ancestor of an element by selector
     154    /**
     155     * Find first ancestor of an element by selector
     156     *
     157     * @param {Object} child
     158     * @param {String} selector
     159     * @param {String} stopSelector
     160     */
    120161    function getCurrentParent( child, selector, stopSelector ) {
    121162
     
    140181    }
    141182
    142     // Remove all off-canvas states
     183    /**
     184     * Remove all off-canvas states
     185     */
    143186    function removeAllFocusStates() {
    144187        'use strict';
    145188
    146         var getFocusedElements = document.querySelectorAll(':hover, :focus, :focus-within');
     189        var siteBranding            = document.getElementsByClassName( 'site-branding' )[0];
     190        var getFocusedElements      = siteBranding.querySelectorAll(':hover, :focus, :focus-within');
     191        var getFocusedClassElements = siteBranding.querySelectorAll('.is-focused');
    147192        var i;
     193
    148194
    149195        for ( i = 0; i < getFocusedElements.length; i++) {
    150196            getFocusedElements[i].blur();
    151197        }
    152     }
    153 
    154     // Matches polyfill for IE11
     198
     199        for ( o = 0; o < getFocusedClassElements.length; o++) {
     200            deleteClass( getFocusedClassElements[o], 'is-focused' );
     201        }
     202    }
     203
     204    /**
     205     * Matches polyfill for IE11
     206     */
    155207    if (!Element.prototype.matches) {
    156208        Element.prototype.matches = Element.prototype.msMatchesSelector;
    157209    }
    158210
    159     // Toggle `focus` class to allow sub-menu access on touch screens.
     211    /**
     212     * Toggle `focus` class to allow sub-menu access on touch screens.
     213     */
    160214    function toggleSubmenuDisplay() {
    161215
     
    211265                // Prevent default mouse events
    212266                event.preventDefault();
    213             }
    214 
    215             // Prevent default mouse events
    216             event.preventDefault();
     267            } else if (
     268                event.target.matches('.submenu-expand') ||
     269                null != getCurrentParent( event.target, '.submenu-expand' ) &&
     270                getCurrentParent( event.target, '.submenu-expand' ).matches( '.submenu-expand' ) ||
     271                event.target.matches('.menu-item-link-return') ||
     272                null != getCurrentParent( event.target, '.menu-item-link-return' ) &&
     273                getCurrentParent( event.target, '.menu-item-link-return' ).matches( '.menu-item-link-return' ) ) {
     274                    // Prevent default mouse events
     275                    event.preventDefault();
     276            }
    217277
    218278            // Prevent default mouse/focus events
     
    223283        document.addEventListener('focus', function(event) {
    224284
    225             if ( event.target.matches('.main-navigation > div > ul > li > a') ) {
    226 
    227                 // Remove Focuse elements in sibling div
    228                 var currentDiv        = getCurrentParent( event.target, 'div' );
     285            if ( event.target.matches('.main-navigation > div > ul > li a') ) {
     286
     287                // Remove Focuse elements in sibling div
     288                var currentDiv        = getCurrentParent( event.target, 'div' );
    229289                var currentDivSibling = currentDiv.previousElementSibling === null ? currentDiv.nextElementSibling : currentDiv.previousElementSibling;
    230290                var focusedElement    = currentDivSibling.querySelector( '.is-focused' );
    231291                var focusedClass      = 'is-focused';
    232                 var prevLi            = event.target.parentNode.previousElementSibling;
    233                 var nextLi            = event.target.parentNode.nextElementSibling;
     292                var prevLi            = .previousElementSibling;
     293                var nextLi            = .nextElementSibling;
    234294
    235295                if ( null !== focusedElement && null !== hasClass( focusedElement, focusedClass ) ) {
     
    237297                }
    238298
    239                 // Add .is-focused class to top-level ul
    240                 if ( event.target.parentNode.querySelector( '.main-navigation ul ul') ) {
    241                     addClass( event.target.parentNode, focusedClass );
     299                // Add .is-focused class to top-level
     300                if ( ) ) {
     301                    addClass( , focusedClass );
    242302                }
    243303
     
    252312                }
    253313            }
     314
    254315        }, true);
    255     }
    256 
    257     // Run our sub-menu function as soon as the document is `ready`
     316
     317        document.addEventListener('click', function(event) {
     318
     319            // Remove all focused menu states when clicking outside site branding
     320            if ( event.target !== document.getElementsByClassName( 'site-branding' )[0] ) {
     321                removeAllFocusStates();
     322            } else {
     323                // nothing
     324            }
     325
     326        }, false);
     327    }
     328
     329    /**
     330     * Run our sub-menu function as soon as the document is `ready`
     331     */
    258332    document.addEventListener( 'DOMContentLoaded', function() {
    259333        toggleSubmenuDisplay();
    260334    });
    261     // Annnnnd also every time the window resizes
     335
     336    /**
     337     * Run our sub-menu function on selective refresh in the customizer
     338     */
     339    document.addEventListener( 'customize-preview-menu-refreshed', function( e, params ) {
     340        if ( 'menu-1' === params.wpNavMenuArgs.theme_location ) {
     341            toggleSubmenuDisplay();
     342        }
     343    });
     344
     345    /**
     346     * Run our sub-menu function every time the window resizes
     347     */
    262348    var isResizing = false;
    263     window.addEventListener( 'resize',
     349    window.addEventListener( 'resize', function() {
     350        isResizing = true;
    264351        debounce( function() {
    265352            if ( isResizing ) {
     
    267354            }
    268355
    269             isResizing = true;
    270             setTimeout( function() {
    271                 toggleSubmenuDisplay();
    272                 isResizing = false;
    273             }, 150 );
    274         } )
    275     );
     356            toggleSubmenuDisplay();
     357            isResizing = false;
     358
     359        }, 150 );
     360    } );
    276361
    277362})();
Note: See TracChangeset for help on using the changeset viewer.