diff --git a/wp-admin/js/nav-menu.dev.js b/wp-admin/js/nav-menu.dev.js index 8ec6f37671..6fd34b7238 100644 --- a/wp-admin/js/nav-menu.dev.js +++ b/wp-admin/js/nav-menu.dev.js @@ -161,20 +161,20 @@ var wpNavMenu; }, initSortables : function() { - var currentDepth = 0, originalDepth, minDepth, maxDepth, prevBottom, - menuLeft = api.menuList.offset().left, - newItem, transport; + var currentDepth = 0, originalDepth, minDepth, maxDepth, + prev, next, prevBottom, nextThreshold, helperHeight, transport, + menuLeft = api.menuList.offset().left; api.menuList.sortable({ handle: '.menu-item-handle', placeholder: 'sortable-placeholder', start: function(e, ui) { - var height, width, parent, children, maxChildDepth; + var height, width, parent, children, maxChildDepth, tempHolder; transport = ui.item.children('.menu-item-transport'); // Set depths. currentDepth must be set before children are located. - originalDepth = ( newItem ) ? 0 : ui.item.menuItemDepth(); + originalDepth = ui.item.menuItemDepth(); updateCurrentDepth(ui, originalDepth); // Attach child elements to parent @@ -183,14 +183,12 @@ var wpNavMenu; children = parent.childMenuItems(); transport.append( children ); - // Now that the element is complete, we can update... - updateDepthRange(ui); - // Update the height of the placeholder to match the moving item. height = transport.outerHeight(); // If there are children, account for distance between top of children and parent height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0; height += ui.helper.outerHeight(); + helperHeight = height; height -= 2; // Subtract 2 for borders ui.placeholder.height(height); @@ -204,6 +202,17 @@ var wpNavMenu; width += api.depthToPx(maxChildDepth - originalDepth); // Account for children width -= 2; // Subtract 2 for borders ui.placeholder.width(width); + + // Update the list of menu items. + tempHolder = ui.placeholder.next(); + 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. + ui.item.after( ui.placeholder ); // reattach the placeholder. + tempHolder.css('margin-top', 0); // reset the margin + + // Now that the element is complete, we can update... + updateSharedVars(ui); }, stop: function(e, ui) { var children, depthChange = currentDepth - originalDepth; @@ -225,9 +234,9 @@ var wpNavMenu; // Make sure the placeholder is inside the menu. // Otherwise fix it, or we're in trouble. if( ! ui.placeholder.parent().hasClass('menu') ) - ui.placeholder.appendTo(api.menuList); + (prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder ); - updateDepthRange(ui); + updateSharedVars(ui); }, sort: function(e, ui) { var offset = ui.helper.offset(), @@ -240,18 +249,28 @@ var wpNavMenu; if( depth != currentDepth ) updateCurrentDepth(ui, depth); + + // If we overlap the next element, manually shift downwards + if( nextThreshold && offset.top + helperHeight > nextThreshold ) { + next.after( ui.placeholder ); + updateSharedVars( ui ); + $(this).sortable( "refreshPositions" ); + } } }); - function updateDepthRange(ui) { - var prev = ui.placeholder.prev(), - next = ui.placeholder.next(), depth; + function updateSharedVars(ui) { + var depth; + + prev = ui.placeholder.prev(); + next = ui.placeholder.next(); // 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(); prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0; + nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0; minDepth = (next.length) ? next.menuItemDepth() : 0; if( prev.length ) diff --git a/wp-admin/js/nav-menu.js b/wp-admin/js/nav-menu.js index 8bcfad021c..38214759c5 100644 --- a/wp-admin/js/nav-menu.js +++ b/wp-admin/js/nav-menu.js @@ -1 +1 @@ -var wpNavMenu;(function(b){var a=wpNavMenu={options:{menuItemDepthPerLevel:30,globalMaxDepth:11},menuList:undefined,targetList:undefined,autoCompleteData:{},init:function(){a.menuList=b("#menu-to-edit");a.targetList=a.menuList;this.jQueryExtensions();this.attachMenuEditListeners();this.setupInputWithDefaultTitle();this.attachAddMenuItemListeners();this.attachQuickSearchListeners();this.attachTabsPanelListeners();this.attachHomeLinkListener();if(a.menuList.length){this.initSortables()}this.initToggles();this.initTabManager()},jQueryExtensions:function(){b.fn.extend({menuItemDepth:function(){return a.pxToDepth(this.eq(0).css("margin-left").slice(0,-2))},updateDepthClass:function(d,c){return this.each(function(){var e=b(this);c=c||e.menuItemDepth();b(this).removeClass("menu-item-depth-"+c).addClass("menu-item-depth-"+d)})},shiftDepthClass:function(c){return this.each(function(){var d=b(this),e=d.menuItemDepth();b(this).removeClass("menu-item-depth-"+e).addClass("menu-item-depth-"+(e+c))})},childMenuItems:function(){var c=b();this.each(function(){var d=b(this),f=d.menuItemDepth(),e=d.next();while(e.length&&e.menuItemDepth()>f){c=c.add(e);e=e.next()}});return c},updateParentMenuItemDBId:function(){return this.each(function(){var e=b(this),c=e.find(".menu-item-data-parent-id"),f=e.menuItemDepth(),d=e.prev();if(f==0){c.val(0)}else{while(d.menuItemDepth()!=f-1){d=d.prev()}c.val(d.find(".menu-item-data-db-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var c=b(this);b(".hide-column-tog").not(":checked").each(function(){c.find(".field-"+b(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(c){return this.each(function(){var e=b(this),d={},g=e.find(".tabs-panel-active .categorychecklist li input:checked"),f=new RegExp("menu-item\\[([^\\]]*)");c=c||a.addMenuItemToBottom;if(!g.length){return false}e.find("img.waiting").show();b(g).each(function(){var h=f.exec(b(this).attr("name")),i="undefined"==typeof h[1]?0:parseInt(h[1],10);d[i]=a.getListDataFromID(i)});a.addItemToMenu(d,c,function(){g.removeAttr("checked");e.find("img.waiting").hide()})})}})},initToggles:function(){postboxes.add_postbox_toggles("nav-menus");columns.useCheckboxesForHidden();columns.checked=function(c){b(".field-"+c).removeClass("hidden-field")};columns.unchecked=function(c){b(".field-"+c).addClass("hidden-field")};a.menuList.hideAdvancedMenuItemFields()},initSortables:function(){var j=0,i,g,c,h,f=a.menuList.offset().left,k,e;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(s,r){var m,q,p,n,o;e=r.item.children(".menu-item-transport");i=(k)?0:r.item.menuItemDepth();d(r,i);p=(r.item.next()[0]==r.placeholder[0])?r.item.next():r.item;n=p.childMenuItems();e.append(n);l(r);m=e.outerHeight();m+=(m>0)?(r.placeholder.css("margin-top").slice(0,-2)*1):0;m+=r.helper.outerHeight();m-=2;r.placeholder.height(m);o=i;n.each(function(){var t=b(this).menuItemDepth();o=(t>o)?t:o});q=r.helper.find(".menu-item-handle").outerWidth();q+=a.depthToPx(o-i);q-=2;r.placeholder.width(q)},stop:function(p,o){var n,m=j-i;n=e.children().insertAfter(o.item);if(m!=0){o.item.updateDepthClass(j);n.shiftDepthClass(m)}o.item.updateParentMenuItemDBId();a.recalculateMenuItemPositions()},change:function(n,m){if(!m.placeholder.parent().hasClass("menu")){m.placeholder.appendTo(a.menuList)}l(m)},sort:function(n,m){var p=m.helper.offset(),o=a.pxToDepth(p.left-f);if(o>c||p.topa.options.globalMaxDepth)?a.options.globalMaxDepth:p}else{c=0}}function d(m,n){m.placeholder.updateDepthClass(n,j);j=n}},attachMenuEditListeners:function(){var c=this;b("#update-nav-menu").bind("click",function(d){if(d.target&&d.target.className){if(-1!=d.target.className.indexOf("item-edit")){return c.eventOnClickEditLink(d.target)}else{if(-1!=d.target.className.indexOf("menu-delete")){return c.eventOnClickMenuDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-delete")){return c.eventOnClickMenuItemDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-close")){return c.eventOnClickCloseLink(d.target)}}}}}})},setupInputWithDefaultTitle:function(){var c="input-with-default-title";b("."+c).each(function(){var f=b(this),e=f.attr("title"),d=f.val();f.data(c,e);if(""==d){f.val(e)}else{if(e==d){return}else{f.removeClass(c)}}}).focus(function(){var d=b(this);if(d.val()==d.data(c)){d.val("").removeClass(c)}}).blur(function(){var d=b(this);if(""==d.val()){d.addClass(c).val(d.data(c))}})},attachAddMenuItemListeners:function(){var c=b("#nav-menu-meta");c.find(".add-to-menu input").click(function(){b(this).trigger("wp-add-menu-item",[a.addMenuItemToBottom]);return false});c.find(".customlinkdiv").bind("wp-add-menu-item",function(f,d){a.addCustomLink(d)});c.find(".posttypediv, .taxonomydiv").bind("wp-add-menu-item",function(f,d){b(this).addSelectedToMenu(d)})},attachQuickSearchListeners:function(){var d=this,c=b("#nav-menu-meta");b("input.quick-search").each(function(e,f){d.setupQuickSearchEventListeners(f)});c.find(".quick-search-submit").click(function(){b(this).trigger("wp-quick-search");return false});c.find(".inside").children().bind("wp-quick-search",function(){d.quickSearch(b(this).attr("id"))})},quickSearch:function(j){var e=b("#"+j+" .quick-search").attr("name"),g=b("#"+j+" .quick-search").val(),i=b("#menu").val(),d=b("#menu-settings-column-nonce").val(),h={},f=this,c=function(){};c=f.processQuickSearchQueryResponse;h={action:"menu-quick-search","response-format":"markup",menu:i,"menu-settings-column-nonce":d,q:g,type:e};b.post(ajaxurl,h,function(k){c.call(f,k,h)})},addCustomLink:function(c){var e=b("#custom-menu-item-url").val(),d=b("#custom-menu-item-name").val();c=c||a.addMenuItemToBottom;if(""==e||"http://"==e){return false}b(".customlinkdiv img.waiting").show();this.addLinkToMenu(e,d,c,function(){b(".customlinkdiv img.waiting").hide();b("#custom-menu-item-name").val("").blur();b("#custom-menu-item-url").val("http://")})},addLinkToMenu:function(e,d,c,f){c=c||a.addMenuItemToBottom;f=f||function(){};a.addItemToMenu({"-1":{"menu-item-type":"custom","menu-item-url":e,"menu-item-title":d}},c,f)},addItemToMenu:function(e,c,g){var f=b("#menu").val(),d=b("#menu-settings-column-nonce").val();c=c||function(){};g=g||function(){};params={action:"add-menu-item",menu:f,"menu-settings-column-nonce":d,"menu-item":e};b.post(ajaxurl,params,function(h){c(h,params);g()})},addMenuItemToBottom:function(c,d){b(c).hideAdvancedMenuItemFields().appendTo(a.targetList)},addMenuItemToTop:function(c,d){b(c).hideAdvancedMenuItemFields().prependTo(a.targetList)},attachHomeLinkListener:function(){b(".add-home-link",".customlinkdiv").click(function(c){a.addLinkToMenu(navMenuL10n.homeurl,navMenuL10n.home,a.addMenuItemToTop,a.recalculateMenuItemPositions);return false})},attachTabsPanelListeners:function(){b("#menu-settings-column").bind("click",function(j){var h,k,d,l,c,g,f;if(j.target&&j.target.className&&-1!=j.target.className.indexOf("nav-tab-link")){d=/#(.*)$/.exec(j.target.href);l=b(j.target).parents(".inside").first()[0];c=l?l.getElementsByTagName("input"):[];g=c.length;while(g--){c[g].checked=false}b(".tabs-panel",l).each(function(){if(this.className){this.className=this.className.replace("tabs-panel-active","tabs-panel-inactive")}});b(".tabs",l).each(function(){this.className=this.className.replace("tabs","")});j.target.parentNode.className+=" tabs";if(d&&d[1]){k=document.getElementById(d[1]);if(k){k.className=k.className.replace("tabs-panel-inactive","tabs-panel-active")}}return false}else{if(j.target&&j.target.className&&-1!=j.target.className.indexOf("select-all")){h=/#(.*)$/.exec(j.target.href);if(h&&h[1]){f=b("#"+h[1]+" .tabs-panel-active .menu-item-title input");if(f.length===f.filter(":checked").length){f.removeAttr("checked")}else{f.attr("checked","checked")}return false}}}})},initTabManager:function(){var h=b(".nav-tabs-wrapper"),i=h.children(".nav-tabs"),g=i.children(".nav-tab-active"),l=i.children(".nav-tab"),e=0,m,f,k,d,j=false;function c(){f=h.offset().left;m=f+h.width();g.makeTabVisible()}b.fn.extend({makeTabVisible:function(){var o=this.eq(0),p,n;if(!o.length){return}p=o.offset().left;n=p+o.outerWidth();if(n>m){i.animate({"margin-left":"+="+(m-n)+"px"},"fast")}else{if(p=f)?true:false}});l.each(function(){e+=b(this).outerWidth(true)});if(e<=h.width()-i.css("padding-left").slice(0,-2)-i.css("padding-right").slice(0,-2)){return}i.css({"margin-right":(-1*e)+"px",padding:0});k=b('');d=b('');h.wrap('