WordPress.org

Make WordPress Core

Changeset 39928


Ignore:
Timestamp:
01/20/2017 04:14:23 PM (18 months ago)
Author:
adamsilverstein
Message:

Menus: trigger an event when menu items are added or removed.

Fire a menu-item-added event after a menu item is added to the DOM. Fire a menu-removing-item event before a menu item is removed from the DOM. Enables hooking into and responding to menu changes.

Props welcher, adamsilverstein.
Fixes #31218.

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r38981 r39928  
    10041004
    10051005        /**
    1006          * Process the add menu item request response into menu list item.
     1006         * Process the add menu item request response into menu list item. Appends to menu.
    10071007         *
    1008          * @param string menuMarkup The text server response of menu item markup.
    1009          * @param object req The request arguments.
     1008         * @param {string} menuMarkup The text server response of menu item markup.
     1009         *
     1010         * @fires document#menu-item-added Passes menuMarkup as a jQuery object.
    10101011         */
    10111012        addMenuItemToBottom : function( menuMarkup ) {
    1012             $(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList );
     1013            var $menuMarkup = $( menuMarkup );
     1014            $menuMarkup.hideAdvancedMenuItemFields().appendTo( api.targetList );
    10131015            api.refreshKeyboardAccessibility();
    10141016            api.refreshAdvancedAccessibility();
    1015         },
    1016 
     1017            $( document ).trigger( 'menu-item-added', [ $menuMarkup ] );
     1018        },
     1019
     1020        /**
     1021         * Process the add menu item request response into menu list item. Prepends to menu.
     1022         *
     1023         * @param {string} menuMarkup The text server response of menu item markup.
     1024         *
     1025         * @fires document#menu-item-added Passes menuMarkup as a jQuery object.
     1026         */
    10171027        addMenuItemToTop : function( menuMarkup ) {
    1018             $(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
     1028            var $menuMarkup = $( menuMarkup );
     1029            $menuMarkup.hideAdvancedMenuItemFields().prependTo( api.targetList );
    10191030            api.refreshKeyboardAccessibility();
    10201031            api.refreshAdvancedAccessibility();
     1032            $( document ).trigger( 'menu-item-added', [ $menuMarkup ] );
    10211033        },
    10221034
     
    12441256        },
    12451257
     1258        /**
     1259         * Remove a menu item.
     1260         * @param  {object} el The element to be removed as a jQuery object.
     1261         *
     1262         * @fires document#menu-removing-item Passes the element to be removed.
     1263         */
    12461264        removeMenuItem : function(el) {
    12471265            var children = el.childMenuItems();
    12481266
     1267            $( document ).trigger( 'menu-removing-item', [ el ] );
    12491268            el.addClass('deleting').animate({
    12501269                    opacity : 0,
  • trunk/tests/qunit/index.html

    r39075 r39928  
    6767        <script src="wp-admin/js/customize-widgets.js"></script>
    6868        <script src="wp-admin/js/word-count.js"></script>
     69        <script src="wp-admin/js/nav-menu.js"></script>
    6970
    7071        <!-- Customizer templates for sections -->
Note: See TracChangeset for help on using the changeset viewer.