WordPress/wp-admin/js/nav-menu.js

1 line
11 KiB
JavaScript
Raw Normal View History

var wpNavMenu;(function(a){wpNavMenu={init:function(){wpNavMenu.initial_meta_boxes();wpNavMenu.drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#update-nav-menu").submit(function(){wpNavMenu.update_post_data()});a("#create-menu-name").keypress(function(b){if(13==b.keyCode){a("#create-menu-button").click();return false}});a("#custom-menu-item-url, #custom-menu-item-name").keypress(function(b){if(13==b.keyCode){a("#add-custom-links a.button").click();return false}}).focus(function(){if(a(this).val()==a(this).attr("defaultValue")&&a(this).attr("id")!="custom-menu-item-url"){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});a("#create-menu-name").focus(function(){if(a(this).val()==a(this).attr("defaultValue")){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});a(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("nav-menus");a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){wpNavMenu.edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").click(function(){wpNavMenu.remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wpNavMenu.update_menu_item();tb_remove()});a("#cancel-save").click(function(){tb_remove()});a(".show-all").click(function(b){a(b.currentTarget).parent().parent().siblings(".list-wrap").css("display","block");a(b.currentTarget).parent().parent().siblings(".list-wrap").find("li").css("display","block");a(b.currentTarget).hide();a(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){a(b.currentTarget).parent().parent().siblings(".list-wrap").css("display","none");a(b.currentTarget).parent().parent().siblings(".list-wrap").find("li").css("display","none");a(b.currentTarget).hide();a(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){wpNavMenu.add_checked_items_to_menu(b.currentTarget)});a("#add-custom-links .add-to-menu a").click(function(b){if(a("#custom-menu-item-url").val()==a("#custom-menu-item-url").attr("defaultValue")){return}wpNavMenu.add_custom_link(a("#custom-menu-item-name").val(),a("#custom-menu-item-url").val());a("#custom-menu-item-name").val(a("#custom-menu-item-name").attr("defaultValue"));a("#custom-menu-item-url").val(a("#custom-menu-item-url").attr("defaultValue")).focus()})},add_custom_link:function(c,b){var d={action:"save-custom-link",link_name:c,link_url:b};a.post(ajaxurl,d,function(e){if("-1"==e){return}wpNavMenu.add_to_menu(e,e,"custom","custom",navMenuL10n.custom,0,c,b,"","","","","")},"json")},initial_meta_boxes:function(){var c=a("#hidden-metaboxes").val().split(",");if(""!=c){for(var b=0;b<c.length;b++){a("#"+c[b]).attr("style","display: none;");a("#"+c[b]+"-hide").attr("checked",false)}}},drag_and_drop:function(){a(".menu li").each(function(){if(!a(this).children(".dropzone").attr("class")){a(this).prepend('<div class="dropzone"></div>')}});a(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});a(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(h,g){var b=a(this).parent();var j=!a(this).hasClass("dropzone");var f=b.children("input[name=menu-item-object-id[]]").val();var i=g.draggable.children("input[name=menu-item-object-id[]]").val();if(f==i){g.draggable.find("dt").animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){a(this).css("backgroundColor","")}});a(this).parent().find("dt").removeAttr("style");return}if(j&&b.children("ul").length==0){b.append('<ul class="sub-menu" />')}if(j){b.children("ul").append(g.draggable)}else{b.before(g.draggable)}b.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var d=g.draggable.attr("value");var c=b.attr("value");b.find("#menu-"+d).find("#paren