From d1bedc6769962f9fc2f5e3362f47a73aeaf90be3 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 1 Jul 2015 16:43:02 +0000 Subject: [PATCH] Customizer: Make reordering menu items via drag and drop easier. Introduce `wpNavMenu.options.targetTolerance` to define a tolerance when dragging items where no margins between the sortable items exists. props adamsilverstein. fixes #32821. git-svn-id: https://develop.svn.wordpress.org/trunk@33030 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-nav-menus.js | 1 + src/wp-admin/js/nav-menu.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js index e707e4d34f..ee1e7b96f0 100644 --- a/src/wp-admin/js/customize-nav-menus.js +++ b/src/wp-admin/js/customize-nav-menus.js @@ -8,6 +8,7 @@ wpNavMenu.originalInit = wpNavMenu.init; wpNavMenu.options.menuItemDepthPerLevel = 20; wpNavMenu.options.sortableItems = '> .customize-control-nav_menu_item'; + wpNavMenu.options.targetTolerance = 10; wpNavMenu.init = function() { this.jQueryExtensions(); }; diff --git a/src/wp-admin/js/nav-menu.js b/src/wp-admin/js/nav-menu.js index b9a5aea633..b8bae1e747 100644 --- a/src/wp-admin/js/nav-menu.js +++ b/src/wp-admin/js/nav-menu.js @@ -20,8 +20,9 @@ var wpNavMenu; options : { menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead. - globalMaxDepth : 11, - sortableItems: '> *' + globalMaxDepth: 11, + sortableItems: '> *', + targetTolerance: 0 }, menuList : undefined, // Set in init. @@ -438,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 ) { @@ -721,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);