]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/autosave.js
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-includes / js / autosave.js
index b0a2fa5627a3317b533afcfaa90dd7e06b9d6c20..ee0f31858bb7c12667b6997e75af9aa57550c162 100644 (file)
@@ -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('<a target="_blank" href="'+permalink+'" tabindex="4">'+previewText+'</a>');
+
+                       // 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() {
@@ -154,8 +180,13 @@ var autosave = function() {
                doAutoSave = false;
 
        /* Gotta do this up here so we can check the length when tinyMCE is in use */
-       if ( rich ) { tinyMCE.triggerSave(); }
-
+       if ( rich ) {           
+               var ed = tinyMCE.activeEditor;
+               if ( 'mce_fullscreen' == ed.id )
+                       tinyMCE.get('content').setContent(ed.getContent({format : 'raw'}), {format : 'raw'});
+               tinyMCE.get('content').save();
+       }
+       
        post_data["content"] = jQuery("#content").val();
        if ( jQuery('#post_name').val() )
                post_data["post_name"] = jQuery('#post_name').val();
@@ -168,8 +199,6 @@ var autosave = function() {
        autosave_disable_buttons();
 
        var origStatus = jQuery('#original_post_status').val();
-       if ( 'draft' != origStatus ) // autosave currently only turned on for drafts
-               doAutoSave = false;
 
        autosaveLast = jQuery("#title").val()+jQuery("#content").val();
        goodcats = ([]);
@@ -182,9 +211,9 @@ var autosave = function() {
                post_data["comment_status"] = 'open';
        if ( jQuery("#ping_status").attr("checked") )
                post_data["ping_status"] = 'open';
-       if ( jQuery("#excerpt") )
+       if ( jQuery("#excerpt").size() )
                post_data["excerpt"] = jQuery("#excerpt").val();
-       if ( jQuery("#post_author") )
+       if ( jQuery("#post_author").size() )
                post_data["post_author"] = jQuery("#post_author").val();
 
        // Don't run while the TinyMCE spellcheck is on.  Why?  Who knows.