2006-08-10 23:54:45 -04:00
|
|
|
<?php @require_once('../../wp-config.php');
|
2006-08-22 13:31:53 -04:00
|
|
|
cache_javascript_headers();
|
2006-08-10 23:54:45 -04:00
|
|
|
?>
|
2006-08-11 14:19:32 -04:00
|
|
|
var autosaveLast = '';
|
2006-08-10 23:54:45 -04:00
|
|
|
function autosave_timer() {
|
|
|
|
autosave();
|
|
|
|
setTimeout("autosave_timer()", <?php echo apply_filters('autosave_interval', '60000') ?>);
|
|
|
|
}
|
|
|
|
|
|
|
|
function autosave_start_timer() {
|
2006-08-16 02:56:35 -04:00
|
|
|
var form = $('post');
|
|
|
|
autosaveLast = form.post_title.value+form.content.value;
|
2006-08-10 23:54:45 -04:00
|
|
|
setTimeout("autosave_timer()", <?php echo apply_filters('autosave_start_delay', '60000') ?>);
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(isNaN(res)) {
|
|
|
|
message = "<?php _e('Error: '); ?>" + response;
|
|
|
|
} else {
|
|
|
|
message = "<?php _e('Saved at '); ?>" + autosave_cur_time();
|
|
|
|
$('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);
|
2006-08-22 01:57:28 -04:00
|
|
|
nonceAjax.requestFile = "<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php";
|
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-08-11 14:50:28 -04:00
|
|
|
|
2006-08-10 23:54:45 -04:00
|
|
|
function autosave_loading() {
|
|
|
|
$('autosave').innerHTML = "<?php _e('Saving Draft...'); ?>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function autosave_saved() {
|
|
|
|
var response = autosaveAjax.response;
|
|
|
|
var res = parseInt(response);
|
|
|
|
var message;
|
|
|
|
|
|
|
|
if(isNaN(res)) {
|
|
|
|
message = "<?php _e('Error: '); ?>" + response;
|
|
|
|
} else {
|
|
|
|
message = "<?php _e('Saved at '); ?>" + autosave_cur_time() + ".";
|
|
|
|
}
|
|
|
|
$('autosave').innerHTML = message;
|
|
|
|
}
|
|
|
|
|
|
|
|
function autosave() {
|
2006-08-11 14:19:32 -04:00
|
|
|
var form = $('post');
|
|
|
|
|
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 */
|
|
|
|
if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 ) {
|
|
|
|
autosaveAjax.setVar("content", form.content.value);
|
|
|
|
} else {
|
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
|
|
|
|
|
|
|
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(",");
|
|
|
|
|
|
|
|
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);
|
|
|
|
if(form.excerpt)
|
|
|
|
autosaveAjax.setVar("excerpt", form.excerpt.value);
|
|
|
|
|
|
|
|
if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 ) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-08-22 01:57:28 -04:00
|
|
|
autosaveAjax.requestFile = "<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php";
|
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
|
|
|
}
|