WordPress.org

Make WordPress Core

Changeset 14686


Ignore:
Timestamp:
05/16/10 05:39:53 (5 years ago)
Author:
nacin
Message:

First pass at fixing search for add menu item boxes. props koopersmith, see #13283.

Location:
trunk
Files:
5 edited

Legend:

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

    r14675 r14686  
    407407    $menus = wp_get_nav_menus(); 
    408408    $menu_locations = get_nav_menu_locations(); 
    409     //var_dump( $menus ); 
     409 
    410410    foreach ( $locations as $location => $description ) { 
    411411        ?> 
     
    620620            ?> 
    621621            <p class="quick-search-wrap"> 
    622                 <input type="text" class="quick-search regular-text" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" /> 
    623                 <input type="submit" class="quick-search-submit button-secondary" value="<?php esc_attr_e('Search'); ?>" /> 
     622                <input type="text" class="quick-search regular-text input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" /> 
     623                <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 
     624                <input type="submit" class="quick-search-submit button-secondary hide-if-js" value="<?php esc_attr_e('Search'); ?>" /> 
    624625            </p> 
    625626 
     
    795796            ?> 
    796797            <p class="quick-search-wrap"> 
    797                 <input type="text" class="quick-search regular-text" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" /> 
    798                 <input type="submit" class="quick-search-submit button-secondary" value="<?php esc_attr_e('Search'); ?>" /> 
     798                <input type="text" class="quick-search regular-text input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" /> 
     799                <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 
     800                <input type="submit" class="quick-search-submit button-secondary hide-if-js" value="<?php esc_attr_e('Search'); ?>" /> 
    799801            </p> 
    800802 
  • trunk/wp-admin/js/nav-menu.dev.js

    r14615 r14686  
    2222        menuList : undefined,   // Set in init. 
    2323        targetList : undefined, // Set in init. 
    24          
    25         autoCompleteData : {}, 
    2624 
    2725        // Functions that run on init. 
     
    347345     
    348346        attachQuickSearchListeners : function() { 
    349             var that = this, 
    350                 form = $('#nav-menu-meta'); 
     347            var searchTimer; 
    351348             
    352             // auto-suggest for the quick-search boxes 
    353             $('input.quick-search').each(function(i, el) { 
    354                 that.setupQuickSearchEventListeners(el); 
    355             }); 
    356             form.find('.quick-search-submit').click(function() { 
    357                 $(this).trigger('wp-quick-search'); 
    358                 return false; 
    359             }); 
    360             form.find('.inside').children().bind('wp-quick-search', function() { 
    361                 that.quickSearch( $(this).attr('id') ); 
    362             }); 
    363         }, 
    364      
    365         quickSearch : function(id) { 
    366             var type = $('#' + id + ' .quick-search').attr('name'), 
    367             q = $('#' + id + ' .quick-search').val(), 
    368             menu = $('#menu').val(), 
    369             nonce = $('#menu-settings-column-nonce').val(), 
    370             params = {}, 
    371             that = this, 
    372             processMethod = function(){}; 
    373  
    374             processMethod = that.processQuickSearchQueryResponse; 
    375  
     349            $('.quick-search').keypress(function(e){ 
     350                var t = $(this); 
     351                 
     352                if( 13 == e.which ) { 
     353                    api.updateQuickSearchResults( t ); 
     354                    return false; 
     355                } 
     356                 
     357                if( searchTimer ) clearTimeout(searchTimer); 
     358                 
     359                searchTimer = setTimeout(function(){ 
     360                    api.updateQuickSearchResults( t ); 
     361                }, 400); 
     362            }).attr('autocomplete','off'); 
     363        }, 
     364         
     365        updateQuickSearchResults : function(input) { 
     366            var panel, params, 
     367            minSearchLength = 2, 
     368            q = input.val(); 
     369             
     370            if( q.length < minSearchLength ) return; 
     371             
     372            panel = input.parents('.tabs-panel'); 
    376373            params = { 
    377374                'action': 'menu-quick-search', 
    378375                'response-format': 'markup', 
    379                 'menu': menu, 
    380                 'menu-settings-column-nonce': nonce, 
     376                'menu': $('#menu').val(), 
     377                'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(), 
    381378                'q': q, 
    382                 'type': type 
     379                'type': input.attr('name') 
    383380            }; 
    384381 
     382            $('img.waiting', panel).show(); 
     383 
    385384            $.post( ajaxurl, params, function(menuMarkup) { 
    386                 processMethod.call(that, menuMarkup, params); 
     385                api.processQuickSearchQueryResponse(menuMarkup, params, panel); 
    387386            }); 
    388387        }, 
     
    464463        attachTabsPanelListeners : function() { 
    465464            $('#menu-settings-column').bind('click', function(e) { 
    466                 var selectAreaMatch, activePanel, panelIdMatch, wrapper, inputs, i, items; 
     465                var selectAreaMatch, activePanel, panelId, wrapper, items, 
     466                    target = $(e.target); 
    467467                 
    468                 if ( e.target && e.target.className && -1 != e.target.className.indexOf('nav-tab-link') ) { 
    469                     panelIdMatch = /#(.*)$/.exec(e.target.href); 
    470                     wrapper = $(e.target).parents('.inside').first()[0]; 
    471                     inputs = wrapper ? wrapper.getElementsByTagName('input') : []; 
    472                     i = inputs.length; 
     468                if ( target.hasClass('nav-tab-link') ) { 
     469                    panelId = /#(.*)$/.exec(e.target.href); 
     470                    if ( panelId && panelId[1] ) 
     471                        panelId = panelId[1] 
     472                    else 
     473                        return false; 
     474                         
     475                    wrapper = target.parents('.inside').first(); 
    473476 
    474477                    // upon changing tabs, we want to uncheck all checkboxes 
    475                     while( i-- ) 
    476                         inputs[i].checked = false; 
    477  
    478                     $('.tabs-panel', wrapper).each(function() { 
    479                         if ( this.className ) 
    480                             this.className = this.className.replace('tabs-panel-active', 'tabs-panel-inactive'); 
    481                     }); 
    482  
    483                     $('.tabs', wrapper).each(function() { 
    484                         this.className = this.className.replace('tabs', ''); 
    485                     }); 
    486  
    487                     e.target.parentNode.className += ' tabs'; 
    488  
    489                     if ( panelIdMatch && panelIdMatch[1] ) { 
    490                         activePanel = document.getElementById(panelIdMatch[1]); 
    491                         if ( activePanel ) { 
    492                             activePanel.className = activePanel.className.replace('tabs-panel-inactive', 'tabs-panel-active'); 
    493                         } 
    494                     } 
     478                    $('input', wrapper).removeAttr('checked'); 
     479                     
     480                    $('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive'); 
     481                    $('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active'); 
     482 
     483                    $('.tabs', wrapper).removeClass('tabs'); 
     484                    target.parent().addClass('tabs'); 
     485 
     486                    // select the search bar 
     487                    $('.quick-search', wrapper).focus(); 
    495488 
    496489                    return false; 
    497                 } else if ( e.target && e.target.className && -1 != e.target.className.indexOf('select-all') ) { 
     490                } else if ( target.hasClass('select-all') ) { 
    498491                    selectAreaMatch = /#(.*)$/.exec(e.target.href); 
    499492                    if ( selectAreaMatch && selectAreaMatch[1] ) { 
     
    612605        }, 
    613606 
    614         /** 
    615          * Set up quick-search input fields' events. 
    616          * 
    617          * @param object el The input element. 
    618          */ 
    619         setupQuickSearchEventListeners : function(el) { 
    620             var that = this; 
    621             $(el).autocomplete( ajaxurl + '?action=menu-quick-search&type=' + el.name, 
    622                 { 
    623                     delay: 500, 
    624                     formatItem: api.formatAutocompleteResponse, 
    625                     formatResult: api.formatAutocompleteResult, 
    626                     minchars: 2, 
    627                     multiple: false 
    628                 } 
    629             ).bind('blur', function(e) { 
    630                 var changedData = api.autoCompleteData[this.value], 
    631                 inputEl = this; 
    632                 if ( changedData ) { 
    633                     $.post( 
    634                         ajaxurl + '?action=menu-quick-search&type=get-post-item&response-format=markup', 
    635                         changedData, 
    636                         function(r) { 
    637                             that.processQuickSearchQueryResponse.call(that, r, changedData); 
    638                             api.autoCompleteData[inputEl.value] = false; 
    639                         } 
    640                     ); 
    641                 } 
    642             }); 
    643         }, 
    644  
    645607        eventOnClickEditLink : function(clickedEl) { 
    646608            var activeEdit, 
     
    719681         * @param string resp The server response to the query. 
    720682         * @param object req The request arguments. 
     683         * @param jQuery panel The tabs panel we're searching in. 
    721684         */ 
    722         processQuickSearchQueryResponse : function(resp, req) { 
    723             if ( ! req ) 
    724                 req = {}; 
    725             var wrap = document.createElement('ul'), 
     685        processQuickSearchQueryResponse : function(resp, req, panel) { 
     686            var i, matched, newID, 
     687            takenIDs = {}, 
    726688            form = document.getElementById('nav-menu-meta'), 
    727             i, 
    728             items, 
    729             matched, 
    730             message, 
    731             newID, 
    732             pattern = new RegExp('menu-item\\[(\[^\\]\]*)'), 
    733             resultList; 
    734  
    735             // make a unique DB ID number 
    736             matched = pattern.exec(resp); 
    737             if ( matched && matched[1] ) { 
    738                 newID = matched[1]; 
    739                 while( form.elements['menu-item[' + newID + '][menu-item-type]'] ) { 
    740                     newID--; 
    741                 } 
    742  
    743                 if ( newID != matched[1] ) { 
    744                     resp = resp.replace(new RegExp('menu-item\\[' + matched[1] + '\\]', 'g'), 'menu-item[' + newID + ']'); 
    745                 } 
    746             } 
    747  
    748             wrap.innerHTML = resp; 
    749  
    750             items = wrap.getElementsByTagName('li'); 
    751  
    752             if ( items[0] && req.object_type ) { 
    753                 resultList = document.getElementById(req.object_type + '-search-checklist'); 
    754                 if ( resultList ) { 
    755                     resultList.appendChild(items[0]); 
    756                 } 
    757             } else if ( req.type ) { 
    758                 matched = /quick-search-(posttype|taxonomy)-([a-zA-Z_-]*)/.exec(req.type); 
    759                 if ( matched && matched[2] ) { 
    760                     resultList = document.getElementById(matched[2] + '-search-checklist'); 
    761                     if ( resultList ) { 
    762                         i = items.length; 
    763                         if ( ! i ) { 
    764                             message = document.createElement('li'); 
    765                             message.appendChild(document.createTextNode(navMenuL10n.noResultsFound)); 
    766                             resultList.appendChild(message); 
    767                         } 
    768                         while( i-- ) { 
    769                             resultList.appendChild(items[i]); 
    770                         } 
    771                     } 
    772                 } 
    773             } 
     689            pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'), 
     690            items = resp.match(/<li>.*<\/li>/g); 
     691 
     692            if( ! items ) {              
     693                $('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' ); 
     694                $('img.waiting', panel).hide(); 
     695                return; 
     696            } 
     697 
     698            i = items.length; 
     699            while( i-- ) { 
     700                // make a unique DB ID number 
     701                matched = pattern.exec(items[i]); 
     702                if ( matched && matched[1] ) { 
     703                    newID = matched[1]; 
     704                    while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) { 
     705                        newID--; 
     706                    } 
     707 
     708                    takenIDs[newID] = true; 
     709                    if ( newID != matched[1] ) { 
     710                        items[i] = items[i].replace(new RegExp('menu-item\\[' + matched[1] + '\\]', 'g'), 'menu-item[' + newID + ']'); 
     711                    } 
     712                } 
     713            } 
     714 
     715            $('.categorychecklist', panel).html( items.join('') ); 
     716            $('img.waiting', panel).hide(); 
    774717        }, 
    775718 
     
    783726                children.shiftDepthClass(-1).updateParentMenuItemDBId(); 
    784727            }); 
    785         }, 
    786          
    787         formatAutocompleteResponse : function( resultRow, pos, total, queryTerm ) { 
    788             if ( resultRow && resultRow[0] ) { 
    789                 var data = $.parseJSON(resultRow[0]); 
    790                 if ( data.post_title ) { 
    791                     if ( data.ID && data.post_type ) 
    792                         api.autoCompleteData[data.post_title] = {ID: data.ID, object_type: data.post_type}; 
    793                     return data.post_title; 
    794                 } 
    795             } 
    796         }, 
    797  
    798         formatAutocompleteResult : function( resultRow, pos, total, queryTerm ) { 
    799             if ( resultRow && resultRow[0] ) { 
    800                 var data = $.parseJSON(resultRow[0]); 
    801                 if ( data.post_title ) 
    802                     return data.post_title; 
    803             } 
    804728        }, 
    805729 
  • trunk/wp-admin/js/nav-menu.js

    r14615 r14686  
    1 var 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()},jQueryExtensions:function(){b.fn.extend({menuItemDepth:function(){return a.pxToDepth(this.eq(0).css("margin-left").slice(0,-2))},updateDepthClass:function(d,c){return this.each(function(){var e=b(this);c=c||e.menuItemDepth();b(this).removeClass("menu-item-depth-"+c).addClass("menu-item-depth-"+d)})},shiftDepthClass:function(c){return this.each(function(){var d=b(this),e=d.menuItemDepth();b(this).removeClass("menu-item-depth-"+e).addClass("menu-item-depth-"+(e+c))})},childMenuItems:function(){var c=b();this.each(function(){var d=b(this),f=d.menuItemDepth(),e=d.next();while(e.length&&e.menuItemDepth()>f){c=c.add(e);e=e.next()}});return c},updateParentMenuItemDBId:function(){return this.each(function(){var e=b(this),c=e.find(".menu-item-data-parent-id"),f=e.menuItemDepth(),d=e.prev();if(f==0){c.val(0)}else{while(d.menuItemDepth()!=f-1){d=d.prev()}c.val(d.find(".menu-item-data-db-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var c=b(this);b(".hide-column-tog").not(":checked").each(function(){c.find(".field-"+b(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(c){return this.each(function(){var e=b(this),d={},g=e.find(".tabs-panel-active .categorychecklist li input:checked"),f=new RegExp("menu-item\\[([^\\]]*)");c=c||a.addMenuItemToBottom;if(!g.length){return false}e.find("img.waiting").show();b(g).each(function(){var h=f.exec(b(this).attr("name")),i="undefined"==typeof h[1]?0:parseInt(h[1],10);d[i]=a.getListDataFromID(i)});a.addItemToMenu(d,c,function(){g.removeAttr("checked");e.find("img.waiting").hide()})})}})},initToggles:function(){postboxes.add_postbox_toggles("nav-menus");columns.useCheckboxesForHidden();columns.checked=function(c){b(".field-"+c).removeClass("hidden-field")};columns.unchecked=function(c){b(".field-"+c).addClass("hidden-field")};a.menuList.hideAdvancedMenuItemFields()},initSortables:function(){var m=0,l,j,e,h,n,k,o,d,g,i=a.menuList.offset().left;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(w,v){var p,t,s,q,r,u;g=v.item.children(".menu-item-transport");l=v.item.menuItemDepth();f(v,l);s=(v.item.next()[0]==v.placeholder[0])?v.item.next():v.item;q=s.childMenuItems();g.append(q);p=g.outerHeight();p+=(p>0)?(v.placeholder.css("margin-top").slice(0,-2)*1):0;p+=v.helper.outerHeight();d=p;p-=2;v.placeholder.height(p);r=l;q.each(function(){var x=b(this).menuItemDepth();r=(x>r)?x:r});t=v.helper.find(".menu-item-handle").outerWidth();t+=a.depthToPx(r-l);t-=2;v.placeholder.width(t);u=v.placeholder.next();u.css("margin-top",d+"px");v.placeholder.detach();b(this).sortable("refresh");v.item.after(v.placeholder);u.css("margin-top",0);c(v)},stop:function(s,r){var q,p=m-l;q=g.children().insertAfter(r.item);if(p!=0){r.item.updateDepthClass(m);q.shiftDepthClass(p)}r.item.updateParentMenuItemDBId()},change:function(q,p){if(!p.placeholder.parent().hasClass("menu")){(h.length)?h.after(p.placeholder):a.menuList.prepend(p.placeholder)}c(p)},sort:function(q,p){var s=p.helper.offset(),r=a.pxToDepth(s.left-i);if(r>e||s.top<k){r=e}else{if(r<j){r=j}}if(r!=m){f(p,r)}if(o&&s.top+d>o){n.after(p.placeholder);c(p);b(this).sortable("refreshPositions")}}});function c(p){var q;h=p.placeholder.prev();n=p.placeholder.next();if(h[0]==p.item[0]){h=h.prev()}if(n[0]==p.item[0]){n=n.next()}k=(h.length)?h.offset().top+h.height():0;o=(n.length)?n.offset().top+n.height()/3:0;j=(n.length)?n.menuItemDepth():0;if(h.length){e=((q=h.menuItemDepth()+1)>a.options.globalMaxDepth)?a.options.globalMaxDepth:q}else{e=0}}function f(p,q){p.placeholder.updateDepthClass(q,m);m=q}},attachMenuEditListeners:function(){var c=this;b("#update-nav-menu").bind("click",function(d){if(d.target&&d.target.className){if(-1!=d.target.className.indexOf("item-edit")){return c.eventOnClickEditLink(d.target)}else{if(-1!=d.target.className.indexOf("menu-save")){return c.eventOnClickMenuSave(d.target)}else{if(-1!=d.target.className.indexOf("menu-delete")){return c.eventOnClickMenuDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-delete")){return c.eventOnClickMenuItemDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-close")){return c.eventOnClickCloseLink(d.target)}}}}}}})},setupInputWithDefaultTitle:function(){var c="input-with-default-title";b("."+c).each(function(){var f=b(this),e=f.attr("title"),d=f.val();f.data(c,e);if(""==d){f.val(e)}else{if(e==d){return}else{f.removeClass(c)}}}).focus(function(){var d=b(this);if(d.val()==d.data(c)){d.val("").removeClass(c)}}).blur(function(){var d=b(this);if(""==d.val()){d.addClass(c).val(d.data(c))}})},attachAddMenuItemListeners:function(){var c=b("#nav-menu-meta");c.find(".add-to-menu input").click(function(){b(this).trigger("wp-add-menu-item",[a.addMenuItemToBottom]);return false});c.find(".customlinkdiv").bind("wp-add-menu-item",function(f,d){a.addCustomLink(d)});c.find(".posttypediv, .taxonomydiv").bind("wp-add-menu-item",function(f,d){b(this).addSelectedToMenu(d)})},attachQuickSearchListeners:function(){var 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);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},eventOnClickMenuSave:function(c){a.menuList.find(".menu-item-data-position").val(function(d){return d+1});return true},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()})},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-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},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); 
     1var wpNavMenu;(function(b){var a=wpNavMenu={options:{menuItemDepthPerLevel:30,globalMaxDepth:11},menuList:undefined,targetList:undefined,init:function(){a.menuList=b("#menu-to-edit");a.targetList=a.menuList;this.jQueryExtensions();this.attachMenuEditListeners();this.setupInputWithDefaultTitle();this.attachAddMenuItemListeners();this.attachQuickSearchListeners();this.attachTabsPanelListeners();this.attachHomeLinkListener();if(a.menuList.length){this.initSortables()}this.initToggles();this.initTabManager()},jQueryExtensions:function(){b.fn.extend({menuItemDepth:function(){return a.pxToDepth(this.eq(0).css("margin-left").slice(0,-2))},updateDepthClass:function(d,c){return this.each(function(){var e=b(this);c=c||e.menuItemDepth();b(this).removeClass("menu-item-depth-"+c).addClass("menu-item-depth-"+d)})},shiftDepthClass:function(c){return this.each(function(){var d=b(this),e=d.menuItemDepth();b(this).removeClass("menu-item-depth-"+e).addClass("menu-item-depth-"+(e+c))})},childMenuItems:function(){var c=b();this.each(function(){var d=b(this),f=d.menuItemDepth(),e=d.next();while(e.length&&e.menuItemDepth()>f){c=c.add(e);e=e.next()}});return c},updateParentMenuItemDBId:function(){return this.each(function(){var e=b(this),c=e.find(".menu-item-data-parent-id"),f=e.menuItemDepth(),d=e.prev();if(f==0){c.val(0)}else{while(d.menuItemDepth()!=f-1){d=d.prev()}c.val(d.find(".menu-item-data-db-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var c=b(this);b(".hide-column-tog").not(":checked").each(function(){c.find(".field-"+b(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(c){return this.each(function(){var e=b(this),d={},g=e.find(".tabs-panel-active .categorychecklist li input:checked"),f=new RegExp("menu-item\\[([^\\]]*)");c=c||a.addMenuItemToBottom;if(!g.length){return false}e.find("img.waiting").show();b(g).each(function(){var h=f.exec(b(this).attr("name")),i="undefined"==typeof h[1]?0:parseInt(h[1],10);d[i]=a.getListDataFromID(i)});a.addItemToMenu(d,c,function(){g.removeAttr("checked");e.find("img.waiting").hide()})})}})},initToggles:function(){postboxes.add_postbox_toggles("nav-menus");columns.useCheckboxesForHidden();columns.checked=function(c){b(".field-"+c).removeClass("hidden-field")};columns.unchecked=function(c){b(".field-"+c).addClass("hidden-field")};a.menuList.hideAdvancedMenuItemFields()},initSortables:function(){var m=0,l,j,e,h,n,k,o,d,g,i=a.menuList.offset().left;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(w,v){var p,t,s,q,r,u;g=v.item.children(".menu-item-transport");l=v.item.menuItemDepth();f(v,l);s=(v.item.next()[0]==v.placeholder[0])?v.item.next():v.item;q=s.childMenuItems();g.append(q);p=g.outerHeight();p+=(p>0)?(v.placeholder.css("margin-top").slice(0,-2)*1):0;p+=v.helper.outerHeight();d=p;p-=2;v.placeholder.height(p);r=l;q.each(function(){var x=b(this).menuItemDepth();r=(x>r)?x:r});t=v.helper.find(".menu-item-handle").outerWidth();t+=a.depthToPx(r-l);t-=2;v.placeholder.width(t);u=v.placeholder.next();u.css("margin-top",d+"px");v.placeholder.detach();b(this).sortable("refresh");v.item.after(v.placeholder);u.css("margin-top",0);c(v)},stop:function(s,r){var q,p=m-l;q=g.children().insertAfter(r.item);if(p!=0){r.item.updateDepthClass(m);q.shiftDepthClass(p)}r.item.updateParentMenuItemDBId()},change:function(q,p){if(!p.placeholder.parent().hasClass("menu")){(h.length)?h.after(p.placeholder):a.menuList.prepend(p.placeholder)}c(p)},sort:function(q,p){var s=p.helper.offset(),r=a.pxToDepth(s.left-i);if(r>e||s.top<k){r=e}else{if(r<j){r=j}}if(r!=m){f(p,r)}if(o&&s.top+d>o){n.after(p.placeholder);c(p);b(this).sortable("refreshPositions")}}});function c(p){var q;h=p.placeholder.prev();n=p.placeholder.next();if(h[0]==p.item[0]){h=h.prev()}if(n[0]==p.item[0]){n=n.next()}k=(h.length)?h.offset().top+h.height():0;o=(n.length)?n.offset().top+n.height()/3:0;j=(n.length)?n.menuItemDepth():0;if(h.length){e=((q=h.menuItemDepth()+1)>a.options.globalMaxDepth)?a.options.globalMaxDepth:q}else{e=0}}function f(p,q){p.placeholder.updateDepthClass(q,m);m=q}},attachMenuEditListeners:function(){var c=this;b("#update-nav-menu").bind("click",function(d){if(d.target&&d.target.className){if(-1!=d.target.className.indexOf("item-edit")){return c.eventOnClickEditLink(d.target)}else{if(-1!=d.target.className.indexOf("menu-save")){return c.eventOnClickMenuSave(d.target)}else{if(-1!=d.target.className.indexOf("menu-delete")){return c.eventOnClickMenuDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-delete")){return c.eventOnClickMenuItemDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-close")){return c.eventOnClickCloseLink(d.target)}}}}}}})},setupInputWithDefaultTitle:function(){var c="input-with-default-title";b("."+c).each(function(){var f=b(this),e=f.attr("title"),d=f.val();f.data(c,e);if(""==d){f.val(e)}else{if(e==d){return}else{f.removeClass(c)}}}).focus(function(){var d=b(this);if(d.val()==d.data(c)){d.val("").removeClass(c)}}).blur(function(){var d=b(this);if(""==d.val()){d.addClass(c).val(d.data(c))}})},attachAddMenuItemListeners:function(){var c=b("#nav-menu-meta");c.find(".add-to-menu input").click(function(){b(this).trigger("wp-add-menu-item",[a.addMenuItemToBottom]);return false});c.find(".customlinkdiv").bind("wp-add-menu-item",function(f,d){a.addCustomLink(d)});c.find(".posttypediv, .taxonomydiv").bind("wp-add-menu-item",function(f,d){b(this).addSelectedToMenu(d)})},attachQuickSearchListeners:function(){var c;b(".quick-search").keypress(function(f){var d=b(this);if(13==f.which){a.updateQuickSearchResults(d);return false}if(c){clearTimeout(c)}c=setTimeout(function(){a.updateQuickSearchResults(d)},400)}).attr("autocomplete","off")},updateQuickSearchResults:function(d){var c,g,e=2,f=d.val();if(f.length<e){return}c=d.parents(".tabs-panel");g={action:"menu-quick-search","response-format":"markup",menu:b("#menu").val(),"menu-settings-column-nonce":b("#menu-settings-column-nonce").val(),q:f,type:d.attr("name")};b("img.waiting",c).show();b.post(ajaxurl,g,function(h){a.processQuickSearchQueryResponse(h,g,c)})},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);return false})},attachTabsPanelListeners:function(){b("#menu-settings-column").bind("click",function(h){var f,i,d,j,c,g=b(h.target);if(g.hasClass("nav-tab-link")){d=/#(.*)$/.exec(h.target.href);if(d&&d[1]){d=d[1]}else{return false}j=g.parents(".inside").first();b("input",j).removeAttr("checked");b(".tabs-panel-active",j).removeClass("tabs-panel-active").addClass("tabs-panel-inactive");b("#"+d,j).removeClass("tabs-panel-inactive").addClass("tabs-panel-active");b(".tabs",j).removeClass("tabs");g.parent().addClass("tabs");b(".quick-search",j).focus();return false}else{if(g.hasClass("select-all")){f=/#(.*)$/.exec(h.target.href);if(f&&f[1]){c=b("#"+f[1]+" .tabs-panel-active .menu-item-title input");if(c.length===c.filter(":checked").length){c.removeAttr("checked")}else{c.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()})})},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},eventOnClickMenuSave:function(c){a.menuList.find(".menu-item-data-position").val(function(d){return d+1});return true},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,c){var h,e,j,f={},d=document.getElementById("nav-menu-meta"),l=new RegExp("menu-item\\[([^\\]]*)","g"),k=g.match(/<li>.*<\/li>/g);if(!k){b(".categorychecklist",c).html("<li><p>"+navMenuL10n.noResultsFound+"</p></li>");b("img.waiting",c).hide();return}h=k.length;while(h--){e=l.exec(k[h]);if(e&&e[1]){j=e[1];while(d.elements["menu-item["+j+"][menu-item-type]"]||f[j]){j--}f[j]=true;if(j!=e[1]){k[h]=k[h].replace(new RegExp("menu-item\\["+e[1]+"\\]","g"),"menu-item["+j+"]")}}}b(".categorychecklist",c).html(k.join(""));b("img.waiting",c).hide()},removeMenuItem:function(d){d=b(d);var c=d.childMenuItems(),e=this;d.addClass("deleting").fadeOut(350,function(){d.remove();c.shiftDepthClass(-1).updateParentMenuItemDBId()})},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-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},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-admin/nav-menus.php

    r14683 r14686  
    2828wp_enqueue_script( 'jquery-ui-droppable' ); 
    2929wp_enqueue_script( 'jquery-ui-sortable' ); 
    30 wp_enqueue_script( 'jquery-autocomplete' ); 
    3130 
    3231// Nav Menu functions 
  • trunk/wp-includes/script-loader.php

    r14684 r14686  
    394394 
    395395        // Custom Navigation 
    396         $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100513' ); 
     396        $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100515' ); 
    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.