options : {
menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
- globalMaxDepth : 11
+ globalMaxDepth: 11,
+ sortableItems: '> *',
+ targetTolerance: 0
},
menuList : undefined, // Set in init.
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;
// 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 ) );
} );
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 ) {
$( '.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,
api.menuList.sortable({
handle: '.menu-item-handle',
placeholder: 'sortable-placeholder',
+ items: api.options.sortableItems,
start: function(e, ui) {
var height, width, parent, children, tempHolder;
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.
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);
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;
}
});
$('#add-custom-links input[type="text"]').keypress(function(e){
+ $('#customlinkdiv').removeClass('form-invalid');
+
if ( e.keyCode === 13 ) {
e.preventDefault();
$( '#submit-customlinkdiv' ).click();
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' );