diff --git a/wp-admin/js/nav-menu.dev.js b/wp-admin/js/nav-menu.dev.js index f1a1fb215e..512c3e3330 100644 --- a/wp-admin/js/nav-menu.dev.js +++ b/wp-admin/js/nav-menu.dev.js @@ -88,126 +88,6 @@ var wpNavMenu, WPNavMenuHandler = function ($) { menuList, targetList, api; - // jQuery extensions - $.fn.extend({ - menuItemDepth : function() { - return pxToDepth( this.eq(0).css('margin-left').slice(0, -2) ); - }, - updateDepthClass : function(current, prev) { - return this.each(function(){ - var t = $(this); - prev = prev || t.menuItemDepth(); - $(this).removeClass('menu-item-depth-'+ prev ) - .addClass('menu-item-depth-'+ current ); - }); - }, - shiftDepthClass : function(change) { - return this.each(function(){ - var t = $(this), - depth = t.menuItemDepth(); - $(this).removeClass('menu-item-depth-'+ depth ) - .addClass('menu-item-depth-'+ (depth + change) ); - }); - }, - childMenuItems : function() { - var result = $(); - this.each(function(){ - var t = $(this), depth = t.menuItemDepth(), next = t.next(); - while( next.length && next.menuItemDepth() > depth ) { - result = result.add( next ); - next = next.next(); - } - }); - return result; - }, - updateParentMenuItemDBId : function() { - return this.each(function(){ - var item = $(this), - input = item.find('.menu-item-data-parent-id'), - depth = item.menuItemDepth(), - parent = item.prev(); - - if( depth == 0 ) { // Item is on the top level, has no parent - input.val(0); - } else { // Find the parent item, and retrieve its object id. - while( parent.menuItemDepth() != depth - 1 ) { - parent = parent.prev(); - } - input.val( parent.find('.menu-item-data-db-id').val() ); - } - }); - }, - hideAdvancedMenuItemFields : function() { - return this.each(function(){ - var that = $(this); - $('.hide-column-tog').not(':checked').each(function(){ - that.find('.field-' + $(this).val() ).addClass('hidden-field'); - }); - }); - }, - selectItem : function() { - return this.each(function(){ - $(this).addClass('selected-menu-item') - .next().children('input').attr('checked','checked'); - }); - }, - deselectItem : function() { - return this.each(function(){ - $(this).removeClass('selected-menu-item') - .next().children('input').removeAttr('checked'); - }); - }, - toggleItem : function() { - return this.each(function(){ - var t = $(this); - if( t.hasClass('selected-menu-item') ) - t.deselectItem(); - else - t.selectItem(); - }); - }, - /** - * Adds selected menu items to the menu. - * - * @param jQuery metabox The metabox jQuery object. - */ - addSelectedToMenu : function(processMethod) { - return this.each(function() { - var t = $(this), - checked = t.find('.tabs-panel-active .categorychecklist li input:checked'), - re = new RegExp('menu-item\\[(\[^\\]\]*)'); - - processMethod = processMethod || api.addMenuItemToBottom; - - // If no items are checked, bail. - if ( !checked.length ) - return false; - - // Show the ajax spinner - t.find('img.waiting').show(); - - // Retrieve menu item data - $(checked).each(function(){ - var checkbox = $(this), - item = checkbox.parent().prev(); - listItemDBIDMatch = re.exec( checkbox.attr('name') ); - listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); - listItemData = getListDataFromID(listItemDBID); - - menuItem = {}; - menuItem[listItemDBID] = listItemData; - - api.addItemToMenu(menuItem, processMethod, function(){ - item.deselectItem(); - }); - }); - - // Remove the ajax spinner - t.find('img.waiting').hide(); - }); - }, - }); - return api = { // Functions that run on init. @@ -215,6 +95,8 @@ var wpNavMenu, WPNavMenuHandler = function ($) { menuList = $('#menu-to-edit'); targetList = menuList; + this.jQueryExtensions(); + this.attachMenuEditListeners(); this.setupInputWithDefaultTitle(); @@ -236,6 +118,122 @@ var wpNavMenu, WPNavMenuHandler = function ($) { this.checkForEmptyMenu(); }, + + jQueryExtensions : function() { + // jQuery extensions + $.fn.extend({ + menuItemDepth : function() { + return pxToDepth( this.eq(0).css('margin-left').slice(0, -2) ); + }, + updateDepthClass : function(current, prev) { + return this.each(function(){ + var t = $(this); + prev = prev || t.menuItemDepth(); + $(this).removeClass('menu-item-depth-'+ prev ) + .addClass('menu-item-depth-'+ current ); + }); + }, + shiftDepthClass : function(change) { + return this.each(function(){ + var t = $(this), + depth = t.menuItemDepth(); + $(this).removeClass('menu-item-depth-'+ depth ) + .addClass('menu-item-depth-'+ (depth + change) ); + }); + }, + childMenuItems : function() { + var result = $(); + this.each(function(){ + var t = $(this), depth = t.menuItemDepth(), next = t.next(); + while( next.length && next.menuItemDepth() > depth ) { + result = result.add( next ); + next = next.next(); + } + }); + return result; + }, + updateParentMenuItemDBId : function() { + return this.each(function(){ + var item = $(this), + input = item.find('.menu-item-data-parent-id'), + depth = item.menuItemDepth(), + parent = item.prev(); + + if( depth == 0 ) { // Item is on the top level, has no parent + input.val(0); + } else { // Find the parent item, and retrieve its object id. + while( parent.menuItemDepth() != depth - 1 ) { + parent = parent.prev(); + } + input.val( parent.find('.menu-item-data-db-id').val() ); + } + }); + }, + hideAdvancedMenuItemFields : function() { + return this.each(function(){ + var that = $(this); + $('.hide-column-tog').not(':checked').each(function(){ + that.find('.field-' + $(this).val() ).addClass('hidden-field'); + }); + }); + }, + selectItem : function() { + return this.each(function(){ + $(this).addClass('selected-menu-item') + .next().children('input').attr('checked','checked'); + }); + }, + deselectItem : function() { + return this.each(function(){ + $(this).removeClass('selected-menu-item') + .next().children('input').removeAttr('checked'); + }); + }, + toggleItem : function() { + return this.each(function(){ + var t = $(this); + if( t.hasClass('selected-menu-item') ) + t.deselectItem(); + else + t.selectItem(); + }); + }, + /** + * Adds selected menu items to the menu. + * + * @param jQuery metabox The metabox jQuery object. + */ + addSelectedToMenu : function(processMethod) { + return this.each(function() { + var t = $(this), menuItems = {}, + checkboxes = t.find('.tabs-panel-active .categorychecklist li input:checked'), + re = new RegExp('menu-item\\[(\[^\\]\]*)'); + + processMethod = processMethod || api.addMenuItemToBottom; + + // If no items are checked, bail. + if ( !checkboxes.length ) + return false; + + // Show the ajax spinner + t.find('img.waiting').show(); + + // Retrieve menu item data + $(checkboxes).each(function(){ + var listItemDBIDMatch = re.exec( $(this).attr('name') ), + listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); + menuItems[listItemDBID] = getListDataFromID(listItemDBID); + }); + // Add the items + api.addItemToMenu(menuItems, processMethod, function(){ + // Deselect the items and hide the ajax spinner + checkboxes.parent().prev().deselectItem(); + t.find('img.waiting').hide(); + }); + }); + }, + }); + }, initToggles : function() { // init postboxes diff --git a/wp-admin/js/nav-menu.js b/wp-admin/js/nav-menu.js index b3ea8ab97c..0c857ee37b 100644 --- a/wp-admin/js/nav-menu.js +++ b/wp-admin/js/nav-menu.js @@ -1 +1 @@ -var wpNavMenu,WPNavMenuHandler=function(d){var i={},g=30,c=11,l=function(n,r,o,q){if(n&&n[0]){var p=d.parseJSON(n[0]);if(p.post_title){if(p.ID&&p.post_type){i[p.post_title]={ID:p.ID,object_type:p.post_type}}return p.post_title}}},m=function(n,r,o,q){if(n&&n[0]){var p=d.parseJSON(n[0]);if(p.post_title){return p.post_title}}},b=function(t,s){if(!t){return false}s=s||document;var o=["menu-item-db-id","menu-item-object-id","menu-item-object","menu-item-parent-id","menu-item-position","menu-item-type","menu-item-append","menu-item-title","menu-item-url","menu-item-description","menu-item-attr-title","menu-item-target","menu-item-classes","menu-item-xfn"],n={},p=s.getElementsByTagName("input"),r=p.length,q;while(r--){q=o.length;while(q--){if(p[r]&&p[r].name&&"menu-item["+t+"]["+o[q]+"]"==p[r].name){n[o[q]]=p[r].value}}}return n},a=function(){h.find(".menu-item-data-position").val(function(n){return n+1})},f=function(n){return n*g},j=function(n){return Math.floor(n/g)},h,k,e;d.fn.extend({menuItemDepth:function(){return j(this.eq(0).css("margin-left").slice(0,-2))},updateDepthClass:function(o,n){return this.each(function(){var p=d(this);n=n||p.menuItemDepth();d(this).removeClass("menu-item-depth-"+n).addClass("menu-item-depth-"+o)})},shiftDepthClass:function(n){return this.each(function(){var o=d(this),p=o.menuItemDepth();d(this).removeClass("menu-item-depth-"+p).addClass("menu-item-depth-"+(p+n))})},childMenuItems:function(){var n=d();this.each(function(){var o=d(this),q=o.menuItemDepth(),p=o.next();while(p.length&&p.menuItemDepth()>q){n=n.add(p);p=p.next()}});return n},updateParentMenuItemDBId:function(){return this.each(function(){var p=d(this),n=p.find(".menu-item-data-parent-id"),q=p.menuItemDepth(),o=p.prev();if(q==0){n.val(0)}else{while(o.menuItemDepth()!=q-1){o=o.prev()}n.val(o.find(".menu-item-data-db-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var n=d(this);d(".hide-column-tog").not(":checked").each(function(){n.find(".field-"+d(this).val()).addClass("hidden-field")})})},selectItem:function(){return this.each(function(){d(this).addClass("selected-menu-item").next().children("input").attr("checked","checked")})},deselectItem:function(){return this.each(function(){d(this).removeClass("selected-menu-item").next().children("input").removeAttr("checked")})},toggleItem:function(){return this.each(function(){var n=d(this);if(n.hasClass("selected-menu-item")){n.deselectItem()}else{n.selectItem()}})},addSelectedToMenu:function(n){return this.each(function(){var o=d(this),q=o.find(".tabs-panel-active .categorychecklist li input:checked"),p=new RegExp("menu-item\\[([^\\]]*)");n=n||e.addMenuItemToBottom;if(!q.length){return false}o.find("img.waiting").show();d(q).each(function(){var s=d(this),r=s.parent().prev();listItemDBIDMatch=p.exec(s.attr("name"));listItemDBID="undefined"==typeof listItemDBIDMatch[1]?0:parseInt(listItemDBIDMatch[1],10);listItemData=b(listItemDBID);menuItem={};menuItem[listItemDBID]=listItemData;e.addItemToMenu(menuItem,n,function(){r.deselectItem()})});o.find("img.waiting").hide()})},});return e={init:function(){h=d("#menu-to-edit");k=h;this.attachMenuEditListeners();this.setupInputWithDefaultTitle();this.attachAddMenuItemListeners();this.attachQuickSearchListeners();this.attachTabsPanelListeners();this.attachHomeLinkListener();if(h.length){this.initSortables()}this.initToggles();this.initTabManager();this.initAddMenuItemDraggables();this.checkForEmptyMenu()},initToggles:function(){postboxes.add_postbox_toggles("nav-menus");columns.useCheckboxesForHidden();columns.checked=function(n){d(".field-"+n).removeClass("hidden-field")};columns.unchecked=function(n){d(".field-"+n).addClass("hidden-field")};h.hideAdvancedMenuItemFields()},initSortables:function(){var t=0,s,r,n,q=h.offset().left,u,p;h.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(C,B){var w,A,z,x,y;p=B.item.children(".menu-item-transport");u=(B.helper.hasClass("new-menu-item"));s=(u)?0:B.item.menuItemDepth();o(B,s);if(!u){z=(B.item.next()[0]==B.placeholder[0])?B.item.next():B.item;x=z.childMenuItems();p.append(x)}v(B);w=p.outerHeight();w+=(w>0)?(B.placeholder.css("margin-top").slice(0,-2)*1):0;w+=B.helper.outerHeight();w-=2;B.placeholder.height(w);y=s;if(!u){x.each(function(){var D=d(this).menuItemDepth();y=(D>y)?D:y})}A=B.helper.find(".menu-item-handle").outerWidth();A+=f(y-s);A-=2;B.placeholder.width(A)},stop:function(z,y){var x,w=t-s;x=p.children().insertAfter(y.item);if(u){y.item.remove();if(w!=0){x.shiftDepthClass(w)}x.updateParentMenuItemDBId()}else{if(w!=0){y.item.updateDepthClass(t);x.shiftDepthClass(w)}y.item.updateParentMenuItemDBId()}a()},change:function(x,w){if(!w.placeholder.parent().hasClass("menu")){w.placeholder.appendTo(h)}v(w)},sort:function(x,w){var y=j(w.helper.offset().left-q);if(yn){y=n}}if(y!=t){o(w,y)}},receive:function(x,w){p=w.sender.children(".menu-item-transport")}});function v(y){var x=y.placeholder.prev(),w=y.placeholder.next(),z;if(x[0]==y.item[0]){x=x.prev()}if(w[0]==y.item[0]){w=w.next()}r=(w.length)?w.menuItemDepth():0;if(x.length){n=((z=x.menuItemDepth()+1)>c)?c:z}else{n=0}}function o(w,x){w.placeholder.updateDepthClass(x,t);t=x}},initAddMenuItemDraggables:function(){var n=d(".potential-menu-item");n.click(function(o){d(this).toggleItem()}).children().draggable({helper:"clone",connectToSortable:"ul#menu-to-edit",distance:5,zIndex:100,start:function(t,r){var s=d(t.target),q=s.parent(),o=q.parent(),p;q.selectItem();k=s.children(".menu-item-transport");p=o.parents(".tabs-panel").find(".selected-menu-item").children().not(r.helper).clone();r.helper.children(".additional-menu-items").append(p);r.helper.addClass("new-menu-item");r.helper.children("div").hide();p.first().css("margin-top",0);p.children("div").addClass("menu-item-handle");r.helper.children("div").addClass("hidden-handle");o.parents(".inside").find(".add-to-menu input").click();r.helper.width(r.helper.width());r.helper.height(r.helper.height())},stop:function(p,o){k=h;d(p.target).parents(".tabs-panel").find(".selected-menu-item").deselectItem()}})},attachMenuEditListeners:function(){var n=this;d("#update-nav-menu").bind("click",function(o){if(o.target&&o.target.className){if(-1!=o.target.className.indexOf("item-edit")){return n.eventOnClickEditLink(o.target)}else{if(-1!=o.target.className.indexOf("menu-delete")){return n.eventOnClickMenuDelete(o.target)}else{if(-1!=o.target.className.indexOf("item-delete")){return n.eventOnClickMenuItemDelete(o.target)}else{if(-1!=o.target.className.indexOf("item-close")){return n.eventOnClickCloseLink(o.target)}}}}}})},setupInputWithDefaultTitle:function(){var n="input-with-default-title";d("."+n).each(function(){var q=d(this),p=q.attr("title"),o=q.val();q.data(n,p);if(""==o){q.val(p)}else{if(p==o){return}else{q.removeClass(n)}}}).focus(function(){var o=d(this);if(o.val()==o.data(n)){o.val("").removeClass(n)}}).blur(function(){var o=d(this);if(""==o.val()){o.addClass(n).val(o.data(n))}})},attachAddMenuItemListeners:function(){var n=d("#nav-menu-meta");n.find(".add-to-menu input").click(function(){d(this).trigger("wp-add-menu-item",[e.addMenuItemToBottom]);return false});n.find(".customlinkdiv").bind("wp-add-menu-item",function(p,o){e.addCustomLink(o)});n.find(".posttypediv, .taxonomydiv").bind("wp-add-menu-item",function(p,o){d(this).addSelectedToMenu(o)})},attachQuickSearchListeners:function(){var o=this,n=d("#nav-menu-meta");d("input.quick-search").each(function(p,q){o.setupQuickSearchEventListeners(q)});n.find(".quick-search-submit").click(function(){d(this).trigger("wp-quick-search");return false});n.find(".inside").children().bind("wp-quick-search",function(){o.quickSearch(d(this).attr("id"))})},quickSearch:function(v){var p=d("#"+v+" .quick-search").attr("name"),s=d("#"+v+" .quick-search").val(),u=d("#menu").val(),o=d("#menu-settings-column-nonce").val(),t={},r=this,n=function(){};n=r.processQuickSearchQueryResponse;t={action:"menu-quick-search","response-format":"markup",menu:u,"menu-settings-column-nonce":o,q:s,type:p};d.post(ajaxurl,t,function(q){n.call(r,q,t)})},addCustomLink:function(n){var p=d("#custom-menu-item-url").val(),o=d("#custom-menu-item-name").val();n=n||e.addMenuItemToBottom;if(""==p||"http://"==p){return false}d(".customlinkdiv img.waiting").show();this.addLinkToMenu(p,o,n,function(){d(".customlinkdiv img.waiting").hide();d("#custom-menu-item-name").val("").blur();d("#custom-menu-item-url").val("http://")})},addLinkToMenu:function(p,o,n,q){n=n||e.addMenuItemToBottom;q=q||function(){};e.addItemToMenu({"-1":{"menu-item-type":"custom","menu-item-url":p,"menu-item-title":o}},n,q)},addItemToMenu:function(p,n,r){var q=d("#menu").val(),o=d("#menu-settings-column-nonce").val();n=n||function(){};r=r||function(){};params={action:"add-menu-item",menu:q,"menu-settings-column-nonce":o,"menu-item":p,};d.post(ajaxurl,params,function(s){n(s,params);r()})},addMenuItemToBottom:function(n,o){d(n).hideAdvancedMenuItemFields().appendTo(k)},addMenuItemToTop:function(n,o){d(n).hideAdvancedMenuItemFields().prependTo(k)},attachHomeLinkListener:function(){d(".add-home-link",".customlinkdiv").click(function(n){e.addLinkToMenu(navMenuL10n.homeurl,navMenuL10n.home,e.addMenuItemToTop,a);return false})},attachTabsPanelListeners:function(){d("#menu-settings-column").bind("click",function(r){var q,s,o,t,n,p;if(r.target&&r.target.className&&-1!=r.target.className.indexOf("nav-tab-link")){o=/#(.*)$/.exec(r.target.href);t=d(r.target).parents(".inside").first()[0];n=t?t.getElementsByTagName("input"):[];p=n.length;while(p--){n[p].checked=false}d(".tabs-panel",t).each(function(){if(this.className){this.className=this.className.replace("tabs-panel-active","tabs-panel-inactive")}});d(".tabs",t).each(function(){this.className=this.className.replace("tabs","")});r.target.parentNode.className+=" tabs";if(o&&o[1]){s=document.getElementById(o[1]);if(s){s.className=s.className.replace("tabs-panel-inactive","tabs-panel-active")}}return false}else{if(r.target&&r.target.className&&-1!=r.target.className.indexOf("select-all")){q=/#(.*)$/.exec(r.target.href),items;if(q&&q[1]){items=d("#"+q[1]+" .tabs-panel-active .potential-menu-item");if(items.length===items.filter(".selected-menu-item").length){items.deselectItem()}else{items.selectItem()}return false}}}})},initTabManager:function(){var s=d(".nav-tabs-wrapper"),t=s.children(".nav-tabs"),r=t.children(".nav-tab-active"),v=t.children(".nav-tab"),p=0,w,q,u,o;resizing=false;function n(){q=s.offset().left;w=q+s.width();r.makeTabVisible()}d.fn.extend({makeTabVisible:function(){var y=this.eq(0),z,x;if(!y.length){return}z=y.offset().left;x=z+y.outerWidth();if(x>w){t.animate({"margin-left":"+="+(w-x)+"px",},"fast")}else{if(z=q)?true:false}});v.each(function(){p+=d(this).outerWidth(true)});if(p<=s.width()-t.css("padding-left").slice(0,-2)-t.css("padding-right").slice(0,-2)){return}t.css({"margin-right":(-1*p)+"px",padding:0,});u=d('');o=d('');s.wrap('