]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/nav-menu.js
WordPress 4.3
[autoinstalls/wordpress.git] / wp-admin / js / nav-menu.js
index efebce4fbe66be87fe197d2beab13f300af19725..c23fc69683a88799b7e5509dc1655873cbe4c135 100644 (file)
@@ -20,7 +20,9 @@ var wpNavMenu;
 
                options : {
                        menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
-                       globalMaxDepth : 11
+                       globalMaxDepth:  11,
+                       sortableItems:   '> *',
+                       targetTolerance: 0
                },
 
                menuList : undefined,   // Set in init.
@@ -87,10 +89,10 @@ var wpNavMenu;
                                childMenuItems : function() {
                                        var result = $();
                                        this.each(function(){
-                                               var t = $(this), depth = t.menuItemDepth(), next = t.next();
+                                               var t = $(this), depth = t.menuItemDepth(), next = t.next( '.menu-item' );
                                                while( next.length && next.menuItemDepth() > depth ) {
                                                        result = result.add( next );
-                                                       next = next.next();
+                                                       next = next.next( '.menu-item' );
                                                }
                                        });
                                        return result;
@@ -388,11 +390,11 @@ var wpNavMenu;
 
                        // Refresh the accessibility when the user comes close to the item in any way
                        menu.on( 'mouseenter.refreshAccessibility focus.refreshAccessibility touchstart.refreshAccessibility' , '.menu-item' , function(){
-                               api.refreshAdvancedAccessibilityOfItem( $( this ).find( '.item-edit' ) );
+                               api.refreshAdvancedAccessibilityOfItem( $( this ).find( 'a.item-edit' ) );
                        } );
 
                        // We have to update on click as well because we might hover first, change the item, and then click.
-                       menu.on( 'click', '.item-edit', function() {
+                       menu.on( 'click', 'a.item-edit', function() {
                                api.refreshAdvancedAccessibilityOfItem( $( this ) );
                        } );
 
@@ -437,7 +439,7 @@ var wpNavMenu;
                                totalMenuItems = $('#menu-to-edit li').length,
                                hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length;
 
-                               menuItem.find( '.field-move' ).toggle( totalMenuItems > 1 ); 
+                               menuItem.find( '.field-move' ).toggle( totalMenuItems > 1 );
 
                        // Where can they move this menu item?
                        if ( 0 !== position ) {
@@ -509,16 +511,16 @@ var wpNavMenu;
                        $( '.menu-item-settings .field-move a' ).hide();
 
                        // Mark all menu items as unprocessed
-                       $( '.item-edit' ).data( 'needs_accessibility_refresh', true );
+                       $( 'a.item-edit' ).data( 'needs_accessibility_refresh', true );
 
                        // All open items have to be refreshed or they will show no links
-                       $( '.menu-item-edit-active .item-edit' ).each( function() {
+                       $( '.menu-item-edit-active a.item-edit' ).each( function() {
                                api.refreshAdvancedAccessibilityOfItem( this );
                        } );
                },
 
                refreshKeyboardAccessibility : function() {
-                       $( '.item-edit' ).off( 'focus' ).on( 'focus', function(){
+                       $( 'a.item-edit' ).off( 'focus' ).on( 'focus', function(){
                                $(this).off( 'keydown' ).on( 'keydown', function(e){
 
                                        var arrows,
@@ -620,6 +622,7 @@ var wpNavMenu;
                        api.menuList.sortable({
                                handle: '.menu-item-handle',
                                placeholder: 'sortable-placeholder',
+                               items: api.options.sortableItems,
                                start: function(e, ui) {
                                        var height, width, parent, children, tempHolder;
 
@@ -660,7 +663,7 @@ var wpNavMenu;
                                        ui.placeholder.width(width);
 
                                        // Update the list of menu items.
-                                       tempHolder = ui.placeholder.next();
+                                       tempHolder = ui.placeholder.next( '.menu-item' );
                                        tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder
                                        ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item
                                        $(this).sortable( 'refresh' ); // The children aren't sortable. We should let jQ UI know.
@@ -719,11 +722,15 @@ var wpNavMenu;
                                        var offset = ui.helper.offset(),
                                                edge = api.isRTL ? offset.left + ui.helper.width() : offset.left,
                                                depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge );
+
                                        // Check and correct if depth is not within range.
                                        // Also, if the dragged element is dragged upwards over
                                        // an item, shift the placeholder to a child position.
-                                       if ( depth > maxDepth || offset.top < prevBottom ) depth = maxDepth;
-                                       else if ( depth < minDepth ) depth = minDepth;
+                                       if ( depth > maxDepth || offset.top < ( prevBottom - api.options.targetTolerance ) ) {
+                                               depth = maxDepth;
+                                       } else if ( depth < minDepth ) {
+                                               depth = minDepth;
+                                       }
 
                                        if( depth != currentDepth )
                                                updateCurrentDepth(ui, depth);
@@ -740,12 +747,12 @@ var wpNavMenu;
                        function updateSharedVars(ui) {
                                var depth;
 
-                               prev = ui.placeholder.prev();
-                               next = ui.placeholder.next();
+                               prev = ui.placeholder.prev( '.menu-item' );
+                               next = ui.placeholder.next( '.menu-item' );
 
                                // Make sure we don't select the moving item.
-                               if( prev[0] == ui.item[0] ) prev = prev.prev();
-                               if( next[0] == ui.item[0] ) next = next.next();
+                               if( prev[0] == ui.item[0] ) prev = prev.prev( '.menu-item' );
+                               if( next[0] == ui.item[0] ) next = next.next( '.menu-item' );
 
                                prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0;
                                nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0;
@@ -817,6 +824,8 @@ var wpNavMenu;
                                }
                        });
                        $('#add-custom-links input[type="text"]').keypress(function(e){
+                               $('#customlinkdiv').removeClass('form-invalid');
+
                                if ( e.keyCode === 13 ) {
                                        e.preventDefault();
                                        $( '#submit-customlinkdiv' ).click();
@@ -919,8 +928,10 @@ var wpNavMenu;
 
                        processMethod = processMethod || api.addMenuItemToBottom;
 
-                       if ( '' === url || 'http://' == url )
+                       if ( '' === url || 'http://' == url ) {
+                               $('#customlinkdiv').addClass('form-invalid');
                                return false;
+                       }
 
                        // Show the ajax spinner
                        $( '.customlinkdiv .spinner' ).addClass( 'is-active' );