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

@ -4,7 +4,7 @@ jQuery(document).ready( function($) {
$('#title').blur( function() { if ( ($("#post_ID").val() > 0) || ($("#title").val().length == 0) ) return; autosave(); } );
var stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), dotabkey = true;
var stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html();
function updateVisibility() {
if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
@ -182,33 +182,4 @@ jQuery(document).ready( function($) {
return s;
}
});
// preview
$('#post-preview').click(function(e){
if ( 1 > $('#post_ID').val() && autosaveFirst ) {
autosaveDelayPreview = true;
autosave();
return false;
}
$('input#wp-preview').val('dopreview');
$('form#post').attr('target', 'wp-preview').submit().attr('target', '');
$('input#wp-preview').val('');
return false;
});
// 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;
}
}
});
}
});

File diff suppressed because one or more lines are too long

View File

@ -210,7 +210,7 @@ var commentsBox, tagCloud;
})(jQuery);
jQuery(document).ready( function($) {
var noSyncChecks = false, syncChecks, catAddAfter, dotabkey = true, stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), sticky = '';
var noSyncChecks = false, syncChecks, catAddAfter, stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), sticky = '';
// for Press This
if ( typeof autosave != 'function' )
@ -475,43 +475,14 @@ jQuery(document).ready( function($) {
});
// Custom Fields
jQuery('#the-list').wpList( { addAfter: function( xml, s ) {
$('#the-list').wpList( { addAfter: function( xml, s ) {
$('table#list-table').show();
if ( jQuery.isFunction( autosave_update_post_ID ) ) {
if ( $.isFunction( autosave_update_post_ID ) ) {
autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
}
}, addBefore: function( s ) {
s.data += '&post_id=' + jQuery('#post_ID').val();
s.data += '&post_id=' + $('#post_ID').val();
return s;
}
});
// preview
$('#post-preview').click(function(e){
if ( 1 > $('#post_ID').val() && autosaveFirst ) {
autosaveDelayPreview = true;
autosave();
return false;
}
$('input#wp-preview').val('dopreview');
$('form#post').attr('target', 'wp-preview').submit().attr('target', '');
$('input#wp-preview').val('');
return false;
});
// 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;
}
}
});
}
});

File diff suppressed because one or more lines are too long

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'),