Make WordPress Core


Ignore:
Timestamp:
05/02/2016 07:52:01 PM (8 years ago)
Author:
westonruter
Message:

Customize: Allow Esc key to collapse the currently-expanded panel, section (or control).

Pressing Esc collapses any expanded widget or nav menu item controls, or any control that implements the expanding interface. Also improves alignment between WidgetControl and MenuItemControl, adding the expanded state and associated expand/collapse methods to nav menu items.

Props purcebr, celloexpressions, westonruter.
Fixes #22237.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-nav-menus.js

    r36908 r37347  
    994994        initialize: function( id, options ) {
    995995            var control = this;
     996            control.expanded = new api.Value( false );
     997            control.expandedArgumentsQueue = [];
     998            control.expanded.bind( function( expanded ) {
     999                var args = control.expandedArgumentsQueue.shift();
     1000                args = $.extend( {}, control.defaultExpandedArguments, args );
     1001                control.onChangeExpanded( expanded, args );
     1002            });
    9961003            api.Control.prototype.initialize.call( control, id, options );
    9971004            control.active.validate = function() {
     
    13711378
    13721379        /**
     1380         * @since 4.6.0
     1381         *
     1382         * @param {Boolean} expanded
     1383         * @param {Object} [params]
     1384         * @returns {Boolean} false if state already applied
     1385         */
     1386        _toggleExpanded: api.Section.prototype._toggleExpanded,
     1387
     1388        /**
     1389         * @since 4.6.0
     1390         *
     1391         * @param {Object} [params]
     1392         * @returns {Boolean} false if already expanded
     1393         */
     1394        expand: api.Section.prototype.expand,
     1395
     1396        /**
    13731397         * Expand the menu item form control.
    13741398         *
     
    13791403         */
    13801404        expandForm: function( params ) {
    1381             this.toggleForm( true, params );
    1382         },
     1405            this.expand( params );
     1406        },
     1407
     1408        /**
     1409         * @since 4.6.0
     1410         *
     1411         * @param {Object} [params]
     1412         * @returns {Boolean} false if already collapsed
     1413         */
     1414        collapse: api.Section.prototype.collapse,
    13831415
    13841416        /**
     
    13911423         */
    13921424        collapseForm: function( params ) {
    1393             this.toggleForm( false, params );
     1425            this.collapse( params );
    13941426        },
    13951427
     
    13971429         * Expand or collapse the menu item control.
    13981430         *
     1431         * @deprecated this is poor naming, and it is better to directly set control.expanded( showOrHide )
    13991432         * @since 4.5.0 Added params.completeCallback.
    14001433         *
     
    14041437         */
    14051438        toggleForm: function( showOrHide, params ) {
     1439            if ( typeof showOrHide === 'undefined' ) {
     1440                showOrHide = ! this.expanded();
     1441            }
     1442            if ( showOrHide ) {
     1443                this.expand( params );
     1444            } else {
     1445                this.collapse( params );
     1446            }
     1447        },
     1448
     1449        /**
     1450         * Expand or collapse the menu item control.
     1451         *
     1452         * @since 4.6.0
     1453         * @param {boolean}  [showOrHide] - If not supplied, will be inverse of current visibility
     1454         * @param {Object}   [params] - Optional params.
     1455         * @param {Function} [params.completeCallback] - Function to call when the form toggle has finished animating.
     1456         */
     1457        onChangeExpanded: function( showOrHide, params ) {
    14061458            var self = this, $menuitem, $inside, complete;
    14071459
Note: See TracChangeset for help on using the changeset viewer.