WordPress.org

Make WordPress Core

Changeset 13739


Ignore:
Timestamp:
03/17/2010 07:57:08 PM (12 years ago)
Author:
markjaquith
Message:

Nav Menus: blur/Focus behavior for Create Menu and Add Custom Links. Route "return" presses in each of those areas to proper button press. Better create/save logic on the PHP side.

Location:
trunk/wp-admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/nav-menu.php

    r13733 r13739  
    8787function wp_nav_menu_create_metabox() { ?>
    8888    <p>
    89         <input type="text" name="create-menu-name" id="create-menu-name" class="regular-text" value=""  />
    90         <input type="submit" name="create-menu" id="create-menu" class="button" value="<?php esc_attr_e('Create Menu'); ?>" />
     89        <input type="text" name="create-menu-name" id="create-menu-name" class="regular-text" value="<?php esc_attr_e( 'Menu name' ); ?>"  />
     90        <input type="submit" name="create-menu-button" id="create-menu-button" class="button" value="<?php esc_attr_e('Create Menu'); ?>" />
    9191    </p>
    9292    <?php
  • trunk/wp-admin/js/nav-menu.dev.js

    r13733 r13739  
    387387    });
    388388
     389    // Handle some return keypresses
     390    $('#create-menu-name').keypress(function(e){
     391        if ( 13 == e.keyCode ) {
     392            $('#create-menu-button').click();
     393            return false;
     394        }
     395    });
     396
     397    $('#custom-menu-item-url, #custom-menu-item-name').keypress(function(e){
     398        if ( 13 == e.keyCode ) {
     399            $('#add-custom-links a.button').click();
     400            return false;
     401        }
     402    }).focus(function(){
     403        if ( $(this).val() == $(this).attr('defaultValue') && $(this).attr('id') != 'custom-menu-item-url' ) {
     404            $(this).val('');
     405        }
     406    }).blur(function(){
     407        if ( $(this).val() == '' ) {
     408            $(this).val($(this).attr('defaultValue'));
     409        }
     410    });
     411
     412    $('#create-menu-name').focus(function(){
     413        if ( $(this).val() == $(this).attr('defaultValue') ) {
     414            $(this).val('');
     415        }
     416    }).blur(function(){
     417        if ( $(this).val() == '' ) {
     418            $(this).val($(this).attr('defaultValue'));
     419        }
     420    });
     421
    389422    // close postboxes that should be closed
    390423    $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
     
    447480    // Create a new link then add it to the menu
    448481    $('#add-custom-links .add-to-menu a').click(function(e){
    449         var link_url = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-url').val();
    450         var link_name = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-name').val();
    451 
    452482        // Add link to menu
    453         wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, link_name, link_url, '', '', '_self', '', '' );
     483        if ( $('#custom-menu-item-url').val() == $('#custom-menu-item-url').attr('defaultValue') )
     484            return; // Do not allow "http://" submissions to go through
     485        wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, $('#custom-menu-item-name').val(), $('#custom-menu-item-url').val(), '', '', '_self', '', '' );
     486        $('#custom-menu-item-name').val($('#custom-menu-item-name').attr('defaultValue'));
     487        $('#custom-menu-item-url' ).val($('#custom-menu-item-url' ).attr('defaultValue')).focus();
    454488    });
    455489});
  • trunk/wp-admin/js/nav-menu.js

    r13730 r13739  
    1 function wp_nav_menu_autocomplete(a){jQuery("#add-"+a+" .quick-search").autocomplete(jQuery("#add-"+a+" .autocomplete").val().split("|"));jQuery("#add-"+a+" .quick-search").result(function(b,d,c){jQuery("#add-"+a+" .list-wrap").css("display","block");jQuery("#add-"+a+" .list-wrap li:contains('"+d+"')").css("display","block");jQuery("#add-"+a+" .show-all").hide();jQuery("#add-"+a+" .hide-all").show()})}function wp_edit_menu_item(a){var f=jQuery("#menu-item-type"+a).val();var b=jQuery("#menu-item-title"+a).val();var g=jQuery("#menu-item-url"+a).val();var c=jQuery("#menu-item-attr-title"+a).val();var d=jQuery("#menu-item-target"+a).val();var h=jQuery("#menu-item-description"+a).val();var e=jQuery("#menu-item-classes"+a).val();var i=jQuery("#menu-item-xfn"+a).val();if("custom"!=f){jQuery("#edit-menu-item-url").attr("disabled","disabled")}jQuery("#edit-menu-item-id").val(a);jQuery("#edit-menu-item-title").val(b);jQuery("#edit-menu-item-url").val(g);jQuery("#edit-menu-item-attr-title").val(c);jQuery("#edit-menu-item-target").val(d);jQuery("#edit-menu-item-target option[value='"+d+"']").attr("selected","selected");jQuery("#edit-menu-item-description").val(h);jQuery("#edit-menu-item-classes").val(e);jQuery("#edit-menu-item-xfn").val(i);jQuery("#edit-menu-item-title").focus()}function wp_update_menu_item(){var h=jQuery("#edit-menu-item-id").val();var f=jQuery("#edit-menu-item-title").val();var b=jQuery("#edit-menu-item-url").val();var g=jQuery("#edit-menu-item-attr-title").val();var d=jQuery("#edit-menu-item-target").val();var c=jQuery("#edit-menu-item-description").val();var a=jQuery("#edit-menu-item-classes").val();var e=jQuery("#edit-menu-item-xfn").val();jQuery(".menu #menu-item"+h).find("span.item-title").html(f);jQuery(".menu #menu-item-title"+h).val(f);jQuery(".menu #menu-item-url"+h).val(b);jQuery(".menu #menu-item-attr-title"+h).val(g);jQuery(".menu #menu-item-target"+h).val(d);jQuery(".menu #menu-item-description"+h).val(c);jQuery(".menu #menu-item-classes"+h).val(a);jQuery(".menu #menu-item-xfn"+h).val(e);jQuery(".menu #menu-item"+h+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_remove_menu_item(b){var a=document.getElementById("menu-item"+b);if(a){jQuery(a).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})})}}function wp_add_item_to_menu(a,k,f,n,l,b,m,h,e,d,c,i){var j=wp_get_unique_menu_id();var g=wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i);jQuery(".menu").append('<li id="menu-item'+j+'" value="'+j+'"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">'+b+'</span><span class="item-controls"><span class="item-type">'+n+'</span><a class="item-edit thickbox" id="edit'+j+'" value="'+j+'" onClick="wp_edit_menu_item('+j+')" title="'+navMenuL10n.thickbox+'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'+navMenuL10n.edit+'</a> | <a class="item-delete" id="delete'+j+'" value="'+j+'">Delete</a></span></dt></dl>'+g+"</li>");jQuery(".menu #menu-item"+j+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_add_checked_items_to_menu(b){var a=jQuery(b).siblings(".list-wrap").find(":checked");if(0==a.length){return false}jQuery(a).each(function(){var h=jQuery(this).parent().siblings(".menu-item-type").val();if("custom"==h){var e=jQuery(this).parent().siblings(".menu-item-attr-title").val();var f=jQuery(this).parent().siblings(".menu-item-target").val();var g=jQuery(this).parent().siblings(".menu-item-classes").val();var j=jQuery(this).parent().siblings(".menu-item-xfn").val()}else{var e="";var f="_self";var g="";var j=""}var c=jQuery(this).parent().siblings(".menu-item-db-id").val();var k=jQuery(this).parent().siblings(".menu-item-object-id").val();var n=jQuery(this).parent().siblings(".menu-item-append").val();var l=jQuery(this).parent().siblings(".menu-item-parent-id").val();var d=jQuery(this).parent().siblings(".menu-item-title").val();var m=jQuery(this).parent().siblings(".menu-item-url").val();var i=jQuery(this).parent().siblings(".menu-item-description").val();if(undefined==i){i=""}wp_add_item_to_menu(c,k,h,n,l,d,m,i,e,f,g,j);jQuery(this).attr("checked",false)})}function wp_drag_and_drop(){jQuery(".menu li").each(function(){if(!jQuery(this).children(".dropzone").attr("class")){jQuery(this).prepend('<div class="dropzone"></div>')}});jQuery(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});jQuery(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(f,d){var a=jQuery(this).parent();var g=!jQuery(this).hasClass("dropzone");if(g&&a.children("ul").length==0){a.append('<ul class="sub-menu" />')}if(g){a.children("ul").append(d.draggable)}else{a.before(d.draggable)}a.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var c=d.draggable.attr("value");var b=a.attr("value");a.find("#menu-"+c).find("#parent"+c).val(b);jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style")},over:function(){if(jQuery(this).attr("class")=="dropzone ui-droppable"){jQuery(this).parent().find("div:first").css("background","none").css("height","50px")}else{if(jQuery(this).attr("class")=="ui-droppable"){jQuery(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var a=jQuery(this).parent().attr("id")},out:function(){jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style");jQuery(this).filter(".dropzone").css({borderColor:""})}})}function wp_update_post_data(){var a=0;jQuery(".menu li").each(function(c){c=c+1;var b=jQuery(this).attr("value");jQuery(this).find("#menu-item-position"+b).attr("value",c);jQuery(this).attr("id","menu-item"+c);jQuery(this).attr("value",c);jQuery(this).find("#menu-item-db-id"+b).attr("id","menu-item-db-id"+c);jQuery(this).find("#menu-item-object-id"+b).attr("id","menu-item-object-id"+c);jQuery(this).find("#menu-item-append"+b).attr("id","menu-item-append"+c);jQuery(this).find("#menu-item-type"+b).attr("id","menu-item-type"+c);jQuery(this).find("#menu-item-position"+b).attr("id","menu-item-position"+c);var d=jQuery(this).find("#menu-item-parent-id"+b).parent().parent().parent().attr("value");jQuery(this).find("#menu-item-parent-id"+b).attr("id","menu-item-parent-id"+c);if(d){}else{d=0}jQuery(this).find("#menu-item-parent-id"+b).attr("value",d);jQuery(this).find("#menu-item-title"+b).attr("id","menu-item-title"+c);jQuery(this).find("#menu-item-url"+b).attr("id","menu-item-url"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-classes"+b).attr("id","menu-item-classes"+c);jQuery(this).find("#menu-item-xfn"+b).attr("id","menu-item-xfn"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-attr-title"+b).attr("id","menu-item-attr-title"+c);jQuery(this).find("#menu-item-target"+b).attr("id","menu-item-target"+c);jQuery("#li-count").attr("value",c)})}function wp_get_unique_menu_id(){var d=jQuery(".menu li").length+1;var e=d;var a=0;try{var f=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}while(a==0){e=e+1;try{var b=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}}return e}function wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i){var g="";g+='<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id'+j+'" value="'+a+'" />';g+='<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id'+j+'" value="'+k+'" />';g+='<input type="hidden" name="menu-item-type[]" id="menu-item-type'+j+'" value="'+f+'" />';g+='<input type="hidden" name="menu-item-append[]" id="menu-item-append'+j+'" value="'+n+'" />';g+='<input type="hidden" name="menu-item-parent-id[]" id="menu-item-parent-id'+j+'" value="'+l+'" />';g+='<input type="hidden" name="menu-item-position[]" id="menu-item-position'+j+'" value="'+j+'" />';g+='<input type="hidden" name="menu-item-title[]" id="menu-item-title'+j+'" value="'+b+'" />';g+='<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title'+j+'" value="'+e+'" />';g+='<input type="hidden" name="menu-item-url[]" id="menu-item-url'+j+'" value="'+m+'" />';g+='<input type="hidden" name="menu-item-target[]" id="menu-item-target'+j+'" value="'+d+'" />';g+='<input type="hidden" name="menu-item-description[]" id="menu-item-description'+j+'" value="'+h+'" />';g+='<input type="hidden" name="menu-item-classes[]" id="menu-item-classes'+j+'" value="'+c+'" />';g+='<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn'+j+'" value="'+i+'" />';return g}jQuery(document).ready(function(a){wp_drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#save_menu").click(function(){return wp_update_post_data()});a(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("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(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(b){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();return tb_remove()});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","block");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","block");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","none");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","none");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){return wp_add_checked_items_to_menu(b.currentTarget)});a("#add-custom-links .add-to-menu a").click(function(d){var b=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-url").val();var c=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-name").val();wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,c,b,"","","_self","","")})});function get_html_translation_table(i,g){var d={},f={},c=0,a="";var e={},b={};var j={},h={};e[0]="HTML_SPECIALCHARS";e[1]="HTML_ENTITIES";b[0]="ENT_NOQUOTES";b[2]="ENT_COMPAT";b[3]="ENT_QUOTES";j=!isNaN(i)?e[i]:i?i.toUpperCase():"HTML_SPECIALCHARS";h=!isNaN(g)?b[g]:g?g.toUpperCase():"ENT_COMPAT";if(j!=="HTML_SPECIALCHARS"&&j!=="HTML_ENTITIES"){throw new Error("Table: "+j+" not supported")}d["38"]="&amp;";if(j==="HTML_ENTITIES"){d["160"]="&nbsp;";d["161"]="&iexcl;";d["162"]="&cent;";d["163"]="&pound;";d["164"]="&curren;";d["165"]="&yen;";d["166"]="&brvbar;";d["167"]="&sect;";d["168"]="&uml;";d["169"]="&copy;";d["170"]="&ordf;";d["171"]="&laquo;";d["172"]="&not;";d["173"]="&shy;";d["174"]="&reg;";d["175"]="&macr;";d["176"]="&deg;";d["177"]="&plusmn;";d["178"]="&sup2;";d["179"]="&sup3;";d["180"]="&acute;";d["181"]="&micro;";d["182"]="&para;";d["183"]="&middot;";d["184"]="&cedil;";d["185"]="&sup1;";d["186"]="&ordm;";d["187"]="&raquo;";d["188"]="&frac14;";d["189"]="&frac12;";d["190"]="&frac34;";d["191"]="&iquest;";d["192"]="&Agrave;";d["193"]="&Aacute;";d["194"]="&Acirc;";d["195"]="&Atilde;";d["196"]="&Auml;";d["197"]="&Aring;";d["198"]="&AElig;";d["199"]="&Ccedil;";d["200"]="&Egrave;";d["201"]="&Eacute;";d["202"]="&Ecirc;";d["203"]="&Euml;";d["204"]="&Igrave;";d["205"]="&Iacute;";d["206"]="&Icirc;";d["207"]="&Iuml;";d["208"]="&ETH;";d["209"]="&Ntilde;";d["210"]="&Ograve;";d["211"]="&Oacute;";d["212"]="&Ocirc;";d["213"]="&Otilde;";d["214"]="&Ouml;";d["215"]="&times;";d["216"]="&Oslash;";d["217"]="&Ugrave;";d["218"]="&Uacute;";d["219"]="&Ucirc;";d["220"]="&Uuml;";d["221"]="&Yacute;";d["222"]="&THORN;";d["223"]="&szlig;";d["224"]="&agrave;";d["225"]="&aacute;";d["226"]="&acirc;";d["227"]="&atilde;";d["228"]="&auml;";d["229"]="&aring;";d["230"]="&aelig;";d["231"]="&ccedil;";d["232"]="&egrave;";d["233"]="&eacute;";d["234"]="&ecirc;";d["235"]="&euml;";d["236"]="&igrave;";d["237"]="&iacute;";d["238"]="&icirc;";d["239"]="&iuml;";d["240"]="&eth;";d["241"]="&ntilde;";d["242"]="&ograve;";d["243"]="&oacute;";d["244"]="&ocirc;";d["245"]="&otilde;";d["246"]="&ouml;";d["247"]="&divide;";d["248"]="&oslash;";d["249"]="&ugrave;";d["250"]="&uacute;";d["251"]="&ucirc;";d["252"]="&uuml;";d["253"]="&yacute;";d["254"]="&thorn;";d["255"]="&yuml;"}if(h!=="ENT_NOQUOTES"){d["34"]="&quot;"}if(h==="ENT_QUOTES"){d["39"]="&#39;"}d["60"]="&lt;";d["62"]="&gt;";for(c in d){a=String.fromCharCode(c);f[a]=d[c]}return f}function htmlentities(c,f){var e={},d="",a="",b="";a=c.toString();if(false===(e=this.get_html_translation_table("HTML_ENTITIES",f))){return false}e["'"]="&#039;";for(d in e){b=e[d];a=a.split(d).join(b)}return a};
     1function wp_nav_menu_autocomplete(a){jQuery("#add-"+a+" .quick-search").autocomplete(jQuery("#add-"+a+" .autocomplete").val().split("|"));jQuery("#add-"+a+" .quick-search").result(function(b,d,c){jQuery("#add-"+a+" .list-wrap").css("display","block");jQuery("#add-"+a+" .list-wrap li:contains('"+d+"')").css("display","block");jQuery("#add-"+a+" .show-all").hide();jQuery("#add-"+a+" .hide-all").show()})}function wp_edit_menu_item(a){var f=jQuery("#menu-item-type"+a).val();var b=jQuery("#menu-item-title"+a).val();var g=jQuery("#menu-item-url"+a).val();var c=jQuery("#menu-item-attr-title"+a).val();var d=jQuery("#menu-item-target"+a).val();var h=jQuery("#menu-item-description"+a).val();var e=jQuery("#menu-item-classes"+a).val();var i=jQuery("#menu-item-xfn"+a).val();if("custom"!=f){jQuery("#edit-menu-item-url").attr("disabled","disabled")}jQuery("#edit-menu-item-id").val(a);jQuery("#edit-menu-item-title").val(b);jQuery("#edit-menu-item-url").val(g);jQuery("#edit-menu-item-attr-title").val(c);jQuery("#edit-menu-item-target").val(d);jQuery("#edit-menu-item-target option[value='"+d+"']").attr("selected","selected");jQuery("#edit-menu-item-description").val(h);jQuery("#edit-menu-item-classes").val(e);jQuery("#edit-menu-item-xfn").val(i);jQuery("#edit-menu-item-title").focus()}function wp_update_menu_item(){var h=jQuery("#edit-menu-item-id").val();var f=jQuery("#edit-menu-item-title").val();var b=jQuery("#edit-menu-item-url").val();var g=jQuery("#edit-menu-item-attr-title").val();var d=jQuery("#edit-menu-item-target").val();var c=jQuery("#edit-menu-item-description").val();var a=jQuery("#edit-menu-item-classes").val();var e=jQuery("#edit-menu-item-xfn").val();jQuery(".menu #menu-item"+h).find("span.item-title").html(f);jQuery(".menu #menu-item-title"+h).val(f);jQuery(".menu #menu-item-url"+h).val(b);jQuery(".menu #menu-item-attr-title"+h).val(g);jQuery(".menu #menu-item-target"+h).val(d);jQuery(".menu #menu-item-description"+h).val(c);jQuery(".menu #menu-item-classes"+h).val(a);jQuery(".menu #menu-item-xfn"+h).val(e);jQuery(".menu #menu-item"+h+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_remove_menu_item(b){var a=document.getElementById("menu-item"+b);if(a){jQuery(a).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})})}}function wp_add_item_to_menu(a,k,f,n,l,b,m,h,e,d,c,i){var j=wp_get_unique_menu_id();var g=wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i);jQuery(".menu").append('<li id="menu-item'+j+'" value="'+j+'"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">'+b+'</span><span class="item-controls"><span class="item-type">'+n+'</span><a class="item-edit thickbox" id="edit'+j+'" value="'+j+'" onClick="wp_edit_menu_item('+j+')" title="'+navMenuL10n.thickbox+'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'+navMenuL10n.edit+'</a> | <a class="item-delete" id="delete'+j+'" value="'+j+'">Delete</a></span></dt></dl>'+g+"</li>");jQuery(".menu #menu-item"+j+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_add_checked_items_to_menu(b){var a=jQuery(b).siblings(".list-wrap").find(":checked");if(0==a.length){return false}jQuery(a).each(function(){var h=jQuery(this).parent().siblings(".menu-item-type").val();if("custom"==h){var e=jQuery(this).parent().siblings(".menu-item-attr-title").val();var f=jQuery(this).parent().siblings(".menu-item-target").val();var g=jQuery(this).parent().siblings(".menu-item-classes").val();var j=jQuery(this).parent().siblings(".menu-item-xfn").val()}else{var e="";var f="_self";var g="";var j=""}var c=jQuery(this).parent().siblings(".menu-item-db-id").val();var k=jQuery(this).parent().siblings(".menu-item-object-id").val();var n=jQuery(this).parent().siblings(".menu-item-append").val();var l=jQuery(this).parent().siblings(".menu-item-parent-id").val();var d=jQuery(this).parent().siblings(".menu-item-title").val();var m=jQuery(this).parent().siblings(".menu-item-url").val();var i=jQuery(this).parent().siblings(".menu-item-description").val();if(undefined==i){i=""}wp_add_item_to_menu(c,k,h,n,l,d,m,i,e,f,g,j);jQuery(this).attr("checked",false)})}function wp_drag_and_drop(){jQuery(".menu li").each(function(){if(!jQuery(this).children(".dropzone").attr("class")){jQuery(this).prepend('<div class="dropzone"></div>')}});jQuery(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});jQuery(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(f,d){var a=jQuery(this).parent();var g=!jQuery(this).hasClass("dropzone");if(g&&a.children("ul").length==0){a.append('<ul class="sub-menu" />')}if(g){a.children("ul").append(d.draggable)}else{a.before(d.draggable)}a.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var c=d.draggable.attr("value");var b=a.attr("value");a.find("#menu-"+c).find("#parent"+c).val(b);jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style")},over:function(){if(jQuery(this).attr("class")=="dropzone ui-droppable"){jQuery(this).parent().find("div:first").css("background","none").css("height","50px")}else{if(jQuery(this).attr("class")=="ui-droppable"){jQuery(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var a=jQuery(this).parent().attr("id")},out:function(){jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style");jQuery(this).filter(".dropzone").css({borderColor:""})}})}function wp_update_post_data(){var a=0;jQuery(".menu li").each(function(c){c=c+1;var b=jQuery(this).attr("value");jQuery(this).find("#menu-item-position"+b).attr("value",c);jQuery(this).attr("id","menu-item"+c);jQuery(this).attr("value",c);jQuery(this).find("#menu-item-db-id"+b).attr("id","menu-item-db-id"+c);jQuery(this).find("#menu-item-object-id"+b).attr("id","menu-item-object-id"+c);jQuery(this).find("#menu-item-append"+b).attr("id","menu-item-append"+c);jQuery(this).find("#menu-item-type"+b).attr("id","menu-item-type"+c);jQuery(this).find("#menu-item-position"+b).attr("id","menu-item-position"+c);var d=jQuery(this).find("#menu-item-parent-id"+b).parent().parent().parent().attr("value");jQuery(this).find("#menu-item-parent-id"+b).attr("id","menu-item-parent-id"+c);if(d){}else{d=0}jQuery(this).find("#menu-item-parent-id"+b).attr("value",d);jQuery(this).find("#menu-item-title"+b).attr("id","menu-item-title"+c);jQuery(this).find("#menu-item-url"+b).attr("id","menu-item-url"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-classes"+b).attr("id","menu-item-classes"+c);jQuery(this).find("#menu-item-xfn"+b).attr("id","menu-item-xfn"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-attr-title"+b).attr("id","menu-item-attr-title"+c);jQuery(this).find("#menu-item-target"+b).attr("id","menu-item-target"+c);jQuery("#li-count").attr("value",c)})}function wp_get_unique_menu_id(){var d=jQuery(".menu li").length+1;var e=d;var a=0;try{var f=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}while(a==0){e=e+1;try{var b=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}}return e}function wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i){var g="";g+='<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id'+j+'" value="'+a+'" />';g+='<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id'+j+'" value="'+k+'" />';g+='<input type="hidden" name="menu-item-type[]" id="menu-item-type'+j+'" value="'+f+'" />';g+='<input type="hidden" name="menu-item-append[]" id="menu-item-append'+j+'" value="'+n+'" />';g+='<input type="hidden" name="menu-item-parent-id[]" id="menu-item-parent-id'+j+'" value="'+l+'" />';g+='<input type="hidden" name="menu-item-position[]" id="menu-item-position'+j+'" value="'+j+'" />';g+='<input type="hidden" name="menu-item-title[]" id="menu-item-title'+j+'" value="'+b+'" />';g+='<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title'+j+'" value="'+e+'" />';g+='<input type="hidden" name="menu-item-url[]" id="menu-item-url'+j+'" value="'+m+'" />';g+='<input type="hidden" name="menu-item-target[]" id="menu-item-target'+j+'" value="'+d+'" />';g+='<input type="hidden" name="menu-item-description[]" id="menu-item-description'+j+'" value="'+h+'" />';g+='<input type="hidden" name="menu-item-classes[]" id="menu-item-classes'+j+'" value="'+c+'" />';g+='<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn'+j+'" value="'+i+'" />';return g}jQuery(document).ready(function(a){wp_drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#save_menu").click(function(){return wp_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("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(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(b){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();return tb_remove()});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","block");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","block");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","none");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","none");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){return wp_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}wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,a("#custom-menu-item-name").val(),a("#custom-menu-item-url").val(),"","","_self","","");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()})});function get_html_translation_table(i,g){var d={},f={},c=0,a="";var e={},b={};var j={},h={};e[0]="HTML_SPECIALCHARS";e[1]="HTML_ENTITIES";b[0]="ENT_NOQUOTES";b[2]="ENT_COMPAT";b[3]="ENT_QUOTES";j=!isNaN(i)?e[i]:i?i.toUpperCase():"HTML_SPECIALCHARS";h=!isNaN(g)?b[g]:g?g.toUpperCase():"ENT_COMPAT";if(j!=="HTML_SPECIALCHARS"&&j!=="HTML_ENTITIES"){throw new Error("Table: "+j+" not supported")}d["38"]="&amp;";if(j==="HTML_ENTITIES"){d["160"]="&nbsp;";d["161"]="&iexcl;";d["162"]="&cent;";d["163"]="&pound;";d["164"]="&curren;";d["165"]="&yen;";d["166"]="&brvbar;";d["167"]="&sect;";d["168"]="&uml;";d["169"]="&copy;";d["170"]="&ordf;";d["171"]="&laquo;";d["172"]="&not;";d["173"]="&shy;";d["174"]="&reg;";d["175"]="&macr;";d["176"]="&deg;";d["177"]="&plusmn;";d["178"]="&sup2;";d["179"]="&sup3;";d["180"]="&acute;";d["181"]="&micro;";d["182"]="&para;";d["183"]="&middot;";d["184"]="&cedil;";d["185"]="&sup1;";d["186"]="&ordm;";d["187"]="&raquo;";d["188"]="&frac14;";d["189"]="&frac12;";d["190"]="&frac34;";d["191"]="&iquest;";d["192"]="&Agrave;";d["193"]="&Aacute;";d["194"]="&Acirc;";d["195"]="&Atilde;";d["196"]="&Auml;";d["197"]="&Aring;";d["198"]="&AElig;";d["199"]="&Ccedil;";d["200"]="&Egrave;";d["201"]="&Eacute;";d["202"]="&Ecirc;";d["203"]="&Euml;";d["204"]="&Igrave;";d["205"]="&Iacute;";d["206"]="&Icirc;";d["207"]="&Iuml;";d["208"]="&ETH;";d["209"]="&Ntilde;";d["210"]="&Ograve;";d["211"]="&Oacute;";d["212"]="&Ocirc;";d["213"]="&Otilde;";d["214"]="&Ouml;";d["215"]="&times;";d["216"]="&Oslash;";d["217"]="&Ugrave;";d["218"]="&Uacute;";d["219"]="&Ucirc;";d["220"]="&Uuml;";d["221"]="&Yacute;";d["222"]="&THORN;";d["223"]="&szlig;";d["224"]="&agrave;";d["225"]="&aacute;";d["226"]="&acirc;";d["227"]="&atilde;";d["228"]="&auml;";d["229"]="&aring;";d["230"]="&aelig;";d["231"]="&ccedil;";d["232"]="&egrave;";d["233"]="&eacute;";d["234"]="&ecirc;";d["235"]="&euml;";d["236"]="&igrave;";d["237"]="&iacute;";d["238"]="&icirc;";d["239"]="&iuml;";d["240"]="&eth;";d["241"]="&ntilde;";d["242"]="&ograve;";d["243"]="&oacute;";d["244"]="&ocirc;";d["245"]="&otilde;";d["246"]="&ouml;";d["247"]="&divide;";d["248"]="&oslash;";d["249"]="&ugrave;";d["250"]="&uacute;";d["251"]="&ucirc;";d["252"]="&uuml;";d["253"]="&yacute;";d["254"]="&thorn;";d["255"]="&yuml;"}if(h!=="ENT_NOQUOTES"){d["34"]="&quot;"}if(h==="ENT_QUOTES"){d["39"]="&#39;"}d["60"]="&lt;";d["62"]="&gt;";for(c in d){a=String.fromCharCode(c);f[a]=d[c]}return f}function htmlentities(c,f){var e={},d="",a="",b="";a=c.toString();if(false===(e=this.get_html_translation_table("HTML_ENTITIES",f))){return false}e["'"]="&#039;";for(d in e){b=e[d];a=a.split(d).join(b)}return a};
  • trunk/wp-admin/nav-menus.php

    r13733 r13739  
    6868
    6969        // Add Menu
    70         if ( isset($_POST['create-menu']) ) {
     70        if ( isset($_POST['create-menu-button']) ) {
    7171            if ( current_theme_supports('nav-menus') ) {
    7272                $add_nav_menu = esc_html( $_POST['create-menu-name'] );
     
    8787                unset($add_nav_menu);
    8888            }
    89         } elseif ( isset($_POST['menu-name']) ) {
    90             $old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A );
    91             $args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], );
    92             $new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args );
    93         }
    94 
    95         // Update menu items
    96         $update_nav_items = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0;
    97         $update_nav_menu = is_nav_menu( $nav_menu_selected_id );
    98 
    99         if ( !is_wp_error($update_nav_menu) ) {
    100             $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
    101             $parent_menu_ids = array();
    102 
    103             // Loop through all POST variables
    104             for ( $k = 0; $k < $update_nav_items; $k++ ) {
    105                 $menu_item_db_id        = isset( $_POST['menu-item-db-id'][$k] )        ? $_POST['menu-item-db-id'][$k]     : 0;
    106                 $menu_item_object_id    = isset( $_POST['menu-item-object-id'][$k] )    ? $_POST['menu-item-object-id'][$k] : 0;
    107                 $menu_item_parent_id    = isset( $_POST['menu-item-parent-id'][$k] )    ? $_POST['menu-item-parent-id'][$k] : 0;
    108                 $menu_item_position     = isset( $_POST['menu-item-position'][$k] )     ? $_POST['menu-item-position'][$k]  : 0;
    109                 $menu_item_type         = isset( $_POST['menu-item-type'][$k] )         ? $_POST['menu-item-type'][$k]      : 'custom';
    110                 $menu_item_append       = isset( $_POST['menu-item-append'][$k] )       ? $_POST['menu-item-append'][$k]    : 'custom';
    111 
    112                 $menu_item_title        = isset( $_POST['menu-item-title'][$k] )        ? $_POST['menu-item-title'][$k]     : '';
    113                 $menu_item_url          = isset( $_POST['menu-item-url'][$k] )          ? $_POST['menu-item-url'][$k]       : '';
    114                 $menu_item_description  = isset( $_POST['menu-item-description'][$k] )  ? $_POST['menu-item-description'][$k]: '';
    115                 $menu_item_attr_title   = isset( $_POST['menu-item-attr-title'][$k] )   ? $_POST['menu-item-attr-title'][$k] : '';
    116                 $menu_item_target       = isset( $_POST['menu-item-target'][$k] )       ? $_POST['menu-item-target'][$k]    : 0;
    117                 $menu_item_classes      = isset( $_POST['menu-item-classes'][$k] )      ? $_POST['menu-item-classes'][$k]   : '';
    118                 $menu_item_xfn          = isset( $_POST['menu-item-xfn'][$k] )          ? $_POST['menu-item-xfn'][$k]       : '';
    119 
    120                 // Menu item title can't be blank
    121                 if ( '' == $menu_item_title )
    122                     continue;
    123 
    124                 // Populate the menu item
    125                 $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
    126                     'ping_status' => 0, 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position,
    127                     'post_excerpt' => $menu_item_attr_title, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ),
    128                     'post_content' => $menu_item_description, 'post_title' => $menu_item_title );
    129 
    130                 // New menu item
    131                 if ( $menu_item_db_id == 0 ) {
    132                     $menu_item_db_id = wp_insert_post( $post );
    133                 } elseif ( isset( $menu_items[$menu_item_db_id] ) ) {
    134                     $post['ID'] = $menu_item_db_id;
    135                     wp_update_post( $post );
    136                     unset( $menu_items[$menu_item_db_id] );
     89        } else {
     90            if ( isset($_POST['menu-name']) ) {
     91                $old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A );
     92                $args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], );
     93                $new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args );
     94            }
     95
     96            // Update menu items
     97            $update_nav_items = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0;
     98            $update_nav_menu = is_nav_menu( $nav_menu_selected_id );
     99
     100            if ( !is_wp_error($update_nav_menu) ) {
     101                $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
     102                $parent_menu_ids = array();
     103
     104                // Loop through all POST variables
     105                for ( $k = 0; $k < $update_nav_items; $k++ ) {
     106                    $menu_item_db_id        = isset( $_POST['menu-item-db-id'][$k] )        ? $_POST['menu-item-db-id'][$k]     : 0;
     107                    $menu_item_object_id    = isset( $_POST['menu-item-object-id'][$k] )    ? $_POST['menu-item-object-id'][$k] : 0;
     108                    $menu_item_parent_id    = isset( $_POST['menu-item-parent-id'][$k] )    ? $_POST['menu-item-parent-id'][$k] : 0;
     109                    $menu_item_position     = isset( $_POST['menu-item-position'][$k] )     ? $_POST['menu-item-position'][$k]  : 0;
     110                    $menu_item_type         = isset( $_POST['menu-item-type'][$k] )         ? $_POST['menu-item-type'][$k]      : 'custom';
     111                    $menu_item_append       = isset( $_POST['menu-item-append'][$k] )       ? $_POST['menu-item-append'][$k]    : 'custom';
     112
     113                    $menu_item_title        = isset( $_POST['menu-item-title'][$k] )        ? $_POST['menu-item-title'][$k]     : '';
     114                    $menu_item_url          = isset( $_POST['menu-item-url'][$k] )          ? $_POST['menu-item-url'][$k]       : '';
     115                    $menu_item_description  = isset( $_POST['menu-item-description'][$k] )  ? $_POST['menu-item-description'][$k]: '';
     116                    $menu_item_attr_title   = isset( $_POST['menu-item-attr-title'][$k] )   ? $_POST['menu-item-attr-title'][$k] : '';
     117                    $menu_item_target       = isset( $_POST['menu-item-target'][$k] )       ? $_POST['menu-item-target'][$k]    : 0;
     118                    $menu_item_classes      = isset( $_POST['menu-item-classes'][$k] )      ? $_POST['menu-item-classes'][$k]   : '';
     119                    $menu_item_xfn          = isset( $_POST['menu-item-xfn'][$k] )          ? $_POST['menu-item-xfn'][$k]       : '';
     120
     121                    // Menu item title can't be blank
     122                    if ( '' == $menu_item_title )
     123                        continue;
     124
     125                    // Populate the menu item
     126                    $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
     127                        'ping_status' => 0, 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position,
     128                        'post_excerpt' => $menu_item_attr_title, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ),
     129                        'post_content' => $menu_item_description, 'post_title' => $menu_item_title );
     130
     131                    // New menu item
     132                    if ( $menu_item_db_id == 0 ) {
     133                        $menu_item_db_id = wp_insert_post( $post );
     134                    } elseif ( isset( $menu_items[$menu_item_db_id] ) ) {
     135                        $post['ID'] = $menu_item_db_id;
     136                        wp_update_post( $post );
     137                        unset( $menu_items[$menu_item_db_id] );
     138                    }
     139                    $parent_menu_ids[$k] = $menu_item_db_id;
     140
     141                    // @todo sanitize type append and ID.
     142                    update_post_meta( $menu_item_db_id, 'menu_item_type', $menu_item_type );
     143                    update_post_meta( $menu_item_db_id, 'menu_item_append', $menu_item_append );
     144                    update_post_meta( $menu_item_db_id, 'menu_item_object_id', $menu_item_object_id );
     145                    update_post_meta( $menu_item_db_id, 'menu_item_target', sanitize_key($menu_item_target) );
     146                    // @todo handle sanitizing multiple classes separated by whitespace.
     147                    update_post_meta( $menu_item_db_id, 'menu_item_classes', sanitize_html_class($menu_item_classes) );
     148                    update_post_meta( $menu_item_db_id, 'menu_item_xfn', sanitize_html_class($menu_item_xfn) );
     149
     150                    // @todo: only save custom link urls.
     151                    update_post_meta( $menu_item_db_id, 'menu_item_url', esc_url_raw( $menu_item_url ) );
    137152                }
    138                 $parent_menu_ids[$k] = $menu_item_db_id;
    139 
    140                 // @todo sanitize type append and ID.
    141                 update_post_meta( $menu_item_db_id, 'menu_item_type', $menu_item_type );
    142                 update_post_meta( $menu_item_db_id, 'menu_item_append', $menu_item_append );
    143                 update_post_meta( $menu_item_db_id, 'menu_item_object_id', $menu_item_object_id );
    144                 update_post_meta( $menu_item_db_id, 'menu_item_target', sanitize_key($menu_item_target) );
    145                 // @todo handle sanitizing multiple classes separated by whitespace.
    146                 update_post_meta( $menu_item_db_id, 'menu_item_classes', sanitize_html_class($menu_item_classes) );
    147                 update_post_meta( $menu_item_db_id, 'menu_item_xfn', sanitize_html_class($menu_item_xfn) );
    148 
    149                 // @todo: only save custom link urls.
    150                 update_post_meta( $menu_item_db_id, 'menu_item_url', esc_url_raw( $menu_item_url ) );
     153
     154                // Remove menu items from the menu that weren't in $_POST
     155                if ( !empty( $menu_items ) ) {
     156                    foreach ( array_keys( $menu_items ) as $menu_item_id ) {
     157                        wp_delete_post( $menu_item_id );
     158                    }
     159                }
     160                $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>';
    151161            }
    152 
    153             // Remove menu items from the menu that weren't in $_POST
    154             if ( !empty( $menu_items ) ) {
    155                 foreach ( array_keys( $menu_items ) as $menu_item_id ) {
    156                     wp_delete_post( $menu_item_id );
    157                 }
    158             }
    159             $messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>';
    160162        }
    161163        break;
Note: See TracChangeset for help on using the changeset viewer.