Auto add preview link after autosaving a new post or page. Props filosofo. see #5847
git-svn-id: http://svn.automattic.com/wordpress/trunk@6953 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
833447d59e
commit
eb3cb51113
|
@ -524,6 +524,11 @@ case 'closed-postboxes' :
|
|||
$current_user = wp_get_current_user();
|
||||
update_usermeta($current_user->ID, 'closedpostboxes_'.$page, $closed);
|
||||
break;
|
||||
case 'get-permalink':
|
||||
check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
|
||||
$post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
|
||||
die(get_permalink($post_id));
|
||||
break;
|
||||
case 'sample-permalink':
|
||||
check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
|
||||
$post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
|
||||
|
|
|
@ -92,6 +92,7 @@ addLoadEvent(focusit);
|
|||
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
|
||||
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
|
||||
<?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>
|
||||
<?php wp_nonce_field( 'getpermalink', 'getpermalinknonce', false ); ?>
|
||||
</div>
|
||||
|
||||
<?php echo $form_pingback ?>
|
||||
|
|
|
@ -59,6 +59,7 @@ addLoadEvent(focusit);
|
|||
<?php the_editor($post->post_content); ?>
|
||||
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
|
||||
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
|
||||
<?php wp_nonce_field( 'getpermalink', 'getpermalinknonce', false ); ?>
|
||||
</div>
|
||||
|
||||
<div class="submitbox" id="submitpage">
|
||||
|
|
|
@ -46,9 +46,26 @@ function autosave_update_post_ID(response) {
|
|||
message = autosaveL10n.failText;
|
||||
}
|
||||
jQuery('#autosave').html(message);
|
||||
autosave_update_preview_link(res);
|
||||
autosave_enable_buttons();
|
||||
}
|
||||
|
||||
function autosave_update_preview_link(post_id) {
|
||||
// Add preview button if not already there
|
||||
if ( ! jQuery('#previewview > *').get()[0] ) {
|
||||
var post_type = jQuery('#post_type').val();
|
||||
var previewText = 'page' == post_type ? autosaveL10n.previewPageText : autosaveL10n.previewPostText;
|
||||
jQuery.post(autosaveL10n.requestFile, {
|
||||
action: "get-permalink",
|
||||
post_id: post_id,
|
||||
getpermalinknonce: jQuery('#getpermalinknonce').val()
|
||||
}, function(permalink) {
|
||||
jQuery('#previewview').html('<a target="_blank" href="'+permalink+'">'+previewText+'</a>');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function autosave_loading() {
|
||||
jQuery('#autosave').html(autosaveL10n.savingText);
|
||||
}
|
||||
|
@ -63,6 +80,7 @@ function autosave_saved(response) {
|
|||
message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
|
||||
}
|
||||
jQuery('#autosave').html(message);
|
||||
autosave_update_preview_link(res);
|
||||
autosave_enable_buttons();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,13 @@ class WP_Scripts {
|
|||
|
||||
$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
|
||||
|
||||
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('jquery', 'schedule'), '20080206');
|
||||
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('jquery', 'schedule'), '20080220');
|
||||
$this->localize( 'autosave', 'autosaveL10n', array(
|
||||
'autosaveInterval' => apply_filters('autosave_interval', '120'),
|
||||
'errorText' => __('Error: %response%'),
|
||||
'failText' => __('Error: Autosave Failed.'),
|
||||
'previewPageText' => __('Preview this Page'),
|
||||
'previewPostText' => __('Preview this Post'),
|
||||
'saveText' => __('Saved at %time%.'),
|
||||
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
|
||||
'savingText' => __('Saving Draft...')
|
||||
|
|
Loading…
Reference in New Issue