From f02fddce86726658342ad4c065d3afab188cd022 Mon Sep 17 00:00:00 2001 From: nacin Date: Mon, 17 May 2010 23:58:56 +0000 Subject: [PATCH] Save menu locations meta box via ajax. see #13378. git-svn-id: http://svn.automattic.com/wordpress/trunk@14715 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 8 ++++++++ wp-admin/includes/nav-menu.php | 1 - wp-admin/js/nav-menu.dev.js | 9 ++++++++- wp-admin/js/nav-menu.js | 2 +- wp-includes/script-loader.php | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 4790d16861..70f5d1b5f2 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -1103,6 +1103,14 @@ case 'menu-quick-search': exit; break; +case 'menu-locations-save': + if ( ! current_user_can( 'edit_theme_options' ) ) + die('-1'); + if ( ! isset( $_POST['menu-locations' ] ) ) + die('0'); + set_theme_mod( 'nav_menu_locations', $_POST['menu-locations'] ); + die('1'); + break; case 'meta-box-order': check_ajax_referer( 'meta-box-order' ); $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false; diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index 83677a352a..444c70756f 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -403,7 +403,6 @@ function wp_nav_menu_taxonomy_meta_boxes() { */ function wp_nav_menu_locations_meta_box() { $locations = get_registered_nav_menus(); - $mods = get_nav_menu_locations(); $menus = wp_get_nav_menus(); $menu_locations = get_nav_menu_locations(); diff --git a/wp-admin/js/nav-menu.dev.js b/wp-admin/js/nav-menu.dev.js index 1c0fa6ec08..9c2c3f6342 100644 --- a/wp-admin/js/nav-menu.dev.js +++ b/wp-admin/js/nav-menu.dev.js @@ -329,7 +329,7 @@ var wpNavMenu; }, attachAddMenuItemListeners : function() { - var form = $('#nav-menu-meta'); + var form = $('#nav-menu-meta'), loc = form.find('#nav-menu-theme-locations'); form.find('.add-to-menu input').click(function(){ $(this).trigger('wp-add-menu-item', [api.addMenuItemToBottom]); @@ -341,6 +341,13 @@ var wpNavMenu; form.find('.posttypediv, .taxonomydiv').bind('wp-add-menu-item', function(e, processMethod) { $(this).addSelectedToMenu( processMethod ); }); + loc.find('input[type=submit]').click(function() { + loc.find('.waiting').show(); + $.post( ajaxurl, loc.find('select').serialize() + '&action=menu-locations-save', function(r) { + loc.find('.waiting').hide(); + }); + return false; + }); }, attachQuickSearchListeners : function() { diff --git a/wp-admin/js/nav-menu.js b/wp-admin/js/nav-menu.js index f9a0f42984..5204896285 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,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 m=0,l,j,e,h,n,k,o,d,g,i=a.menuList.offset().left;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(w,v){var p,t,s,q,r,u;g=v.item.children(".menu-item-transport");l=v.item.menuItemDepth();f(v,l);s=(v.item.next()[0]==v.placeholder[0])?v.item.next():v.item;q=s.childMenuItems();g.append(q);p=g.outerHeight();p+=(p>0)?(v.placeholder.css("margin-top").slice(0,-2)*1):0;p+=v.helper.outerHeight();d=p;p-=2;v.placeholder.height(p);r=l;q.each(function(){var x=b(this).menuItemDepth();r=(x>r)?x:r});t=v.helper.find(".menu-item-handle").outerWidth();t+=a.depthToPx(r-l);t-=2;v.placeholder.width(t);u=v.placeholder.next();u.css("margin-top",d+"px");v.placeholder.detach();b(this).sortable("refresh");v.item.after(v.placeholder);u.css("margin-top",0);c(v)},stop:function(s,r){var q,p=m-l;q=g.children().insertAfter(r.item);if(p!=0){r.item.updateDepthClass(m);q.shiftDepthClass(p)}r.item.updateParentMenuItemDBId()},change:function(q,p){if(!p.placeholder.parent().hasClass("menu")){(h.length)?h.after(p.placeholder):a.menuList.prepend(p.placeholder)}c(p)},sort:function(q,p){var s=p.helper.offset(),r=a.pxToDepth(s.left-i);if(r>e||s.topo){n.after(p.placeholder);c(p);b(this).sortable("refreshPositions")}}});function c(p){var q;h=p.placeholder.prev();n=p.placeholder.next();if(h[0]==p.item[0]){h=h.prev()}if(n[0]==p.item[0]){n=n.next()}k=(h.length)?h.offset().top+h.height():0;o=(n.length)?n.offset().top+n.height()/3:0;j=(n.length)?n.menuItemDepth():0;if(h.length){e=((q=h.menuItemDepth()+1)>a.options.globalMaxDepth)?a.options.globalMaxDepth:q}else{e=0}}function f(p,q){p.placeholder.updateDepthClass(q,m);m=q}},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-save")){return c.eventOnClickMenuSave(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 c;b(".quick-search").keypress(function(f){var d=b(this);if(13==f.which){a.updateQuickSearchResults(d);return false}if(c){clearTimeout(c)}c=setTimeout(function(){a.updateQuickSearchResults(d)},400)}).attr("autocomplete","off")},updateQuickSearchResults:function(d){var c,g,e=2,f=d.val();if(f.lengthm){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('