Make WordPress Core

Changeset 14475


Ignore:
Timestamp:
05/06/2010 05:11:52 PM (14 years ago)
Author:
nacin
Message:

Adopt WP's general JS structure. Remove last of trailing commas. Remove dead code. props koopersmith, see #13220.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/nav-menu.dev.js

    r14474 r14475  
    99 */
    1010
    11 var wpNavMenu, WPNavMenuHandler = function ($) {
    12     var autoCompleteData = {},
    13 
    14     menuItemDepthPerLevel = 30, // Do not use directly. Use depthToPx and pxToDepth instead.
    15     globalMaxDepth = 11,
    16 
    17     formatAutocompleteResponse = function( resultRow, pos, total, queryTerm ) {
    18         if ( resultRow && resultRow[0] ) {
    19             var data = $.parseJSON(resultRow[0]);
    20             if ( data.post_title ) {
    21                 if ( data.ID && data.post_type )
    22                     autoCompleteData[data.post_title] = {ID: data.ID, object_type: data.post_type};
    23                 return data.post_title;
    24             }
    25         }
    26     },
    27 
    28     formatAutocompleteResult = function( resultRow, pos, total, queryTerm ) {
    29         if ( resultRow && resultRow[0] ) {
    30             var data = $.parseJSON(resultRow[0]);
    31             if ( data.post_title )
    32                 return data.post_title;
    33         }
    34     },
    35 
    36     getListDataFromID = function(menuItemID, parentEl) {
    37         if ( ! menuItemID )
    38             return false;
    39         parentEl = parentEl || document;
    40         var fields = [
    41             'menu-item-db-id',
    42             'menu-item-object-id',
    43             'menu-item-object',
    44             'menu-item-parent-id',
    45             'menu-item-position',
    46             'menu-item-type',
    47             'menu-item-append',
    48             'menu-item-title',
    49             'menu-item-url',
    50             'menu-item-description',
    51             'menu-item-attr-title',
    52             'menu-item-target',
    53             'menu-item-classes',
    54             'menu-item-xfn'
    55         ],
    56         itemData = {},
    57         inputs = parentEl.getElementsByTagName('input'),
    58         i = inputs.length,
    59         j;
    60 
    61         while ( i-- ) {
    62             j = fields.length;
    63             while ( j-- ) {
    64                 if (
    65                     inputs[i] &&
    66                     inputs[i].name &&
    67                     'menu-item[' + menuItemID + '][' + fields[j] + ']' == inputs[i].name
    68                 ) {
    69                     itemData[fields[j]] = inputs[i].value;
    70                 }
    71             }
    72         }
    73 
    74         return itemData;
    75     },
    76 
    77     recalculateMenuItemPositions = function() {
    78         menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
    79     },
    80 
    81     depthToPx = function(depth) {
    82         return depth * menuItemDepthPerLevel;
    83     },
    84 
    85     pxToDepth = function(px) {
    86         return Math.floor(px / menuItemDepthPerLevel);
    87     },
    88 
    89     menuList, targetList, api;
    90 
    91     return api = {
     11var wpNavMenu;
     12
     13(function($) {
     14   
     15    var api = wpNavMenu = {
     16       
     17        options : {
     18            menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
     19            globalMaxDepth : 11
     20        },
     21       
     22        menuList : undefined,   // Set in init.
     23        targetList : undefined, // Set in init.
     24       
     25        autoCompleteData : {},
    9226
    9327        // Functions that run on init.
    9428        init : function() {
    95             menuList = $('#menu-to-edit');
    96             targetList = menuList;
     29            api.menuList = $('#menu-to-edit');
     30            api.targetList = api.menuList;
    9731
    9832            this.jQueryExtensions();
     
    10842            this.attachHomeLinkListener();
    10943
    110             if( menuList.length ) // If no menu, we're in the + tab.
     44            if( api.menuList.length ) // If no menu, we're in the + tab.
    11145                this.initSortables();
    11246
     
    12256            $.fn.extend({
    12357                menuItemDepth : function() {
    124                     return pxToDepth( this.eq(0).css('margin-left').slice(0, -2) );
     58                    return api.pxToDepth( this.eq(0).css('margin-left').slice(0, -2) );
    12559                },
    12660                updateDepthClass : function(current, prev) {
     
    200134                            var listItemDBIDMatch = re.exec( $(this).attr('name') ),
    201135                                listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
    202                             menuItems[listItemDBID] = getListDataFromID(listItemDBID);
     136                            menuItems[listItemDBID] = api.getListDataFromID(listItemDBID);
    203137                        });
    204138                        // Add the items
     
    226160            }
    227161            // hide fields
    228             menuList.hideAdvancedMenuItemFields();
     162            api.menuList.hideAdvancedMenuItemFields();
    229163        },
    230164
    231165        initSortables : function() {
    232166            var currentDepth = 0, originalDepth, minDepth, maxDepth,
    233                 menuLeft = menuList.offset().left,
     167                menuLeft = api.menuList.offset().left,
    234168                newItem, transport;
    235169
    236             menuList.sortable({
     170            api.menuList.sortable({
    237171                handle: '.menu-item-handle',
    238172                placeholder: 'sortable-placeholder',
     
    270204                    });
    271205                    width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width
    272                     width += depthToPx(maxChildDepth - originalDepth); // Account for children
     206                    width += api.depthToPx(maxChildDepth - originalDepth); // Account for children
    273207                    width -= 2; // Subtract 2 for borders
    274208                    ui.placeholder.width(width);
     
    288222                    ui.item.updateParentMenuItemDBId();
    289223                    // Update positions
    290                     recalculateMenuItemPositions();
     224                    api.recalculateMenuItemPositions();
    291225                },
    292226                change: function(e, ui) {
     
    294228                    // Otherwise fix it, or we're in trouble.
    295229                    if( ! ui.placeholder.parent().hasClass('menu') )
    296                         ui.placeholder.appendTo(menuList);
     230                        ui.placeholder.appendTo(api.menuList);
    297231
    298232                    updateDepthRange(ui);
    299233                },
    300234                sort: function(e, ui) {
    301                     var depth = pxToDepth(ui.helper.offset().left - menuLeft);
     235                    var depth = api.pxToDepth(ui.helper.offset().left - menuLeft);
    302236                    // Check and correct if depth is not within range.
    303237                    if ( depth < minDepth ) depth = minDepth;
     
    306240                    if( depth != currentDepth )
    307241                        updateCurrentDepth(ui, depth);
    308                 },
     242                }
    309243            });
    310244
     
    320254
    321255                if( prev.length )
    322                     maxDepth = ( (depth = prev.menuItemDepth() + 1) > globalMaxDepth ) ? globalMaxDepth : depth;
     256                    maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth;
    323257                else
    324258                    maxDepth = 0;
     
    493427         */
    494428        addMenuItemToBottom : function( menuMarkup, req ) {
    495             $(menuMarkup).hideAdvancedMenuItemFields().appendTo( targetList );
     429            $(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList );
    496430        },
    497431   
    498432        addMenuItemToTop : function( menuMarkup, req ) {
    499             $(menuMarkup).hideAdvancedMenuItemFields().prependTo( targetList );
     433            $(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
    500434        },
    501435   
    502436        attachHomeLinkListener : function() {
    503437            $('.add-home-link', '.customlinkdiv').click(function(e) {
    504                 api.addLinkToMenu( navMenuL10n.homeurl, navMenuL10n.home, api.addMenuItemToTop, recalculateMenuItemPositions );
     438                api.addLinkToMenu( navMenuL10n.homeurl, navMenuL10n.home, api.addMenuItemToTop, api.recalculateMenuItemPositions );
    505439                return false;
    506440            });
     
    667601                {
    668602                    delay: 500,
    669                     formatItem: formatAutocompleteResponse,
    670                     formatResult: formatAutocompleteResult,
     603                    formatItem: api.formatAutocompleteResponse,
     604                    formatResult: api.formatAutocompleteResult,
    671605                    minchars: 2,
    672606                    multiple: false
    673607                }
    674608            ).bind('blur', function(e) {
    675                 var changedData = autoCompleteData[this.value],
     609                var changedData = api.autoCompleteData[this.value],
    676610                inputEl = this;
    677611                if ( changedData ) {
     
    681615                        function(r) {
    682616                            that.processQuickSearchQueryResponse.call(that, r, changedData);
    683                             autoCompleteData[inputEl.value] = false;
     617                            api.autoCompleteData[inputEl.value] = false;
    684618                        }
    685619                    );
     
    821755                el.remove();
    822756                children.shiftDepthClass(-1).updateParentMenuItemDBId();
    823                 recalculateMenuItemPositions();
     757                api.recalculateMenuItemPositions();
    824758                that.checkForEmptyMenu();
    825759            });
     
    827761   
    828762        checkForEmptyMenu : function() {
    829             if( menuList.children().length ) return;
    830             menuList.height(80).one('sortstop', function(){
     763            if( api.menuList.children().length ) return;
     764            api.menuList.height(80).one('sortstop', function(){
    831765                $(this).height('auto');
    832766            });
     767        },
     768       
     769        formatAutocompleteResponse : function( resultRow, pos, total, queryTerm ) {
     770            if ( resultRow && resultRow[0] ) {
     771                var data = $.parseJSON(resultRow[0]);
     772                if ( data.post_title ) {
     773                    if ( data.ID && data.post_type )
     774                        api.autoCompleteData[data.post_title] = {ID: data.ID, object_type: data.post_type};
     775                    return data.post_title;
     776                }
     777            }
     778        },
     779
     780        formatAutocompleteResult : function( resultRow, pos, total, queryTerm ) {
     781            if ( resultRow && resultRow[0] ) {
     782                var data = $.parseJSON(resultRow[0]);
     783                if ( data.post_title )
     784                    return data.post_title;
     785            }
     786        },
     787
     788        getListDataFromID : function(menuItemID, parentEl) {
     789            if ( ! menuItemID )
     790                return false;
     791            parentEl = parentEl || document;
     792            var fields = [
     793                'menu-item-db-id',
     794                'menu-item-object-id',
     795                'menu-item-object',
     796                'menu-item-parent-id',
     797                'menu-item-position',
     798                'menu-item-type',
     799                'menu-item-append',
     800                'menu-item-title',
     801                'menu-item-url',
     802                'menu-item-description',
     803                'menu-item-attr-title',
     804                'menu-item-target',
     805                'menu-item-classes',
     806                'menu-item-xfn'
     807            ],
     808            itemData = {},
     809            inputs = parentEl.getElementsByTagName('input'),
     810            i = inputs.length,
     811            j;
     812
     813            while ( i-- ) {
     814                j = fields.length;
     815                while ( j-- ) {
     816                    if (
     817                        inputs[i] &&
     818                        inputs[i].name &&
     819                        'menu-item[' + menuItemID + '][' + fields[j] + ']' == inputs[i].name
     820                    ) {
     821                        itemData[fields[j]] = inputs[i].value;
     822                    }
     823                }
     824            }
     825
     826            return itemData;
     827        },
     828
     829        recalculateMenuItemPositions : function() {
     830            api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
     831        },
     832
     833        depthToPx : function(depth) {
     834            return depth * api.options.menuItemDepthPerLevel;
     835        },
     836
     837        pxToDepth : function(px) {
     838            return Math.floor(px / api.options.menuItemDepthPerLevel);
    833839        }
    834     }
    835 }
    836 
    837 wpNavMenu = new WPNavMenuHandler(jQuery);
    838 
    839 jQuery(function() {
    840     wpNavMenu.init();
    841 });
     840
     841    };
     842
     843    $(document).ready(function(){ wpNavMenu.init(); });
     844
     845})(jQuery);
  • trunk/wp-admin/js/nav-menu.js

    r14474 r14475  
    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;return e={init:function(){h=d("#menu-to-edit");k=h;this.jQueryExtensions();this.attachMenuEditListeners();this.setupInputWithDefaultTitle();this.attachAddMenuItemListeners();this.attachQuickSearchListeners();this.attachTabsPanelListeners();this.attachHomeLinkListener();if(h.length){this.initSortables()}this.initToggles();this.initTabManager();this.checkForEmptyMenu()},jQueryExtensions:function(){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")})})},addSelectedToMenu:function(n){return this.each(function(){var p=d(this),o={},r=p.find(".tabs-panel-active .categorychecklist li input:checked"),q=new RegExp("menu-item\\[([^\\]]*)");n=n||e.addMenuItemToBottom;if(!r.length){return false}p.find("img.waiting").show();d(r).each(function(){var s=q.exec(d(this).attr("name")),t="undefined"==typeof s[1]?0:parseInt(s[1],10);o[t]=b(t)});e.addItemToMenu(o,n,function(){r.removeAttr("checked");p.find("img.waiting").hide()})})}})},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");s=(u)?0:B.item.menuItemDepth();o(B,s);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;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(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(y<r){y=r}else{if(y>n){y=n}}if(y!=t){o(w,y)}},});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}},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(s){var r,t,o,u,n,q,p;if(s.target&&s.target.className&&-1!=s.target.className.indexOf("nav-tab-link")){o=/#(.*)$/.exec(s.target.href);u=d(s.target).parents(".inside").first()[0];n=u?u.getElementsByTagName("input"):[];q=n.length;while(q--){n[q].checked=false}d(".tabs-panel",u).each(function(){if(this.className){this.className=this.className.replace("tabs-panel-active","tabs-panel-inactive")}});d(".tabs",u).each(function(){this.className=this.className.replace("tabs","")});s.target.parentNode.className+=" tabs";if(o&&o[1]){t=document.getElementById(o[1]);if(t){t.className=t.className.replace("tabs-panel-inactive","tabs-panel-active")}}return false}else{if(s.target&&s.target.className&&-1!=s.target.className.indexOf("select-all")){r=/#(.*)$/.exec(s.target.href);if(r&&r[1]){p=d("#"+r[1]+" .tabs-panel-active .menu-item-title input");if(p.length===p.filter(":checked").length){p.removeAttr("checked")}else{p.attr("checked","checked")}return false}}}})},initTabManager:function(){var s=d(".nav-tabs-wrapper"),t=s.children(".nav-tabs"),r=t.children(".nav-tab-active"),w=t.children(".nav-tab"),p=0,x,q,v,o,u=false;function n(){q=s.offset().left;x=q+s.width();r.makeTabVisible()}d.fn.extend({makeTabVisible:function(){var z=this.eq(0),A,y;if(!z.length){return}A=z.offset().left;y=A+z.outerWidth();if(y>x){t.animate({"margin-left":"+="+(x-y)+"px"},"fast")}else{if(A<q){t.animate({"margin-left":"-="+(A-q)+"px"},"fast")}}return z},isTabVisible:function(){var z=this.eq(0),A=z.offset().left,y=A+z.outerWidth();return(y<=x&&A>=q)?true:false}});w.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});v=d('<div class="nav-tabs-arrow nav-tabs-arrow-left"><a>&laquo;</a></div>');o=d('<div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div>');s.wrap('<div class="nav-tabs-nav"/>').parent().prepend(v).append(o);n();d(window).resize(function(){if(u){return}u=true;setTimeout(function(){n();u=false},1000)});d.each([{arrow:v,next:"next",last:"first",operator:"+="},{arrow:o,next:"prev",last:"last",operator:"-="}],function(){var y=this;this.arrow.mousedown(function(){var A=w[y.last](),z=function(){if(!A.isTabVisible()){t.animate({"margin-left":y.operator+"90px"},300,"linear",z)}};z()}).mouseup(function(){var A,z;t.stop(true);A=w[y.last]();while((z=A[y.next]())&&z.length&&!z.isTabVisible()){A=z}A.makeTabVisible()})})},setupQuickSearchEventListeners:function(n){var o=this;d(n).autocomplete(ajaxurl+"?action=menu-quick-search&type="+n.name,{delay:500,formatItem:l,formatResult:m,minchars:2,multiple:false}).bind("blur",function(r){var p=i[this.value],q=this;if(p){d.post(ajaxurl+"?action=menu-quick-search&type=get-post-item&response-format=markup",p,function(s){o.processQuickSearchQueryResponse.call(o,s,p);i[q.value]=false})}})},eventOnClickEditLink:function(n){var p,o=/#(.*)$/.exec(n.href);if(o&&o[1]){p=d("#"+o[1]);if(0!=p.length){if(p.hasClass("menu-item-edit-inactive")){p.slideDown("fast").siblings("dl").andSelf().removeClass("menu-item-edit-inactive").addClass("menu-item-edit-active")}else{p.slideUp("fast").siblings("dl").andSelf().removeClass("menu-item-edit-active").addClass("menu-item-edit-inactive")}return false}}},eventOnClickCloseLink:function(n){d(n).closest(".menu-item-settings").siblings("dl").find(".item-edit").click();return false},eventOnClickMenuDelete:function(n){if(confirm(navMenuL10n.warnDeleteMenu)){return true}else{return false}},eventOnClickMenuItemDelete:function(n){var q,p,o=this;if(confirm(navMenuL10n.warnDeleteMenuItem)){p=/_wpnonce=([a-zA-Z0-9]*)$/.exec(n.href);if(p&&p[1]){q=parseInt(n.id.replace("delete-",""),10);d.post(ajaxurl,{action:"delete-menu-item","menu-item":q,_wpnonce:p[1]},function(r){if("1"==r){o.removeMenuItem(document.getElementById("menu-item-"+q))}});return false}return true}else{return false}},processQuickSearchQueryResponse:function(r,w){if(!w){w={}}var o=document.createElement("ul"),n=document.getElementById("nav-menu-meta"),s,v,p,x,t,u=new RegExp("menu-item\\[([^\\]]*)"),q;p=u.exec(r);if(p&&p[1]){t=p[1];while(n.elements["menu-item["+t+"][menu-item-type]"]){t--}if(t!=p[1]){r=r.replace(new RegExp("menu-item\\["+p[1]+"\\]","g"),"menu-item["+t+"]")}}o.innerHTML=r;v=o.getElementsByTagName("li");if(v[0]&&w.object_type){q=document.getElementById(w.object_type+"-search-checklist");if(q){q.appendChild(v[0])}}else{if(w.type){p=/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*)/.exec(w.type);if(p&&p[2]){q=document.getElementById(p[2]+"-search-checklist");if(q){s=v.length;if(!s){x=document.createElement("li");x.appendChild(document.createTextNode(navMenuL10n.noResultsFound));q.appendChild(x)}while(s--){q.appendChild(v[s])}}}}}},removeMenuItem:function(o){o=d(o);var n=o.childMenuItems(),p=this;o.addClass("deleting").fadeOut(350,function(){o.remove();n.shiftDepthClass(-1).updateParentMenuItemDBId();a();p.checkForEmptyMenu()})},checkForEmptyMenu:function(){if(h.children().length){return}h.height(80).one("sortstop",function(){d(this).height("auto")})}}};wpNavMenu=new WPNavMenuHandler(jQuery);jQuery(function(){wpNavMenu.init()});
     1var 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();this.checkForEmptyMenu()},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 i=0,h,g,c,f=a.menuList.offset().left,j,e;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(r,q){var l,p,o,m,n;e=q.item.children(".menu-item-transport");h=(j)?0:q.item.menuItemDepth();d(q,h);o=(q.item.next()[0]==q.placeholder[0])?q.item.next():q.item;m=o.childMenuItems();e.append(m);k(q);l=e.outerHeight();l+=(l>0)?(q.placeholder.css("margin-top").slice(0,-2)*1):0;l+=q.helper.outerHeight();l-=2;q.placeholder.height(l);n=h;m.each(function(){var s=b(this).menuItemDepth();n=(s>n)?s:n});p=q.helper.find(".menu-item-handle").outerWidth();p+=a.depthToPx(n-h);p-=2;q.placeholder.width(p)},stop:function(o,n){var m,l=i-h;m=e.children().insertAfter(n.item);if(l!=0){n.item.updateDepthClass(i);m.shiftDepthClass(l)}n.item.updateParentMenuItemDBId();a.recalculateMenuItemPositions()},change:function(m,l){if(!l.placeholder.parent().hasClass("menu")){l.placeholder.appendTo(a.menuList)}k(l)},sort:function(m,l){var n=a.pxToDepth(l.helper.offset().left-f);if(n<g){n=g}else{if(n>c){n=c}}if(n!=i){d(l,n)}}});function k(n){var m=n.placeholder.prev(),l=n.placeholder.next(),o;if(m[0]==n.item[0]){m=m.prev()}if(l[0]==n.item[0]){l=l.next()}g=(l.length)?l.menuItemDepth():0;if(m.length){c=((o=m.menuItemDepth()+1)>a.options.globalMaxDepth)?a.options.globalMaxDepth:o}else{c=0}}function d(l,m){l.placeholder.updateDepthClass(m,i);i=m}},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){i.animate({"margin-left":"-="+(p-f)+"px"},"fast")}}return o},isTabVisible:function(){var o=this.eq(0),p=o.offset().left,n=p+o.outerWidth();return(n<=m&&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('<div class="nav-tabs-arrow nav-tabs-arrow-left"><a>&laquo;</a></div>');d=b('<div class="nav-tabs-arrow nav-tabs-arrow-right"><a>&raquo;</a></div>');h.wrap('<div class="nav-tabs-nav"/>').parent().prepend(k).append(d);c();b(window).resize(function(){if(j){return}j=true;setTimeout(function(){c();j=false},1000)});b.each([{arrow:k,next:"next",last:"first",operator:"+="},{arrow:d,next:"prev",last:"last",operator:"-="}],function(){var n=this;this.arrow.mousedown(function(){var p=l[n.last](),o=function(){if(!p.isTabVisible()){i.animate({"margin-left":n.operator+"90px"},300,"linear",o)}};o()}).mouseup(function(){var p,o;i.stop(true);p=l[n.last]();while((o=p[n.next]())&&o.length&&!o.isTabVisible()){p=o}p.makeTabVisible()})})},setupQuickSearchEventListeners:function(c){var d=this;b(c).autocomplete(ajaxurl+"?action=menu-quick-search&type="+c.name,{delay:500,formatItem:a.formatAutocompleteResponse,formatResult:a.formatAutocompleteResult,minchars:2,multiple:false}).bind("blur",function(h){var f=a.autoCompleteData[this.value],g=this;if(f){b.post(ajaxurl+"?action=menu-quick-search&type=get-post-item&response-format=markup",f,function(e){d.processQuickSearchQueryResponse.call(d,e,f);a.autoCompleteData[g.value]=false})}})},eventOnClickEditLink:function(c){var e,d=/#(.*)$/.exec(c.href);if(d&&d[1]){e=b("#"+d[1]);if(0!=e.length){if(e.hasClass("menu-item-edit-inactive")){e.slideDown("fast").siblings("dl").andSelf().removeClass("menu-item-edit-inactive").addClass("menu-item-edit-active")}else{e.slideUp("fast").siblings("dl").andSelf().removeClass("menu-item-edit-active").addClass("menu-item-edit-inactive")}return false}}},eventOnClickCloseLink:function(c){b(c).closest(".menu-item-settings").siblings("dl").find(".item-edit").click();return false},eventOnClickMenuDelete:function(c){if(confirm(navMenuL10n.warnDeleteMenu)){return true}else{return false}},eventOnClickMenuItemDelete:function(c){var f,e,d=this;if(confirm(navMenuL10n.warnDeleteMenuItem)){e=/_wpnonce=([a-zA-Z0-9]*)$/.exec(c.href);if(e&&e[1]){f=parseInt(c.id.replace("delete-",""),10);b.post(ajaxurl,{action:"delete-menu-item","menu-item":f,_wpnonce:e[1]},function(g){if("1"==g){d.removeMenuItem(document.getElementById("menu-item-"+f))}});return false}return true}else{return false}},processQuickSearchQueryResponse:function(g,m){if(!m){m={}}var d=document.createElement("ul"),c=document.getElementById("nav-menu-meta"),h,l,e,n,j,k=new RegExp("menu-item\\[([^\\]]*)"),f;e=k.exec(g);if(e&&e[1]){j=e[1];while(c.elements["menu-item["+j+"][menu-item-type]"]){j--}if(j!=e[1]){g=g.replace(new RegExp("menu-item\\["+e[1]+"\\]","g"),"menu-item["+j+"]")}}d.innerHTML=g;l=d.getElementsByTagName("li");if(l[0]&&m.object_type){f=document.getElementById(m.object_type+"-search-checklist");if(f){f.appendChild(l[0])}}else{if(m.type){e=/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*)/.exec(m.type);if(e&&e[2]){f=document.getElementById(e[2]+"-search-checklist");if(f){h=l.length;if(!h){n=document.createElement("li");n.appendChild(document.createTextNode(navMenuL10n.noResultsFound));f.appendChild(n)}while(h--){f.appendChild(l[h])}}}}}},removeMenuItem:function(d){d=b(d);var c=d.childMenuItems(),e=this;d.addClass("deleting").fadeOut(350,function(){d.remove();c.shiftDepthClass(-1).updateParentMenuItemDBId();a.recalculateMenuItemPositions();e.checkForEmptyMenu()})},checkForEmptyMenu:function(){if(a.menuList.children().length){return}a.menuList.height(80).one("sortstop",function(){b(this).height("auto")})},formatAutocompleteResponse:function(c,g,d,f){if(c&&c[0]){var e=b.parseJSON(c[0]);if(e.post_title){if(e.ID&&e.post_type){a.autoCompleteData[e.post_title]={ID:e.ID,object_type:e.post_type}}return e.post_title}}},formatAutocompleteResult:function(c,g,d,f){if(c&&c[0]){var e=b.parseJSON(c[0]);if(e.post_title){return e.post_title}}},getListDataFromID:function(k,h){if(!k){return false}h=h||document;var d=["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"],c={},e=h.getElementsByTagName("input"),g=e.length,f;while(g--){f=d.length;while(f--){if(e[g]&&e[g].name&&"menu-item["+k+"]["+d[f]+"]"==e[g].name){c[d[f]]=e[g].value}}}return c},recalculateMenuItemPositions:function(){a.menuList.find(".menu-item-data-position").val(function(c){return c+1})},depthToPx:function(c){return c*a.options.menuItemDepthPerLevel},pxToDepth:function(c){return Math.floor(c/a.options.menuItemDepthPerLevel)}};b(document).ready(function(){wpNavMenu.init()})})(jQuery);
  • trunk/wp-includes/script-loader.php

    r14472 r14475  
    394394
    395395        // Custom Navigation
    396         $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100506' );
     396        $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100506b' );
    397397        $scripts->localize( 'nav-menu', 'navMenuL10n', array(
    398398            'home' => _x('Home', 'nav menu home label'),
Note: See TracChangeset for help on using the changeset viewer.