Ensure autosave is run before showing preview for new posts/pages.

git-svn-id: http://svn.automattic.com/wordpress/trunk@11466 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz
2009-05-27 11:04:00 +00:00
parent a4a448741e
commit 6b559e2124
7 changed files with 56 additions and 78 deletions

View File

@@ -1,6 +1,8 @@
var autosave, autosaveLast = '', autosavePeriodical, autosaveOldMessage = '', autosaveDelayPreview = false, autosaveFirst = true;
var autosave, autosaveLast = '', autosavePeriodical, autosaveOldMessage = '', autosaveDelayPreview = false, notSaved = true;
jQuery(function($) {
jQuery(document).ready( function($) {
var dotabkey = true;
autosaveLast = $('#post #title').val() + $('#post #content').val();
autosavePeriodical = $.schedule({time: autosaveL10n.autosaveInterval * 1000, func: function() { autosave(); }, repeat: true, protect: true});
@@ -21,6 +23,38 @@ jQuery(function($) {
return autosaveL10n.saveAlert;
}
};
// preview
$('#post-preview').click(function(){
if ( 1 > $('#post_ID').val() && notSaved ) {
autosaveDelayPreview = true;
autosave();
return false;
}
doPreview();
return false;
});
doPreview = function() {
$('input#wp-preview').val('dopreview');
$('form#post').attr('target', 'wp-preview').submit().attr('target', '');
$('input#wp-preview').val('');
}
// This code is meant to allow tabbing from Title to Post if tinyMCE is defined.
if ( typeof tinyMCE != 'undefined' ) {
$('#title')[$.browser.opera ? 'keypress' : 'keydown'](function (e) {
if ( e.which == 9 && !e.shiftKey && !e.controlKey && !e.altKey ) {
if ( ($("#post_ID").val() < 1) && ($("#title").val().length > 0) ) { autosave(); }
if ( tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden() && dotabkey ) {
e.preventDefault();
dotabkey = false;
tinyMCE.activeEditor.focus();
return false;
}
}
});
}
});
function autosave_parse_response(response) {
@@ -68,14 +102,16 @@ function autosave_saved_new(response) {
tempID = jQuery('#post_ID').val();
postID = parseInt( res.responses[0].id, 10 );
autosave_update_post_ID( postID ); // disabled form buttons are re-enabled here
if ( tempID < 0 && postID > 0 ) // update media buttons
if ( tempID < 0 && postID > 0 ) { // update media buttons
notSaved = false;
jQuery('#media-buttons a').each(function(){
this.href = this.href.replace(tempID, postID);
});
// activate preview
autosaveFirst = false;
if ( autosaveDelayPreview )
jQuery('#post-preview').click();
}
if ( autosaveDelayPreview ) {
autosaveDelayPreview = false;
doPreview();
}
} else {
autosave_enable_buttons(); // re-enable disabled form buttons
}
@@ -172,8 +208,8 @@ autosave = function() {
post_data["post_name"] = jQuery('#post_name').val();
// Nothing to save or no change.
if( (post_data["post_title"].length==0 && post_data["content"].length==0) || post_data["post_title"] + post_data["content"] == autosaveLast) {
doAutoSave = false
if( ( post_data["post_title"].length == 0 && post_data["content"].length == 0 ) || post_data["post_title"] + post_data["content"] == autosaveLast) {
doAutoSave = false;
}
autosave_disable_buttons();

File diff suppressed because one or more lines are too long

View File

@@ -98,7 +98,7 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};'
) );
$scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20090523' );
$scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20090526' );
$scripts->add_data( 'autosave', 'group', 1 );
$scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array('wp-ajax-response'), '20090504' );
@@ -264,7 +264,7 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(slugL10n);}catch(e){};'
) );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'slug'), '20090506' );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'slug'), '20090526' );
$scripts->add_data( 'post', 'group', 1 );
$scripts->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
@@ -292,7 +292,7 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(postL10n);}catch(e){};'
) );
$scripts->add( 'page', "/wp-admin/js/page$suffix.js", array('jquery', 'slug', 'wp-lists', 'postbox'), '20090102' );
$scripts->add( 'page', "/wp-admin/js/page$suffix.js", array('jquery', 'slug', 'wp-lists', 'postbox'), '20090526' );
$scripts->add_data( 'page', 'group', 1 );
$scripts->localize( 'page', 'postL10n', array(
'cancel' => __('Cancel'),