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
This commit is contained in:
parent
cab4a6a625
commit
93aa40cbff
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
22
wp-includes/js/jquery/suggest.js
vendored
22
wp-includes/js/jquery/suggest.js
vendored
@ -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) {
|
||||
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';
|
||||
|
@ -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')),
|
||||
|
Loading…
Reference in New Issue
Block a user