From 2dde47a9f279d5d98d7c21b98c81677f0c92016e Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 4 Nov 2008 23:15:59 +0000 Subject: [PATCH] Add "Choose from popular tags" to the tags postbox git-svn-id: https://develop.svn.wordpress.org/trunk@9518 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-ajax.php | 23 ++++++++++++ wp-admin/css/colors-fresh.css | 3 +- wp-admin/css/global.css | 59 +++++++++++++++++-------------- wp-admin/edit-form-advanced.php | 2 +- wp-admin/edit-tags.php | 2 +- wp-admin/js/post.js | 45 ++++++++++++++++++++--- wp-admin/wp-admin.css | 15 +++++++- wp-includes/category-template.php | 2 +- 8 files changed, 114 insertions(+), 37 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 6c7d907222..ca3b56342c 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -422,6 +422,29 @@ case 'add-tag' : // From Manage->Tags ) ); $x->send(); break; +case 'get-tagcloud' : + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + + $tags = get_tags( array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) ); + + if ( empty( $tags ) ) + die('0'); + + foreach ( $tags as $key => $tag ) { + $tags[ $key ]->link = '#'; + $tags[ $key ]->id = $tag->term_id; + } + + $return = wp_generate_tag_cloud( $tags ); + + if ( empty($return) ) + die('0'); + + echo $return; + + exit; + break; case 'add-comment' : check_ajax_referer( $action ); if ( !current_user_can( 'edit_post', $id ) ) diff --git a/wp-admin/css/colors-fresh.css b/wp-admin/css/colors-fresh.css index 3f266e0fa0..48e1106874 100644 --- a/wp-admin/css/colors-fresh.css +++ b/wp-admin/css/colors-fresh.css @@ -889,7 +889,8 @@ abbr.required, } #timestampdiv input, -#namediv input { +#namediv input, +#tagsdiv #the-tagcloud { border-color: #ddd; } diff --git a/wp-admin/css/global.css b/wp-admin/css/global.css index 147239f94d..bac227090f 100644 --- a/wp-admin/css/global.css +++ b/wp-admin/css/global.css @@ -145,38 +145,40 @@ input[type="radio"] { /* styles for use by people extending the WordPress interface */ -body { - margin: 0; - padding: 0; +body, +td { + font: 13px/19px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana, sans-serif; } -body, td { - font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana, sans-serif; +p { + margin: 1em 0; } -form, label input { - margin: 0; - padding: 0; -} - -img { - border: 0; +blockquote { + margin: 1em; } label { cursor: pointer; } -li, dd { +li, +dd { margin-bottom: 6px; } -p, li, dl, dd, dt { +p, +li, +dl, +dd, +dt { line-height: 140%; } -textarea, input, select { - font: 13px Verdana, Arial, Helvetica, sans-serif; +textarea, +input, +select { + font: 13px/19px Verdana, Arial, Helvetica, sans-serif; margin: 1px; padding: 3px; } @@ -291,7 +293,8 @@ h6 { white-space: nowrap; } -.widefat td, .widefat th { +.widefat td, +.widefat th { border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ccc; @@ -326,11 +329,7 @@ h6 { .widefat tbody th.check-column { padding: 10px 0 22px; } -/* -th.check-column + th, th.check-column + td { - padding-left: 5px; -} -*/ + .widefat .num, .widefat .column-comments { text-align: center; @@ -340,27 +339,33 @@ th.check-column + th, th.check-column + td { vertical-align: middle; } -.wrap, .updated, .error { +.wrap, +.updated, +.error { margin: 0 15px; padding: 0; } -.updated, .error { +.updated, +.error { border-width: 1px; border-style: solid; padding: 0 0.6em; margin: 3px 15px 5px; } -.updated p, .error p { +.updated p, +.error p { margin: 0.6em 0; } -.wrap .updated, .wrap .error { +.wrap .updated, +.wrap .error { margin: auto 0 0; } -.updated a, .error a { +.updated a, +.error a { text-decoration: underline; } diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 4b5adcb6e1..f7685b0196 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -235,7 +235,7 @@ function post_tags_meta_box($post) { ?>

-

+ 'edit')); else - wp_tag_cloud(); + wp_tag_cloud(); ?> diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index b13dbf3844..dc8443c86e 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -37,14 +37,25 @@ function tag_update_quickclicks() { jQuery( '#tagchecklist' ).prepend( ''+postL10n.tagsUsed+'
' ); } -function tag_flush_to_text() { - var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val(); +function tag_flush_to_text(e,a) { + a = a || false; + var text = a ? jQuery(a).text() : jQuery('#newtag').val(); + var newtags = jQuery('#tags-input').val(); + var t = text.replace( /\s*([^,]+)[\s,]*/, '$1' ); + + if ( newtags.indexOf(t) != -1 ) + return false; + + newtags += ',' + text; + // massage newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' ); jQuery('#tags-input').val( newtags ); tag_update_quickclicks(); - jQuery('#newtag').val(''); - jQuery('#newtag').focus(); + if ( ! a ) { + jQuery('#newtag').val(''); + jQuery('#newtag').focus(); + } return false; } @@ -58,9 +69,33 @@ function tag_press_key( e ) { tag_flush_to_text(); return false; } -} +}; + +(function($){ + tagCloud = { + init : function() { + $('#tagcloud-link').click(function(){tagCloud.get(); return false;}); + }, + + get : function() { + $.post('admin-ajax.php', {'action':'get-tagcloud'}, function(r, stat) { + if ( 0 == r || 'success' != stat ) + r = wpAjax.broken; + + r = '

'+r+'

'; + $('#tagcloud-link').after($(r)); + $('#the-tagcloud a').click(function(){ + tag_flush_to_text(0,this); + return false; + }); + }); + } + } +})(jQuery); jQuery(document).ready( function($) { + tagCloud.init(); + // close postboxes that should be closed jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed'); diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index 4470b0d97e..4c7098d466 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -2920,4 +2920,17 @@ ul.core-updates li { } form.upgrade { margin-top: 8px; -} \ No newline at end of file +} + +#tagsdiv #the-tagcloud { + margin: 5px 5px 10px; + padding: 8px; + border-width: 1px; + border-style: solid; + line-height: 1.8em; + word-spacing: 3px; + -moz-border-radius: 6px; + -khtml-border-radius: 6px; + -webkit-border-radius: 6px; + border-radius: 6px; +} diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index 1346f43fe8..cae7b6330d 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -664,7 +664,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { foreach ( $tags as $key => $tag ) { $count = $counts[ $key ]; - $tag_link = clean_url( $tag->link ); + $tag_link = '#' != $tag->link ? clean_url( $tag->link ) : '#'; $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; $tag_name = $tags[ $key ]->name; $a[] = "