Make WordPress Core

Ticket #13283: 13283.diff

File 13283.diff, 11.8 KB (added by koopersmith, 15 years ago)
  • wp-admin/includes/nav-menu.php

     
    406406        $mods = get_nav_menu_locations();
    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                ?>
    412412                <p>
     
    619619                        }
    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
    626627                        <ul id="<?php echo $post_type_name; ?>-search-checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear">
     
    794795                        }
    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
    801803                        <ul id="<?php echo $taxonomy_name; ?>-search-checklist" class="list:<?php echo $taxonomy_name?> categorychecklist form-no-clear">
  • wp-admin/js/nav-menu.dev.js

     
    2121               
    2222                menuList : undefined,   // Set in init.
    2323                targetList : undefined, // Set in init.
    24                
    25                 autoCompleteData : {},
    2624
    2725                // Functions that run on init.
    2826                init : function() {
     
    346344                },
    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                         });
     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');
    363363                },
    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 
     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                },
    389388       
     
    463462
    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;
     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');
    477482
    478                                         $('.tabs-panel', wrapper).each(function() {
    479                                                 if ( this.className )
    480                                                         this.className = this.className.replace('tabs-panel-active', 'tabs-panel-inactive');
    481                                         });
     483                                        $('.tabs', wrapper).removeClass('tabs');
     484                                        target.parent().addClass('tabs');
    482485
    483                                         $('.tabs', wrapper).each(function() {
    484                                                 this.className = this.className.replace('tabs', '');
    485                                         });
     486                                        // select the search bar
     487                                        $('.quick-search', wrapper).focus();
    486488
    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                                         }
    495 
    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] ) {
    500493                                                items = $('#' + selectAreaMatch[1] + ' .tabs-panel-active .menu-item-title input');
     
    611604                        });
    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,
    647609                        matchedSection = /#(.*)$/.exec(clickedEl.href);
     
    718680                 *
    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;
     689                        pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'),
     690                        items = resp.match(/<li>.*<\/li>/g);
    734691
    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                                 }
     692                        if( ! items ) {                         
     693                                $('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' );
     694                                $('img.waiting', panel).hide();
     695                                return;
    746696                        }
    747697
    748                         wrap.innerHTML = resp;
     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                                        }
    749707
    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                                                 }
     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 + ']');
    771711                                        }
    772712                                }
    773713                        }
     714
     715                        $('.categorychecklist', panel).html( items.join('') );
     716                        $('img.waiting', panel).hide();
    774717                },
    775718
    776719                removeMenuItem : function(el) {
     
    783726                                children.shiftDepthClass(-1).updateParentMenuItemDBId();
    784727                        });
    785728                },
    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                 },
    797729
    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                         }
    804                 },
    805 
    806730                getListDataFromID : function(menuItemID, parentEl) {
    807731                        if ( ! menuItemID )
    808732                                return false;
  • wp-admin/nav-menus.php

     
    2727wp_enqueue_script( 'jquery-ui-draggable' );
    2828wp_enqueue_script( 'jquery-ui-droppable' );
    2929wp_enqueue_script( 'jquery-ui-sortable' );
    30 wp_enqueue_script( 'jquery-autocomplete' );
    3130
    3231// Nav Menu functions
    3332wp_enqueue_script( 'nav-menu' );