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();
|
$current_user = wp_get_current_user();
|
||||||
update_usermeta($current_user->ID, 'closedpostboxes_'.$page, $closed);
|
update_usermeta($current_user->ID, 'closedpostboxes_'.$page, $closed);
|
||||||
break;
|
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':
|
case 'sample-permalink':
|
||||||
check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
|
check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
|
||||||
$post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
|
$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( 'autosave', 'autosavenonce', false ); ?>
|
||||||
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
|
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
|
||||||
<?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>
|
<?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>
|
||||||
|
<?php wp_nonce_field( 'getpermalink', 'getpermalinknonce', false ); ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php echo $form_pingback ?>
|
<?php echo $form_pingback ?>
|
||||||
|
|
|
@ -59,6 +59,7 @@ addLoadEvent(focusit);
|
||||||
<?php the_editor($post->post_content); ?>
|
<?php the_editor($post->post_content); ?>
|
||||||
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
|
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
|
||||||
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
|
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
|
||||||
|
<?php wp_nonce_field( 'getpermalink', 'getpermalinknonce', false ); ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="submitbox" id="submitpage">
|
<div class="submitbox" id="submitpage">
|
||||||
|
|
|
@ -46,9 +46,26 @@ function autosave_update_post_ID(response) {
|
||||||
message = autosaveL10n.failText;
|
message = autosaveL10n.failText;
|
||||||
}
|
}
|
||||||
jQuery('#autosave').html(message);
|
jQuery('#autosave').html(message);
|
||||||
|
autosave_update_preview_link(res);
|
||||||
autosave_enable_buttons();
|
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() {
|
function autosave_loading() {
|
||||||
jQuery('#autosave').html(autosaveL10n.savingText);
|
jQuery('#autosave').html(autosaveL10n.savingText);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +80,7 @@ function autosave_saved(response) {
|
||||||
message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
|
message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
|
||||||
}
|
}
|
||||||
jQuery('#autosave').html(message);
|
jQuery('#autosave').html(message);
|
||||||
|
autosave_update_preview_link(res);
|
||||||
autosave_enable_buttons();
|
autosave_enable_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,13 @@ class WP_Scripts {
|
||||||
|
|
||||||
$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
|
$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(
|
$this->localize( 'autosave', 'autosaveL10n', array(
|
||||||
'autosaveInterval' => apply_filters('autosave_interval', '120'),
|
'autosaveInterval' => apply_filters('autosave_interval', '120'),
|
||||||
'errorText' => __('Error: %response%'),
|
'errorText' => __('Error: %response%'),
|
||||||
'failText' => __('Error: Autosave Failed.'),
|
'failText' => __('Error: Autosave Failed.'),
|
||||||
|
'previewPageText' => __('Preview this Page'),
|
||||||
|
'previewPostText' => __('Preview this Post'),
|
||||||
'saveText' => __('Saved at %time%.'),
|
'saveText' => __('Saved at %time%.'),
|
||||||
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
|
'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
|
||||||
'savingText' => __('Saving Draft...')
|
'savingText' => __('Saving Draft...')
|
||||||
|
@ -484,4 +486,4 @@ function wp_prototype_before_jquery( $js_array ) {
|
||||||
|
|
||||||
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
|
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue