2006-08-11 20:19:32 +02:00
|
|
|
var autosaveLast = '';
|
2006-10-30 21:18:59 +01:00
|
|
|
var autosavePeriodical;
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2006-08-11 05:54:45 +02:00
|
|
|
function autosave_start_timer() {
|
2008-01-04 09:46:33 +01:00
|
|
|
autosaveLast = jQuery('#post #title').val()+jQuery('#post #content').val();
|
2007-01-18 04:32:54 +01:00
|
|
|
// Keep autosave_interval in sync with edit_post().
|
2008-01-04 09:46:33 +01:00
|
|
|
autosavePeriodical = jQuery.schedule({time: autosaveL10n.autosaveInterval * 1000, func: autosave, repeat: true, protect: true});
|
|
|
|
|
2006-11-21 01:55:06 +01:00
|
|
|
//Disable autosave after the form has been submitted
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery("#post #submit").submit(function() { jQuery.cancel(autosavePeriodical); });
|
|
|
|
jQuery("#post #save").click(function() { jQuery.cancel(autosavePeriodical); });
|
|
|
|
jQuery("#post #submit").click(function() { jQuery.cancel(autosavePeriodical); });
|
|
|
|
jQuery("#post #publish").click(function() { jQuery.cancel(autosavePeriodical); });
|
|
|
|
jQuery("#post #deletepost").click(function() { jQuery.cancel(autosavePeriodical); });
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
|
|
|
addLoadEvent(autosave_start_timer)
|
|
|
|
|
|
|
|
function autosave_cur_time() {
|
|
|
|
var now = new Date();
|
|
|
|
return "" + ((now.getHours() >12) ? now.getHours() -12 : now.getHours()) +
|
|
|
|
((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes() +
|
|
|
|
((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
|
|
|
|
}
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2008-01-04 09:46:33 +01:00
|
|
|
function autosave_update_post_ID(response) {
|
2006-08-11 05:54:45 +02:00
|
|
|
var res = parseInt(response);
|
|
|
|
var message;
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-08-11 05:54:45 +02:00
|
|
|
if(isNaN(res)) {
|
2007-03-06 18:35:01 +01:00
|
|
|
message = autosaveL10n.errorText.replace(/%response%/g, response);
|
2006-08-11 05:54:45 +02:00
|
|
|
} else {
|
2007-03-06 18:35:01 +01:00
|
|
|
message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery('#post_ID').attr({name: "post_ID"});
|
|
|
|
jQuery('#post_ID').val(res);
|
2006-08-11 20:50:28 +02:00
|
|
|
// We need new nonces
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery.post(autosaveL10n.requestFile, {
|
|
|
|
action: "autosave-generate-nonces",
|
|
|
|
post_ID: res,
|
|
|
|
cookie: document.cookie,
|
|
|
|
post_type: jQuery('#post_type').val()
|
|
|
|
}, function(html) {
|
|
|
|
jQuery('#_wpnonce').val(html);
|
|
|
|
});
|
|
|
|
jQuery('#hiddenaction').val('editpost');
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery('#autosave').html(message);
|
2006-12-06 06:33:52 +01:00
|
|
|
autosave_enable_buttons();
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
2006-08-11 20:50:28 +02:00
|
|
|
|
2006-08-11 05:54:45 +02:00
|
|
|
function autosave_loading() {
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery('#autosave').html(autosaveL10n.savingText);
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
|
|
|
|
2008-01-04 09:46:33 +01:00
|
|
|
function autosave_saved(response) {
|
2006-08-11 05:54:45 +02:00
|
|
|
var res = parseInt(response);
|
|
|
|
var message;
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-08-11 05:54:45 +02:00
|
|
|
if(isNaN(res)) {
|
2007-03-06 18:35:01 +01:00
|
|
|
message = autosaveL10n.errorText.replace(/%response%/g, response);
|
2006-08-11 05:54:45 +02:00
|
|
|
} else {
|
2007-03-06 18:35:01 +01:00
|
|
|
message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery('#autosave').html(message);
|
2006-12-06 06:33:52 +01:00
|
|
|
autosave_enable_buttons();
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
2006-12-06 06:33:52 +01:00
|
|
|
|
|
|
|
function autosave_disable_buttons() {
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery("#post #save:enabled").attr('disabled', 'disabled');
|
|
|
|
jQuery("#post #submit:enabled").attr('disabled', 'disabled');
|
|
|
|
jQuery("#post #publish:enabled").attr('disabled', 'disabled');
|
|
|
|
jQuery("#post #deletepost:enabled").attr('disabled', 'disabled');
|
2007-01-18 04:32:54 +01:00
|
|
|
setTimeout('autosave_enable_buttons();', 1000); // Re-enable 1 sec later. Just gives autosave a head start to avoid collisions.
|
2006-12-06 06:33:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function autosave_enable_buttons() {
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery("#post #save:disabled").attr('disabled', '');
|
|
|
|
jQuery("#post #submit:disabled").attr('disabled', '');
|
|
|
|
jQuery("#post #publish:disabled").attr('disabled', '');
|
|
|
|
jQuery("#post #deletepost:disabled").attr('disabled', '');
|
2006-12-06 06:33:52 +01:00
|
|
|
}
|
|
|
|
|
2006-08-11 05:54:45 +02:00
|
|
|
function autosave() {
|
2006-09-22 21:35:37 +02:00
|
|
|
var rich = ((typeof tinyMCE != "undefined") && tinyMCE.getInstanceById('content')) ? true : false;
|
2008-01-04 09:46:33 +01:00
|
|
|
var post_data = {
|
|
|
|
action: "autosave",
|
|
|
|
post_ID: jQuery("#post_ID").val() || 0,
|
|
|
|
post_title: jQuery("#title").val() || "",
|
|
|
|
cookie: document.cookie,
|
|
|
|
tags_input: jQuery("#tags-input").val() || "",
|
|
|
|
post_type: jQuery('#post_type').val() || ""
|
|
|
|
};
|
2006-08-11 05:54:45 +02:00
|
|
|
|
|
|
|
/* Gotta do this up here so we can check the length when tinyMCE is in use */
|
2006-09-22 09:04:41 +02:00
|
|
|
if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {
|
2008-01-04 09:46:33 +01:00
|
|
|
post_data["content"] = jQuery("#content").val();
|
2006-08-11 05:54:45 +02:00
|
|
|
} else {
|
2006-10-30 21:18:59 +01:00
|
|
|
// Don't run while the TinyMCE spellcheck is on.
|
2006-08-16 04:50:03 +02:00
|
|
|
if(tinyMCE.selectedInstance.spellcheckerOn) return;
|
2006-08-11 20:19:32 +02:00
|
|
|
tinyMCE.wpTriggerSave();
|
2008-01-04 09:46:33 +01:00
|
|
|
post_data["content"] = jQuery("#content").val();
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
|
|
|
|
2008-01-04 09:46:33 +01:00
|
|
|
if(post_data["post_title"].length==0 || post_data["content"].length==0 || post_data["post_title"] + post_data["content"] == autosaveLast) {
|
2006-08-11 05:54:45 +02:00
|
|
|
return;
|
2008-01-04 09:46:33 +01:00
|
|
|
}
|
2006-08-11 20:19:32 +02:00
|
|
|
|
2006-12-06 06:33:52 +01:00
|
|
|
autosave_disable_buttons();
|
|
|
|
|
2008-01-04 09:46:33 +01:00
|
|
|
autosaveLast = jQuery("#title").val()+jQuery("#content").val();
|
2006-08-11 05:54:45 +02:00
|
|
|
goodcats = ([]);
|
2008-01-04 09:46:33 +01:00
|
|
|
jQuery("[@name='post_category[]']:checked").each( function(i) {
|
|
|
|
goodcats.push(this.value);
|
|
|
|
} );
|
|
|
|
post_data["catslist"] = goodcats.join(",");
|
|
|
|
|
|
|
|
if ( jQuery("#comment_status").attr("checked") )
|
|
|
|
post_data["comment_status"] = 'open';
|
|
|
|
if ( jQuery("#ping_status").attr("checked") )
|
|
|
|
post_data["ping_status"] = 'open';
|
|
|
|
if( jQuery("#excerpt"))
|
|
|
|
post_data["excerpt"] = jQuery("#excerpt").val();
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-09-22 09:04:41 +02:00
|
|
|
if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {
|
2008-01-04 09:46:33 +01:00
|
|
|
post_data["content"] = jQuery("#content").val();
|
2006-08-11 05:54:45 +02:00
|
|
|
} else {
|
2006-08-11 20:19:32 +02:00
|
|
|
tinyMCE.wpTriggerSave();
|
2008-01-04 09:46:33 +01:00
|
|
|
post_data["content"] = jQuery("#content").val();
|
2006-08-11 05:54:45 +02:00
|
|
|
}
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2008-01-04 09:46:33 +01:00
|
|
|
if(parseInt(post_data["post_ID"]) < 1) {
|
|
|
|
post_data["temp_ID"] = post_data["post_ID"];
|
|
|
|
jQuery.ajaxSetup({
|
|
|
|
success: function(html) { autosave_update_post_ID(html); }
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
jQuery.ajaxSetup({
|
|
|
|
success: function(html) { autosave_saved(html); }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
jQuery.ajax({
|
|
|
|
data: post_data,
|
|
|
|
beforeSend: function() { autosave_loading() },
|
|
|
|
type: "POST",
|
|
|
|
url: autosaveL10n.requestFile
|
|
|
|
});
|
2006-08-16 09:28:24 +02:00
|
|
|
}
|