Add "Choose from popular tags" to the tags postbox

git-svn-id: https://develop.svn.wordpress.org/trunk@9518 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2008-11-04 23:15:59 +00:00
parent c6bed34239
commit 2dde47a9f2
8 changed files with 114 additions and 37 deletions

View File

@ -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 ) )

View File

@ -889,7 +889,8 @@ abbr.required,
}
#timestampdiv input,
#namediv input {
#namediv input,
#tagsdiv #the-tagcloud {
border-color: #ddd;
}

View File

@ -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;
}

View File

@ -235,7 +235,7 @@ function post_tags_meta_box($post) {
?>
<p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p>
<div id="tagchecklist"></div>
<p><a href='#'><?php _e( 'Choose from tags' ); ?></a></p>
<p id="tagcloud-link" class="hide-if-no-js"><a href='#'><?php _e( 'Choose from the most popular tags' ); ?></a></p>
<?php
}
add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'side', 'core');

View File

@ -242,7 +242,7 @@ if ( $page_links )
if ( $can_manage )
wp_tag_cloud(array('link' => 'edit'));
else
wp_tag_cloud();
wp_tag_cloud();
?>
</div>

View File

@ -37,14 +37,25 @@ function tag_update_quickclicks() {
jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
}
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 = '<p id="the-tagcloud">'+r+'</p>';
$('#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');

View File

@ -2920,4 +2920,17 @@ ul.core-updates li {
}
form.upgrade {
margin-top: 8px;
}
}
#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;
}

View File

@ -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[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( sprintf( __ngettext( $single_text, $multiple_text, $count ), $count ) ) . "'$rel style='font-size: " .