diff --git a/wp-includes/js/autosave.js b/wp-includes/js/autosave.js index 2f779203c0..ee0f31858b 100644 --- a/wp-includes/js/autosave.js +++ b/wp-includes/js/autosave.js @@ -1,6 +1,8 @@ var autosaveLast = ''; var autosavePeriodical; var autosaveOldMessage = ''; +var autosaveDelayURL = null; +var previewwin; jQuery(function($) { autosaveLast = $('#post #title').val()+$('#post #content').val(); @@ -8,6 +10,16 @@ jQuery(function($) { //Disable autosave after the form has been submitted $("#post").submit(function() { $.cancel(autosavePeriodical); }); + + // Autosave when the preview button is clicked. + $('#previewview a').click(function(e) { + autosave(); + autosaveDelayURL = this.href; + previewwin = window.open('','_blank'); + + e.preventDefault(); + return false; + }); }); function autosave_parse_response(response) { @@ -96,6 +108,16 @@ function autosave_update_preview_link(post_id) { getpermalinknonce: jQuery('#getpermalinknonce').val() }, function(permalink) { jQuery('#previewview').html(''+previewText+''); + + // Autosave when the preview button is clicked. + jQuery('#previewview a').click(function(e) { + autosave(); + autosaveDelayURL = this.href; + previewwin = window.open('','_blank'); + + e.preventDefault(); + return false; + }); }); } } @@ -125,6 +147,10 @@ function autosave_loading() { function autosave_enable_buttons() { jQuery("#submitpost :button:disabled, #submitpost :submit:disabled").attr('disabled', ''); + if ( autosaveDelayURL ) { + previewwin.location = autosaveDelayURL; + autosaveDelayURL = null; + } } function autosave_disable_buttons() { diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 5cbac7dada..cb42b47331 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -46,7 +46,7 @@ function wp_default_scripts( &$scripts ) { 'broken' => __('An unidentified error has occurred.') ) ); - $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' ); + $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080622' ); $scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' ); $scripts->localize( 'wp-lists', 'wpListL10n', array(