Make WordPress Core

Changeset 8214


Ignore:
Timestamp:
06/30/2008 12:04:22 AM (18 years ago)
Author:
markjaquith
Message:

Enable tag auto-suggest for multiple tags at once (without having to hit enter and send each one "down below"). fixes #5580

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r8011 r8214  
    1414        $s = $_GET['q']; // is this slashed already?
    1515
    16         if ( strstr( $s, ',' ) )
    17                 die; // it's a multiple tag insert, we won't find anything
    18         $results = $wpdb->get_col( $wpdb->prepare("SELECT name FROM $wpdb->terms WHERE name LIKE (%s)", '%' . $s . '%') );
     16        if ( strstr( $s, ',' ) ) {
     17                $s = explode( ',', $s );
     18                $s = $s[count( $s ) - 1];
     19        }
     20        $s = trim( $s );
     21        if ( strlen( $s ) < 2 )
     22         die; // require 2 chars for matching
     23        $results = $wpdb->get_col( "SELECT name FROM $wpdb->terms WHERE name LIKE ('%". $s . "%')" );
    1924        echo join( $results, "\n" );
    2025        die;
  • trunk/wp-admin/js/post.js

    r8177 r8214  
    9999
    100100        // auto-suggest stuff
    101         jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2 } );
     101        jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
    102102        jQuery('#newtag').keypress( tag_press_key );
    103103
  • trunk/wp-includes/js/jquery/suggest.js

    r7324 r8214  
    11/*
    2  *      jquery.suggest 1.1 - 2007-08-06
     2 *      jquery.suggest 1.1b - 2007-08-06
     3 * Patched by Mark Jaquith with Alexander Dick's "multiple items" patch to allow for auto-suggesting of more than one tag before submitting
     4 * See: http://www.vulgarisoip.com/2007/06/29/jquerysuggest-an-alternative-jquery-based-autocomplete-library/#comment-7228
    35 *     
    46 *      Uses code and techniques from following libraries:
     
    114116                        var q = $.trim($input.val());
    115117
     118                        if ( options.multiple ) {
     119                                var multipleSepPos = q.lastIndexOf(options.multipleSep);
     120                                if ( multipleSepPos != -1 ) {
     121                                        q = q.substr(multipleSepPos + options.multipleSep.length);
     122                                }
     123                        }
    116124                        if (q.length >= options.minchars) {
    117125                               
     
    246254               
    247255                        if ($currentResult) {
    248                                 $input.val($currentResult.text());
     256                                if ( options.multiple ) {
     257                                        if ( $input.val().indexOf(options.multipleSep) != -1 ) {
     258                                                $currentVal = $input.val().substr( 0, ( $input.val().lastIndexOf(options.multipleSep) + options.multipleSep.length ) );
     259                                        } else {
     260                                                $currentVal = "";
     261                                        }
     262                                        $input.val( $currentVal + $currentResult.text() + options.multipleSep);
     263                                        $input.focus();
     264                                } else {
     265                                        $input.val($currentResult.text());
     266                                }
    249267                                $results.hide();
    250268                               
     
    292310       
    293311                options = options || {};
     312                options.multiple = options.multiple || false;
     313                options.multipleSep = options.multipleSep || ", ";
    294314                options.source = source;
    295315                options.delay = options.delay || 100;
  • trunk/wp-includes/script-loader.php

    r8206 r8214  
    7171        $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561');
    7272        $scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' );
    73         $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('jquery'), '1.1');
     73        $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('jquery'), '1.1b');
    7474        $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20');
    7575        $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430');
     
    139139                        'cancel' => __('Cancel'),
    140140                ) );
    141                 $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080623' );
     141                $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080629' );
    142142                $scripts->localize( 'post', 'postL10n', array(
    143143                        'tagsUsed' =>  __('Tags used on this post:'),
Note: See TracChangeset for help on using the changeset viewer.