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.
Built from https://develop.svn.wordpress.org/trunk@33030


git-svn-id: http://core.svn.wordpress.org/trunk@33001 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2015-07-01 16:44:24 +00:00
parent b837d374bf
commit 78167b8a4c
5 changed files with 15 additions and 9 deletions

View File

@ -8,6 +8,7 @@
wpNavMenu.originalInit = wpNavMenu.init; wpNavMenu.originalInit = wpNavMenu.init;
wpNavMenu.options.menuItemDepthPerLevel = 20; wpNavMenu.options.menuItemDepthPerLevel = 20;
wpNavMenu.options.sortableItems = '> .customize-control-nav_menu_item'; wpNavMenu.options.sortableItems = '> .customize-control-nav_menu_item';
wpNavMenu.options.targetTolerance = 10;
wpNavMenu.init = function() { wpNavMenu.init = function() {
this.jQueryExtensions(); this.jQueryExtensions();
}; };

File diff suppressed because one or more lines are too long

View File

@ -20,8 +20,9 @@ var wpNavMenu;
options : { options : {
menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead. menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
globalMaxDepth : 11, globalMaxDepth: 11,
sortableItems: '> *' sortableItems: '> *',
targetTolerance: 0
}, },
menuList : undefined, // Set in init. menuList : undefined, // Set in init.
@ -438,7 +439,7 @@ var wpNavMenu;
totalMenuItems = $('#menu-to-edit li').length, totalMenuItems = $('#menu-to-edit li').length,
hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).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? // Where can they move this menu item?
if ( 0 !== position ) { if ( 0 !== position ) {
@ -721,11 +722,15 @@ var wpNavMenu;
var offset = ui.helper.offset(), var offset = ui.helper.offset(),
edge = api.isRTL ? offset.left + ui.helper.width() : offset.left, edge = api.isRTL ? offset.left + ui.helper.width() : offset.left,
depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge ); depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge );
// Check and correct if depth is not within range. // Check and correct if depth is not within range.
// Also, if the dragged element is dragged upwards over // Also, if the dragged element is dragged upwards over
// an item, shift the placeholder to a child position. // an item, shift the placeholder to a child position.
if ( depth > maxDepth || offset.top < prevBottom ) depth = maxDepth; if ( depth > maxDepth || offset.top < ( prevBottom - api.options.targetTolerance ) ) {
else if ( depth < minDepth ) depth = minDepth; depth = maxDepth;
} else if ( depth < minDepth ) {
depth = minDepth;
}
if( depth != currentDepth ) if( depth != currentDepth )
updateCurrentDepth(ui, depth); updateCurrentDepth(ui, depth);

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-33029'; $wp_version = '4.3-alpha-33030';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.