Fix race condition with autosave when clicking Publish immediately after entering post title, fixes #6728

git-svn-id: http://svn.automattic.com/wordpress/trunk@11879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz
2009-08-26 04:11:16 +00:00
parent e8b550fd33
commit 83161b0695
7 changed files with 26 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
var autosave, autosaveLast = '', autosavePeriodical, autosaveOldMessage = '', autosaveDelayPreview = false, notSaved = true;
var autosave, autosaveLast = '', autosavePeriodical, autosaveOldMessage = '', autosaveDelayPreview = false, notSaved = true, blockSave = false;
jQuery(document).ready( function($) {
var dotabkey = true;
@@ -12,6 +12,7 @@ jQuery(document).ready( function($) {
});
$('input[type="submit"], a.submitdelete', '#submitpost').click(function(){
blockSave = true;
window.onbeforeunload = null;
$(':button, :submit', '#submitpost').each(function(){
var t = $(this);
@@ -67,6 +68,16 @@ jQuery(document).ready( function($) {
}
});
}
// autosave new posts after a title is typed but not if Publish or Save Draft is clicked
if ( 0 > $('#post_ID').val() ) {
$('#title').blur( function() {
if ( !this.value || 0 < $('#post_ID').val() )
return;
delayed_autosave();
});
}
});
function autosave_parse_response(response) {
@@ -183,6 +194,14 @@ function autosave_disable_buttons() {
setTimeout(autosave_enable_buttons, 5000);
}
function delayed_autosave() {
setTimeout(function(){
if ( blockSave )
return;
autosave();
}, 200);
}
autosave = function() {
// (bool) is rich editor enabled and active
var rich = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden(), post_data, doAutoSave, ed, origStatus, successCallback;

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'), '20090823' );
$scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20090825' );
$scripts->add_data( 'autosave', 'group', 1 );
$scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array('wp-ajax-response'), '20090504' );
@@ -275,7 +275,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'), '20090624' );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'slug'), '20090825' );
$scripts->add_data( 'post', 'group', 1 );
$scripts->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
@@ -303,7 +303,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'), '20090526' );
$scripts->add( 'page', "/wp-admin/js/page$suffix.js", array('jquery', 'slug', 'wp-lists', 'postbox'), '20090825' );
$scripts->add_data( 'page', 'group', 1 );
$scripts->localize( 'page', 'postL10n', array(
'cancel' => __('Cancel'),