2006-08-11 14:19:32 -04:00
|
|
|
var autosaveLast = '';
|
2006-10-30 15:18:59 -05:00
|
|
|
var autosavePeriodical;
|
2006-11-20 19:55:06 -05:00
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
function autosave_start_timer() {
|
2006-08-16 02:56:35 -04:00
|
|
|
var form = $('post');
|
|
|
|
autosaveLast = form.post_title.value+form.content.value;
|
2007-01-17 22:32:54 -05:00
|
|
|
// Keep autosave_interval in sync with edit_post().
|
2007-03-06 12:35:01 -05:00
|
|
|
autosavePeriodical = new PeriodicalExecuter(autosave, autosaveL10n.autosaveInterval);
|
2006-11-20 19:55:06 -05:00
|
|
|
//Disable autosave after the form has been submitted
|
2006-11-20 20:39:09 -05:00
|
|
|
if(form.addEventListener) {
|
|
|
|
form.addEventListener("submit", function () { autosavePeriodical.currentlyExecuting = true; }, false);
|
|
|
|
}
|
2006-11-20 19:55:06 -05:00
|
|
|
if(form.attachEvent) {
|
2006-12-06 00:33:52 -05:00
|
|
|
form.save ? form.save.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
|
|
|
|
form.submit ? form.submit.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
|
|
|
|
form.publish ? form.publish.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
|
|
|
|
form.deletepost ? form.deletepost.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
|
2006-11-20 19:55:06 -05:00
|
|
|
}
|
2006-08-10 23:54:45 -04: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 10:24:54 -05:00
|
|
|
|
2006-08-11 14:50:28 -04:00
|
|
|
function autosave_update_nonce() {
|
|
|
|
var response = nonceAjax.response;
|
|
|
|
document.getElementsByName('_wpnonce')[0].value = response;
|
|
|
|
}
|
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
function autosave_update_post_ID() {
|
|
|
|
var response = autosaveAjax.response;
|
|
|
|
var res = parseInt(response);
|
|
|
|
var message;
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
if(isNaN(res)) {
|
2007-03-06 12:35:01 -05:00
|
|
|
message = autosaveL10n.errorText.replace(/%response%/g, response);
|
2006-08-10 23:54:45 -04:00
|
|
|
} else {
|
2007-03-06 12:35:01 -05:00
|
|
|
message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
|
2006-08-10 23:54:45 -04:00
|
|
|
$('post_ID').name = "post_ID";
|
|
|
|
$('post_ID').value = res;
|
2006-08-11 14:50:28 -04:00
|
|
|
// We need new nonces
|
|
|
|
nonceAjax = new sack();
|
|
|
|
nonceAjax.element = null;
|
|
|
|
nonceAjax.setVar("action", "autosave-generate-nonces");
|
|
|
|
nonceAjax.setVar("post_ID", res);
|
|
|
|
nonceAjax.setVar("cookie", document.cookie);
|
|
|
|
nonceAjax.setVar("post_type", $('post_type').value);
|
2007-03-06 12:35:01 -05:00
|
|
|
nonceAjax.requestFile = autosaveL10n.requestFile;
|
2006-08-11 14:50:28 -04:00
|
|
|
nonceAjax.onCompletion = autosave_update_nonce;
|
|
|
|
nonceAjax.method = "POST";
|
|
|
|
nonceAjax.runAJAX();
|
2006-08-15 17:07:13 -04:00
|
|
|
$('hiddenaction').value = 'editpost';
|
2006-08-10 23:54:45 -04:00
|
|
|
}
|
|
|
|
$('autosave').innerHTML = message;
|
2006-12-06 00:33:52 -05:00
|
|
|
autosave_enable_buttons();
|
2006-08-10 23:54:45 -04:00
|
|
|
}
|
2006-08-11 14:50:28 -04:00
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
function autosave_loading() {
|
2007-03-06 12:35:01 -05:00
|
|
|
$('autosave').innerHTML = autosaveL10n.savingText;
|
2006-08-10 23:54:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function autosave_saved() {
|
|
|
|
var response = autosaveAjax.response;
|
|
|
|
var res = parseInt(response);
|
|
|
|
var message;
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
if(isNaN(res)) {
|
2007-03-06 12:35:01 -05:00
|
|
|
message = autosaveL10n.errorText.replace(/%response%/g, response);
|
2006-08-10 23:54:45 -04:00
|
|
|
} else {
|
2007-03-06 12:35:01 -05:00
|
|
|
message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
|
2006-08-10 23:54:45 -04:00
|
|
|
}
|
|
|
|
$('autosave').innerHTML = message;
|
2006-12-06 00:33:52 -05:00
|
|
|
autosave_enable_buttons();
|
2006-08-10 23:54:45 -04:00
|
|
|
}
|
2006-12-06 00:33:52 -05:00
|
|
|
|
|
|
|
function autosave_disable_buttons() {
|
|
|
|
var form = $('post');
|
|
|
|
form.save ? form.save.disabled = 'disabled' : null;
|
|
|
|
form.submit ? form.submit.disabled = 'disabled' : null;
|
|
|
|
form.publish ? form.publish.disabled = 'disabled' : null;
|
|
|
|
form.deletepost ? form.deletepost.disabled = 'disabled' : null;
|
2007-01-17 22:32:54 -05:00
|
|
|
setTimeout('autosave_enable_buttons();', 1000); // Re-enable 1 sec later. Just gives autosave a head start to avoid collisions.
|
2006-12-06 00:33:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function autosave_enable_buttons() {
|
|
|
|
var form = $('post');
|
|
|
|
form.save ? form.save.disabled = '' : null;
|
|
|
|
form.submit ? form.submit.disabled = '' : null;
|
|
|
|
form.publish ? form.publish.disabled = '' : null;
|
|
|
|
form.deletepost ? form.deletepost.disabled = '' : null;
|
|
|
|
}
|
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
function autosave() {
|
2006-08-11 14:19:32 -04:00
|
|
|
var form = $('post');
|
2006-09-22 15:35:37 -04:00
|
|
|
var rich = ((typeof tinyMCE != "undefined") && tinyMCE.getInstanceById('content')) ? true : false;
|
2006-08-11 14:19:32 -04:00
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
autosaveAjax = new sack();
|
|
|
|
|
|
|
|
/* Gotta do this up here so we can check the length when tinyMCE is in use */
|
2006-09-22 03:04:41 -04:00
|
|
|
if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {
|
2006-08-10 23:54:45 -04:00
|
|
|
autosaveAjax.setVar("content", form.content.value);
|
|
|
|
} else {
|
2006-10-30 15:18:59 -05:00
|
|
|
// Don't run while the TinyMCE spellcheck is on.
|
2006-08-15 22:50:03 -04:00
|
|
|
if(tinyMCE.selectedInstance.spellcheckerOn) return;
|
2006-08-11 14:19:32 -04:00
|
|
|
tinyMCE.wpTriggerSave();
|
2006-08-10 23:54:45 -04:00
|
|
|
autosaveAjax.setVar("content", form.content.value);
|
|
|
|
}
|
|
|
|
|
2006-08-11 14:19:32 -04:00
|
|
|
if(form.post_title.value.length==0 || form.content.value.length==0 || form.post_title.value+form.content.value == autosaveLast)
|
2006-08-10 23:54:45 -04:00
|
|
|
return;
|
2006-08-11 14:19:32 -04:00
|
|
|
|
2006-12-06 00:33:52 -05:00
|
|
|
autosave_disable_buttons();
|
|
|
|
|
2006-08-11 14:19:32 -04:00
|
|
|
autosaveLast = form.post_title.value+form.content.value;
|
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
cats = document.getElementsByName("post_category[]");
|
|
|
|
goodcats = ([]);
|
|
|
|
for(i=0;i<cats.length;i++) {
|
|
|
|
if(cats[i].checked)
|
|
|
|
goodcats.push(cats[i].value);
|
|
|
|
}
|
|
|
|
catslist = goodcats.join(",");
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
autosaveAjax.setVar("action", "autosave");
|
|
|
|
autosaveAjax.setVar("cookie", document.cookie);
|
|
|
|
autosaveAjax.setVar("catslist", catslist);
|
|
|
|
autosaveAjax.setVar("post_ID", $("post_ID").value);
|
|
|
|
autosaveAjax.setVar("post_title", form.post_title.value);
|
|
|
|
autosaveAjax.setVar("post_type", form.post_type.value);
|
2007-12-11 15:30:22 -05:00
|
|
|
autosaveAjax.setVar("tags_input", form.tags_input.value);
|
2006-09-11 20:01:18 -04:00
|
|
|
if ( form.comment_status.checked )
|
|
|
|
autosaveAjax.setVar("comment_status", 'open');
|
|
|
|
if ( form.ping_status.checked )
|
|
|
|
autosaveAjax.setVar("ping_status", 'open');
|
2006-08-10 23:54:45 -04:00
|
|
|
if(form.excerpt)
|
2007-02-27 10:24:54 -05:00
|
|
|
autosaveAjax.setVar("excerpt", form.excerpt.value);
|
|
|
|
|
2006-09-22 03:04:41 -04:00
|
|
|
if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {
|
2006-08-10 23:54:45 -04:00
|
|
|
autosaveAjax.setVar("content", form.content.value);
|
|
|
|
} else {
|
2006-08-11 14:19:32 -04:00
|
|
|
tinyMCE.wpTriggerSave();
|
2006-08-10 23:54:45 -04:00
|
|
|
autosaveAjax.setVar("content", form.content.value);
|
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2007-03-06 12:35:01 -05:00
|
|
|
autosaveAjax.requestFile = autosaveL10n.requestFile;
|
2006-08-10 23:54:45 -04:00
|
|
|
autosaveAjax.method = "POST";
|
|
|
|
autosaveAjax.element = null;
|
|
|
|
autosaveAjax.onLoading = autosave_loading;
|
|
|
|
autosaveAjax.onInteractive = autosave_loading;
|
|
|
|
if(parseInt($("post_ID").value) < 1)
|
|
|
|
autosaveAjax.onCompletion = autosave_update_post_ID;
|
|
|
|
else
|
|
|
|
autosaveAjax.onCompletion = autosave_saved;
|
|
|
|
autosaveAjax.runAJAX();
|
2006-08-16 03:28:24 -04:00
|
|
|
}
|