var autosaveLast = ''; function autosave_timer() { autosave(); setTimeout("autosave_timer()", ); } function autosave_start_timer() { var form = $('post'); autosaveLast = form.post_title.value+form.content.value; setTimeout("autosave_timer()", ); } 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(); } function autosave_update_nonce() { var response = nonceAjax.response; document.getElementsByName('_wpnonce')[0].value = response; } function autosave_update_post_ID() { var response = autosaveAjax.response; var res = parseInt(response); var message; if(isNaN(res)) { message = "" + response; } else { message = "" + autosave_cur_time(); $('post_ID').name = "post_ID"; $('post_ID').value = res; // 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); nonceAjax.requestFile = "/wp-admin/admin-ajax.php"; nonceAjax.onCompletion = autosave_update_nonce; nonceAjax.method = "POST"; nonceAjax.runAJAX(); $('hiddenaction').value = 'editpost'; } $('autosave').innerHTML = message; } function autosave_loading() { $('autosave').innerHTML = ""; } function autosave_saved() { var response = autosaveAjax.response; var res = parseInt(response); var message; if(isNaN(res)) { message = "" + response; } else { message = "" + autosave_cur_time() + "."; } $('autosave').innerHTML = message; } function autosave() { var form = $('post'); var rich = ((typeof tinyMCE != "undefined") && tinyMCE.getInstanceById('content')) ? true : false; 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 || rich == false ) { autosaveAjax.setVar("content", form.content.value); } else { if(tinyMCE.selectedInstance.spellcheckerOn) return; tinyMCE.wpTriggerSave(); autosaveAjax.setVar("content", form.content.value); } if(form.post_title.value.length==0 || form.content.value.length==0 || form.post_title.value+form.content.value == autosaveLast) return; autosaveLast = form.post_title.value+form.content.value; cats = document.getElementsByName("post_category[]"); goodcats = ([]); for(i=0;i