Postbox save updates and admin js refactoring from nbachiyski. fixes #5799

git-svn-id: http://svn.automattic.com/wordpress/trunk@6761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-02-08 19:57:50 +00:00
parent 9989d4c23e
commit bc817d2a2e
13 changed files with 108 additions and 88 deletions

View File

@ -513,11 +513,16 @@ case 'autosave-generate-nonces' :
die('0');
break;
case 'closed-postboxes' :
check_ajax_referer( $action );
check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
$closed = isset( $_POST['closed'] )? $_POST['closed'] : '';
$closed = explode( ',', $_POST['closed'] );
$page = isset( $_POST['page'] )? $_POST['page'] : '';
if ( !preg_match( '/^[a-z-]+$/', $page ) ) {
die(-1);
}
if (!is_array($closed)) break;
$current_user = wp_get_current_user();
update_usermeta($current_user->ID, 'closedpostboxes', $closed);
update_usermeta($current_user->ID, 'closedpostboxes_'.$page, $closed);
break;
case 'sample-permalink':
check_ajax_referer( $action );

View File

@ -89,6 +89,7 @@ addLoadEvent(focusit);
<h3><?php _e('Post') ?></h3>
<?php the_editor($post->post_content); ?>
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
</div>
<?php echo $form_pingback ?>
@ -175,7 +176,7 @@ else
echo clean_url(stripslashes(wp_get_referer()));
?>" /></p>
<div id="tagsdiv" class="postbox <?php echo postbox_classes('tagsdiv'); ?>">
<div id="tagsdiv" class="postbox <?php echo postbox_classes('tagsdiv', 'post'); ?>">
<h3><?php _e('Tags'); ?></h3>
<div class="inside">
<p id="jaxtag"><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>
@ -183,7 +184,7 @@ else
</div>
</div>
<div id="categorydiv" class="postbox <?php echo postbox_classes('categorydiv'); ?>">
<div id="categorydiv" class="postbox <?php echo postbox_classes('categorydiv', 'post'); ?>">
<h3><?php _e('Categories') ?></h3>
<div class="inside">
@ -234,12 +235,12 @@ if (current_user_can('upload_files') && false) {
<h2><?php _e('Advanced Options'); ?></h2>
<div id="postexcerpt" class="postbox <?php echo postbox_classes('postexcerpt'); ?>">
<div id="postexcerpt" class="postbox <?php echo postbox_classes('postexcerpt', 'post'); ?>">
<h3><?php _e('Optional Excerpt') ?></h3>
<div class="inside"><textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt ?></textarea></div>
</div>
<div id="trackbacksdiv" class="postbox <?php echo postbox_classes('trackbacksdiv'); ?>">
<div id="trackbacksdiv" class="postbox <?php echo postbox_classes('trackbacksdiv', 'post'); ?>">
<h3><?php _e('Trackbacks') ?></h3>
<div class="inside">
<?php _e('Send trackbacks to:'); ?> <?php echo $form_trackback; ?> (<?php _e('Separate multiple URLs with spaces'); ?>)
@ -250,7 +251,7 @@ if ( ! empty($pings) )
</div>
</div>
<div id="postcustom" class="postbox <?php echo postbox_classes('postcustom'); ?>">
<div id="postcustom" class="postbox <?php echo postbox_classes('postcustom', 'post'); ?>">
<h3><?php _e('Custom Fields') ?></h3>
<div class="inside">
<div id="postcustomstuff">
@ -271,7 +272,7 @@ list_meta($metadata);
<?php do_action('dbx_post_advanced'); ?>
<div id="commentstatusdiv" class="postbox <?php echo postbox_classes('commentstatusdiv'); ?>">
<div id="commentstatusdiv" class="postbox <?php echo postbox_classes('commentstatusdiv', 'post'); ?>">
<h3><?php _e('Discussion') ?></h3>
<div class="inside">
<input name="advanced_view" type="hidden" value="1" />
@ -282,14 +283,14 @@ list_meta($metadata);
</div>
</div>
<div id="passworddiv" class="postbox <?php echo postbox_classes('passworddiv'); ?>">
<div id="passworddiv" class="postbox <?php echo postbox_classes('passworddiv', 'post'); ?>">
<h3><?php _e('Post Password') ?></h3>
<div class="inside">
<input name="post_password" type="text" size="13" id="post_password" value="<?php echo attribute_escape( $post->post_password ); ?>" />
</div>
</div>
<div id="slugdiv" class="postbox <?php echo postbox_classes('slugdiv'); ?>">
<div id="slugdiv" class="postbox <?php echo postbox_classes('slugdiv', 'post'); ?>">
<h3><?php _e('Post Slug') ?></h3>
<div class="inside">
<input name="post_name" type="text" size="13" id="post_name" value="<?php echo attribute_escape( $post->post_name ); ?>" />
@ -297,7 +298,7 @@ list_meta($metadata);
</div>
<?php if ( current_user_can('edit_posts') ) : ?>
<div id="posttimestampdiv" class="postbox <?php echo postbox_classes('posttimestampdiv'); ?>">
<div id="posttimestampdiv" class="postbox <?php echo postbox_classes('posttimestampdiv', 'post'); ?>">
<h3><?php _e('Post Timestamp'); ?></h3>
<div class="inside"><?php touch_time(($action == 'edit')); ?></div>
</div>
@ -309,7 +310,7 @@ if ( $post->post_author && !in_array($post->post_author, $authors) )
$authors[] = $post->post_author;
if ( $authors && count( $authors ) > 1 ) :
?>
<div id="authordiv" class="postbox <?php echo postbox_classes('authordiv'); ?>">
<div id="authordiv" class="postbox <?php echo postbox_classes('authordiv', 'post'); ?>">
<h3><?php _e('Post Author'); ?></h3>
<div class="inside">
<?php wp_dropdown_users( array('include' => $authors, 'name' => 'post_author_override', 'selected' => empty($post_ID) ? $user_ID : $post->post_author) ); ?>

View File

@ -32,6 +32,7 @@ function xfn_check($class, $value = '', $deprecated = '') {
<?php echo $form ?>
<?php wp_nonce_field($nonce_action); ?>
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
<div class="wrap">
@ -64,7 +65,7 @@ function xfn_check($class, $value = '', $deprecated = '') {
</p>
</div>
<div id="linkcategorydiv" class="postbox <?php echo postbox_classes('linkcategorydiv'); ?>">
<div id="linkcategorydiv" class="postbox <?php echo postbox_classes('linkcategorydiv', 'link'); ?>">
<h3><?php _e('Categories') ?></h3>
<div class="inside">
@ -100,7 +101,7 @@ function xfn_check($class, $value = '', $deprecated = '') {
<h2><?php _e('Advanced Options'); ?></h2>
<div id="linktargetdiv" class="postbox <?php echo postbox_classes('linktargetdiv'); ?>">
<div id="linktargetdiv" class="postbox <?php echo postbox_classes('linktargetdiv', 'link'); ?>">
<h3><?php _e('Target') ?></h3>
<div class="inside">
<label for="link_target_blank" class="selectit">
@ -115,7 +116,7 @@ function xfn_check($class, $value = '', $deprecated = '') {
</div>
</div>
<div id="linkvisiblediv" class="postbox <?php echo postbox_classes('linkvisiblediv'); ?>">
<div id="linkvisiblediv" class="postbox <?php echo postbox_classes('linkvisiblediv', 'link'); ?>">
<h3><?php _e('Visible') ?></h3>
<div class="inside">
<label for="link_visible_yes" class="selectit">
@ -127,7 +128,7 @@ function xfn_check($class, $value = '', $deprecated = '') {
</div>
</div>
<div id="linkxfndiv" class="postbox <?php echo postbox_classes('linkxfndiv'); ?>">
<div id="linkxfndiv" class="postbox <?php echo postbox_classes('linkxfndiv', 'link'); ?>">
<h3><?php _e('Link Relationship (XFN)') ?></h3>
<div class="inside">
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
@ -240,7 +241,7 @@ function xfn_check($class, $value = '', $deprecated = '') {
</div>
</div>
<div id="linkadvanceddiv" class="postbox <?php echo postbox_classes('linkadvanceddiv'); ?>">
<div id="linkadvanceddiv" class="postbox <?php echo postbox_classes('linkadvanceddiv', 'link'); ?>">
<h3><?php _e('Advanced') ?></h3>
<div class="inside">
<table class="editform" width="100%" cellspacing="2" cellpadding="5">

View File

@ -57,6 +57,7 @@ addLoadEvent(focusit);
<h3><?php _e('Page') ?></h3>
<?php the_editor($post->post_content); ?>
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
</div>
<div id="submitpost">
@ -136,7 +137,7 @@ if ( ('edit' == $action) && current_user_can('delete_page', $post_ID) )
<h2><?php _e('Advanced Options'); ?></h2>
<div id="pagepostcustom" class="postbox <?php echo postbox_classes('pagepostcustom'); ?>">
<div id="pagepostcustom" class="postbox <?php echo postbox_classes('pagepostcustom', 'page'); ?>">
<h3><?php _e('Custom Fields') ?></h3>
<div class="inside">
<div id="postcustomstuff">
@ -155,7 +156,7 @@ list_meta($metadata);
</div>
</div>
<div id="pagecommentstatusdiv" class="postbox <?php echo postbox_classes('pagecommentstatusdiv'); ?>">
<div id="pagecommentstatusdiv" class="postbox <?php echo postbox_classes('pagecommentstatusdiv', 'page'); ?>">
<h3><?php _e('Discussion') ?></h3>
<div class="inside">
<input name="advanced_view" type="hidden" value="1" />
@ -166,21 +167,21 @@ list_meta($metadata);
</div>
</div>
<div id="pagepassworddiv" class="postbox <?php echo postbox_classes('pagepassworddiv'); ?>">
<div id="pagepassworddiv" class="postbox <?php echo postbox_classes('pagepassworddiv', 'page'); ?>">
<h3><?php _e('Page Password') ?></h3>
<div class="inside">
<input name="post_password" type="text" size="13" id="post_password" value="<?php echo attribute_escape( $post->post_password ); ?>" />
</div>
</div>
<div id="pageslugdiv" class="postbox <?php echo postbox_classes('pageslugdiv'); ?>">
<div id="pageslugdiv" class="postbox <?php echo postbox_classes('pageslugdiv', 'page'); ?>">
<h3><?php _e('Page Slug') ?></h3>
<div class="inside">
<input name="post_name" type="text" size="13" id="post_name" value="<?php echo attribute_escape( $post->post_name ); ?>" />
</div>
</div>
<div id="pageparentdiv" class="postbox <?php echo postbox_classes('pageparentdiv'); ?>">
<div id="pageparentdiv" class="postbox <?php echo postbox_classes('pageparentdiv', 'page'); ?>">
<h3><?php _e('Page Parent') ?></h3>
<div class="inside">
<select name="parent_id">
@ -191,7 +192,7 @@ list_meta($metadata);
</div>
<?php if ( 0 != count( get_page_templates() ) ) { ?>
<div id="pagetemplatediv" class="postbox <?php echo postbox_classes('pagetemplatediv'); ?>">
<div id="pagetemplatediv" class="postbox <?php echo postbox_classes('pagetemplatediv', 'page'); ?>">
<h3><?php _e('Page Template') ?></h3>
<div class="inside">
<select name="page_template">
@ -202,7 +203,7 @@ list_meta($metadata);
</div>
<?php } ?>
<div id="pageorderdiv" class="postbox <?php echo postbox_classes('pageorderdiv'); ?>">
<div id="pageorderdiv" class="postbox <?php echo postbox_classes('pageorderdiv', 'page'); ?>">
<h3><?php _e('Page Order') ?></h3>
<div class="inside">
<input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo $post->menu_order ?>" />
@ -215,7 +216,7 @@ if ( $post->post_author && !in_array($post->post_author, $authors) )
$authors[] = $post->post_author;
if ( $authors && count( $authors ) > 1 ) :
?>
<div id="pageauthordiv" class="postbox <?php echo postbox_classes('pageauthordiv'); ?>">
<div id="pageauthordiv" class="postbox <?php echo postbox_classes('pageauthordiv', 'page'); ?>">
<h3><?php _e('Post Author'); ?></h3>
<div class="inside">
<?php wp_dropdown_users( array('include' => $authors, 'name' => 'post_author_override', 'selected' => empty($post_ID) ? $user_ID : $post->post_author) ); ?>

View File

@ -517,9 +517,9 @@ function wp_edit_posts_query( $q = false ) {
return array($post_stati, $avail_post_stati);
}
function postbox_classes( $id ) {
function postbox_classes( $id, $page ) {
$current_user = wp_get_current_user();
if ( $closed = get_usermeta( $current_user->ID, 'closedpostboxes' ) ) {
if ( $closed = get_usermeta( $current_user->ID, 'closedpostboxes_'.$page ) ) {
if ( !is_array( $closed ) ) return '';
return in_array( $id, $closed )? 'closed' : '';
} else {

View File

@ -1,6 +1,6 @@
addLoadEvent( function() {
// postboxes
add_postbox_toggles();
add_postbox_toggles('link');
// category tabs
var categoryTabs = jQuery('#category-tabs').tabs();

6
wp-admin/js/page.js Normal file
View File

@ -0,0 +1,6 @@
addLoadEvent( function() {
add_postbox_toggles('page');
make_slugedit_clickable();
});

View File

@ -52,55 +52,9 @@ function tag_press_key( e ) {
}
}
function edit_permalink(post_id) {
var i, c = 0;
var e = jQuery('#editable-post-name');
var revert_e = e.html();
var real_slug = jQuery('#post_name');
var b = jQuery('#edit-slug-buttons');
var revert_b = b.html();
var old_slug = e.children('span').html();
b.html('<a href="" class="save">'+postL10n.save+'</a> <a class="cancel" href="">'+postL10n.cancel+'</a>');
b.children('.save').click(function() {
var new_slug = e.children('input').attr('value');
jQuery.post(postL10n.requestFile, {
action: 'sample-permalink',
post_id: post_id,
new_slug: new_slug,
cookie: document.cookie}, function(data) {
jQuery('#sample-permalink').html(data);
b.html(revert_b);
real_slug.attr('value', new_slug);
make_slugedit_clickable();
});
return false;
});
jQuery('#edit-slug-buttons .cancel').click(function() {
e.html(revert_e);
b.html(revert_b);
real_slug.attr('value', revert_e);
return false;
});
for(i=0; i < revert_e.length; ++i) {
if ('%' == revert_e.charAt(i)) c++;
}
slug_value = (c > revert_e.length/4)? '' : revert_e;
e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
// on enter, just save the new slug, don't save the post
if (13 == key) {b.children('.save').click();return false;}
if (27 == key) {b.children('.cancel').click();return false;}
real_slug.attr('value', this.value)}).focus();
}
function make_slugedit_clickable() {
jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()});
}
addLoadEvent( function() {
// postboxes
add_postbox_toggles();
add_postbox_toggles('post');
// If no tags on the page, skip the tag and category stuff.
if ( !jQuery('#tags-input').size() ) {

View File

@ -1,12 +1,14 @@
function add_postbox_toggles() {
function add_postbox_toggles(page) {
jQuery('.postbox h3').prepend('<a class="togbox">+</a> ');
jQuery('.togbox').click( function() { jQuery(jQuery(this).parent().parent().get(0)).toggleClass('closed'); save_postboxes_state(); } );
jQuery('.togbox').click( function() { jQuery(jQuery(this).parent().parent().get(0)).toggleClass('closed'); save_postboxes_state(page); } );
}
function save_postboxes_state() {
function save_postboxes_state(page) {
var closed = jQuery('.postbox').filter('.closed').map(function() { return this.id; }).get().join(',');
jQuery.post(postboxL10n.requestFile, {
action: 'closed-postboxes',
closed: closed,
cookie: document.cookie});
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
page: page
});
}

46
wp-admin/js/slug.js Normal file
View File

@ -0,0 +1,46 @@
function edit_permalink(post_id) {
var i, c = 0;
var e = jQuery('#editable-post-name');
var revert_e = e.html();
var real_slug = jQuery('#post_name');
var b = jQuery('#edit-slug-buttons');
var revert_b = b.html();
var old_slug = e.children('span').html();
b.html('<a href="" class="save">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>');
b.children('.save').click(function() {
var new_slug = e.children('input').attr('value');
jQuery.post(slugL10n.requestFile, {
action: 'sample-permalink',
post_id: post_id,
new_slug: new_slug,
cookie: document.cookie}, function(data) {
jQuery('#sample-permalink').html(data);
b.html(revert_b);
real_slug.attr('value', new_slug);
make_slugedit_clickable();
});
return false;
});
jQuery('#edit-slug-buttons .cancel').click(function() {
e.html(revert_e);
b.html(revert_b);
real_slug.attr('value', revert_e);
return false;
});
for(i=0; i < revert_e.length; ++i) {
if ('%' == revert_e.charAt(i)) c++;
}
slug_value = (c > revert_e.length/4)? '' : revert_e;
e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
// on enter, just save the new slug, don't save the post
if (13 == key) {b.children('.save').click();return false;}
if (27 == key) {b.children('.cancel').click();return false;}
real_slug.attr('value', this.value)}).focus();
}
function make_slugedit_clickable() {
jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()});
}

View File

@ -4,7 +4,7 @@ $title = __('New Page');
$parent_file = 'post-new.php';
$editing = true;
wp_enqueue_script('autosave');
wp_enqueue_script('post');
wp_enqueue_script('page');
wp_enqueue_script('thickbox');
wp_enqueue_script('media-upload');

View File

@ -52,7 +52,7 @@ case 'edit':
exit();
}
wp_enqueue_script('post');
wp_enqueue_script('page');
wp_enqueue_script('thickbox');
wp_enqueue_script('media-upload');

View File

@ -135,16 +135,20 @@ class WP_Scripts {
$this->localize( 'postbox', 'postboxL10n', array(
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
) );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox'), '20080128' );
$this->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' );
$this->localize( 'slug', 'slugL10n', array(
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
'save' => __('Save'),
'cancel' => __('Cancel'),
) );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080128' );
$this->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
'add' => attribute_escape(__('Add')),
'addTag' => attribute_escape(__('Add new tag')),
'separate' => __('Separate tags with commas'),
'save' => __('Save'),
'cancel' => __('Cancel'),
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
) );
$this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080208' );
$this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' );
$this->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080109' );
$this->localize( 'upload', 'uploadL10n', array(