From 93aa40cbffc7e6066fd7c29541f384ddfbd60928 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Mon, 30 Jun 2008 00:04:22 +0000 Subject: [PATCH] Enable tag auto-suggest for multiple tags at once (without having to hit enter and send each one "down below"). fixes #5580 git-svn-id: https://develop.svn.wordpress.org/trunk@8214 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-ajax.php | 11 ++++++++--- wp-admin/js/post.js | 2 +- wp-includes/js/jquery/suggest.js | 24 ++++++++++++++++++++++-- wp-includes/script-loader.php | 4 ++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index aef321fa7a..b2049e6a04 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -13,9 +13,14 @@ if ( isset($_GET['action']) && 'ajax-tag-search' == $_GET['action'] ) { $s = $_GET['q']; // is this slashed already? - if ( strstr( $s, ',' ) ) - die; // it's a multiple tag insert, we won't find anything - $results = $wpdb->get_col( $wpdb->prepare("SELECT name FROM $wpdb->terms WHERE name LIKE (%s)", '%' . $s . '%') ); + if ( strstr( $s, ',' ) ) { + $s = explode( ',', $s ); + $s = $s[count( $s ) - 1]; + } + $s = trim( $s ); + if ( strlen( $s ) < 2 ) + die; // require 2 chars for matching + $results = $wpdb->get_col( "SELECT name FROM $wpdb->terms WHERE name LIKE ('%". $s . "%')" ); echo join( $results, "\n" ); die; } diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index 273a6a49a3..8f786d2166 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -98,7 +98,7 @@ jQuery(document).ready( function() { jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } ); // auto-suggest stuff - jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2 } ); + jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } ); jQuery('#newtag').keypress( tag_press_key ); // category tabs diff --git a/wp-includes/js/jquery/suggest.js b/wp-includes/js/jquery/suggest.js index d0f4578b14..344008d761 100644 --- a/wp-includes/js/jquery/suggest.js +++ b/wp-includes/js/jquery/suggest.js @@ -1,5 +1,7 @@ /* - * jquery.suggest 1.1 - 2007-08-06 + * jquery.suggest 1.1b - 2007-08-06 + * Patched by Mark Jaquith with Alexander Dick's "multiple items" patch to allow for auto-suggesting of more than one tag before submitting + * See: http://www.vulgarisoip.com/2007/06/29/jquerysuggest-an-alternative-jquery-based-autocomplete-library/#comment-7228 * * Uses code and techniques from following libraries: * 1. http://www.dyve.net/jquery/?autocomplete @@ -113,6 +115,12 @@ var q = $.trim($input.val()); + if ( options.multiple ) { + var multipleSepPos = q.lastIndexOf(options.multipleSep); + if ( multipleSepPos != -1 ) { + q = q.substr(multipleSepPos + options.multipleSep.length); + } + } if (q.length >= options.minchars) { cached = checkCache(q); @@ -245,7 +253,17 @@ $currentResult = getCurrentResult(); if ($currentResult) { - $input.val($currentResult.text()); + if ( options.multiple ) { + if ( $input.val().indexOf(options.multipleSep) != -1 ) { + $currentVal = $input.val().substr( 0, ( $input.val().lastIndexOf(options.multipleSep) + options.multipleSep.length ) ); + } else { + $currentVal = ""; + } + $input.val( $currentVal + $currentResult.text() + options.multipleSep); + $input.focus(); + } else { + $input.val($currentResult.text()); + } $results.hide(); if (options.onSelect) @@ -291,6 +309,8 @@ return; options = options || {}; + options.multiple = options.multiple || false; + options.multipleSep = options.multipleSep || ", "; options.source = source; options.delay = options.delay || 100; options.resultsClass = options.resultsClass || 'ac_results'; diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 9b737cb362..848f2921db 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -70,7 +70,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02'); $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561'); $scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' ); - $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('jquery'), '1.1'); + $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('jquery'), '1.1b'); $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20'); $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430'); $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.1.0'); @@ -138,7 +138,7 @@ function wp_default_scripts( &$scripts ) { 'save' => __('Save'), 'cancel' => __('Cancel'), ) ); - $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080623' ); + $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080629' ); $scripts->localize( 'post', 'postL10n', array( 'tagsUsed' => __('Tags used on this post:'), 'add' => attribute_escape(__('Add')),