Ticket #3469: rename-autosave.diff
File rename-autosave.diff, 12.8 KB (added by , 18 years ago) |
---|
-
wp-includes/js/autosave-js.php
1 <?php @require_once('../../wp-config.php'); 2 cache_javascript_headers(); 3 ?> 4 var autosaveLast = ''; 5 var autosavePeriodical; 6 7 function autosave_start_timer() { 8 var form = $('post'); 9 autosaveLast = form.post_title.value+form.content.value; 10 autosavePeriodical = new PeriodicalExecuter(autosave, <?php echo apply_filters('autosave_interval', '120'); ?>); 11 //Disable autosave after the form has been submitted 12 if(form.addEventListener) { 13 form.addEventListener("submit", function () { autosavePeriodical.currentlyExecuting = true; }, false); 14 } 15 if(form.attachEvent) { 16 form.save ? form.save.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 17 form.submit ? form.submit.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 18 form.publish ? form.publish.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 19 form.deletepost ? form.deletepost.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 20 } 21 } 22 addLoadEvent(autosave_start_timer) 23 24 function autosave_cur_time() { 25 var now = new Date(); 26 return "" + ((now.getHours() >12) ? now.getHours() -12 : now.getHours()) + 27 ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes() + 28 ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds(); 29 } 30 31 function autosave_update_nonce() { 32 var response = nonceAjax.response; 33 document.getElementsByName('_wpnonce')[0].value = response; 34 } 35 36 function autosave_update_post_ID() { 37 var response = autosaveAjax.response; 38 var res = parseInt(response); 39 var message; 40 41 if(isNaN(res)) { 42 message = "<?php echo js_escape(__('Error: ')); ?>" + response; 43 } else { 44 message = "<?php echo js_escape(__('Saved at ')); ?>" + autosave_cur_time(); 45 $('post_ID').name = "post_ID"; 46 $('post_ID').value = res; 47 // We need new nonces 48 nonceAjax = new sack(); 49 nonceAjax.element = null; 50 nonceAjax.setVar("action", "autosave-generate-nonces"); 51 nonceAjax.setVar("post_ID", res); 52 nonceAjax.setVar("cookie", document.cookie); 53 nonceAjax.setVar("post_type", $('post_type').value); 54 nonceAjax.requestFile = "<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php"; 55 nonceAjax.onCompletion = autosave_update_nonce; 56 nonceAjax.method = "POST"; 57 nonceAjax.runAJAX(); 58 $('hiddenaction').value = 'editpost'; 59 } 60 $('autosave').innerHTML = message; 61 autosave_enable_buttons(); 62 } 63 64 function autosave_loading() { 65 $('autosave').innerHTML = "<?php echo js_escape(__('Saving Draft...')); ?>"; 66 } 67 68 function autosave_saved() { 69 var response = autosaveAjax.response; 70 var res = parseInt(response); 71 var message; 72 73 if(isNaN(res)) { 74 message = "<?php echo js_escape(__('Error: ')); ?>" + response; 75 } else { 76 message = "<?php echo js_escape(__('Saved at ')); ?>" + autosave_cur_time() + "."; 77 } 78 $('autosave').innerHTML = message; 79 autosave_enable_buttons(); 80 } 81 82 function autosave_disable_buttons() { 83 var form = $('post'); 84 form.save ? form.save.disabled = 'disabled' : null; 85 form.submit ? form.submit.disabled = 'disabled' : null; 86 form.publish ? form.publish.disabled = 'disabled' : null; 87 form.deletepost ? form.deletepost.disabled = 'disabled' : null; 88 } 89 90 function autosave_enable_buttons() { 91 var form = $('post'); 92 form.save ? form.save.disabled = '' : null; 93 form.submit ? form.submit.disabled = '' : null; 94 form.publish ? form.publish.disabled = '' : null; 95 form.deletepost ? form.deletepost.disabled = '' : null; 96 } 97 98 function autosave() { 99 var form = $('post'); 100 var rich = ((typeof tinyMCE != "undefined") && tinyMCE.getInstanceById('content')) ? true : false; 101 102 autosaveAjax = new sack(); 103 104 /* Gotta do this up here so we can check the length when tinyMCE is in use */ 105 if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) { 106 autosaveAjax.setVar("content", form.content.value); 107 } else { 108 // Don't run while the TinyMCE spellcheck is on. 109 if(tinyMCE.selectedInstance.spellcheckerOn) return; 110 tinyMCE.wpTriggerSave(); 111 autosaveAjax.setVar("content", form.content.value); 112 } 113 114 if(form.post_title.value.length==0 || form.content.value.length==0 || form.post_title.value+form.content.value == autosaveLast) 115 return; 116 117 autosave_disable_buttons(); 118 119 autosaveLast = form.post_title.value+form.content.value; 120 121 cats = document.getElementsByName("post_category[]"); 122 goodcats = ([]); 123 for(i=0;i<cats.length;i++) { 124 if(cats[i].checked) 125 goodcats.push(cats[i].value); 126 } 127 catslist = goodcats.join(","); 128 129 autosaveAjax.setVar("action", "autosave"); 130 autosaveAjax.setVar("cookie", document.cookie); 131 autosaveAjax.setVar("catslist", catslist); 132 autosaveAjax.setVar("post_ID", $("post_ID").value); 133 autosaveAjax.setVar("post_title", form.post_title.value); 134 autosaveAjax.setVar("post_type", form.post_type.value); 135 if ( form.comment_status.checked ) 136 autosaveAjax.setVar("comment_status", 'open'); 137 if ( form.ping_status.checked ) 138 autosaveAjax.setVar("ping_status", 'open'); 139 if(form.excerpt) 140 autosaveAjax.setVar("excerpt", form.excerpt.value); 141 142 if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) { 143 autosaveAjax.setVar("content", form.content.value); 144 } else { 145 tinyMCE.wpTriggerSave(); 146 autosaveAjax.setVar("content", form.content.value); 147 } 148 149 autosaveAjax.requestFile = "<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php"; 150 autosaveAjax.method = "POST"; 151 autosaveAjax.element = null; 152 autosaveAjax.onLoading = autosave_loading; 153 autosaveAjax.onInteractive = autosave_loading; 154 if(parseInt($("post_ID").value) < 1) 155 autosaveAjax.onCompletion = autosave_update_post_ID; 156 else 157 autosaveAjax.onCompletion = autosave_saved; 158 autosaveAjax.runAJAX(); 159 } -
wp-includes/js/autosave.js.php
1 <?php @require_once('../../wp-config.php');2 cache_javascript_headers();3 ?>4 var autosaveLast = '';5 var autosavePeriodical;6 7 function autosave_start_timer() {8 var form = $('post');9 autosaveLast = form.post_title.value+form.content.value;10 autosavePeriodical = new PeriodicalExecuter(autosave, <?php echo apply_filters('autosave_interval', '120'); ?>);11 //Disable autosave after the form has been submitted12 if(form.addEventListener) {13 form.addEventListener("submit", function () { autosavePeriodical.currentlyExecuting = true; }, false);14 }15 if(form.attachEvent) {16 form.save ? form.save.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;17 form.submit ? form.submit.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;18 form.publish ? form.publish.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;19 form.deletepost ? form.deletepost.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;20 }21 }22 addLoadEvent(autosave_start_timer)23 24 function autosave_cur_time() {25 var now = new Date();26 return "" + ((now.getHours() >12) ? now.getHours() -12 : now.getHours()) +27 ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes() +28 ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();29 }30 31 function autosave_update_nonce() {32 var response = nonceAjax.response;33 document.getElementsByName('_wpnonce')[0].value = response;34 }35 36 function autosave_update_post_ID() {37 var response = autosaveAjax.response;38 var res = parseInt(response);39 var message;40 41 if(isNaN(res)) {42 message = "<?php echo js_escape(__('Error: ')); ?>" + response;43 } else {44 message = "<?php echo js_escape(__('Saved at ')); ?>" + autosave_cur_time();45 $('post_ID').name = "post_ID";46 $('post_ID').value = res;47 // We need new nonces48 nonceAjax = new sack();49 nonceAjax.element = null;50 nonceAjax.setVar("action", "autosave-generate-nonces");51 nonceAjax.setVar("post_ID", res);52 nonceAjax.setVar("cookie", document.cookie);53 nonceAjax.setVar("post_type", $('post_type').value);54 nonceAjax.requestFile = "<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php";55 nonceAjax.onCompletion = autosave_update_nonce;56 nonceAjax.method = "POST";57 nonceAjax.runAJAX();58 $('hiddenaction').value = 'editpost';59 }60 $('autosave').innerHTML = message;61 autosave_enable_buttons();62 }63 64 function autosave_loading() {65 $('autosave').innerHTML = "<?php echo js_escape(__('Saving Draft...')); ?>";66 }67 68 function autosave_saved() {69 var response = autosaveAjax.response;70 var res = parseInt(response);71 var message;72 73 if(isNaN(res)) {74 message = "<?php echo js_escape(__('Error: ')); ?>" + response;75 } else {76 message = "<?php echo js_escape(__('Saved at ')); ?>" + autosave_cur_time() + ".";77 }78 $('autosave').innerHTML = message;79 autosave_enable_buttons();80 }81 82 function autosave_disable_buttons() {83 var form = $('post');84 form.save ? form.save.disabled = 'disabled' : null;85 form.submit ? form.submit.disabled = 'disabled' : null;86 form.publish ? form.publish.disabled = 'disabled' : null;87 form.deletepost ? form.deletepost.disabled = 'disabled' : null;88 }89 90 function autosave_enable_buttons() {91 var form = $('post');92 form.save ? form.save.disabled = '' : null;93 form.submit ? form.submit.disabled = '' : null;94 form.publish ? form.publish.disabled = '' : null;95 form.deletepost ? form.deletepost.disabled = '' : null;96 }97 98 function autosave() {99 var form = $('post');100 var rich = ((typeof tinyMCE != "undefined") && tinyMCE.getInstanceById('content')) ? true : false;101 102 autosaveAjax = new sack();103 104 /* Gotta do this up here so we can check the length when tinyMCE is in use */105 if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {106 autosaveAjax.setVar("content", form.content.value);107 } else {108 // Don't run while the TinyMCE spellcheck is on.109 if(tinyMCE.selectedInstance.spellcheckerOn) return;110 tinyMCE.wpTriggerSave();111 autosaveAjax.setVar("content", form.content.value);112 }113 114 if(form.post_title.value.length==0 || form.content.value.length==0 || form.post_title.value+form.content.value == autosaveLast)115 return;116 117 autosave_disable_buttons();118 119 autosaveLast = form.post_title.value+form.content.value;120 121 cats = document.getElementsByName("post_category[]");122 goodcats = ([]);123 for(i=0;i<cats.length;i++) {124 if(cats[i].checked)125 goodcats.push(cats[i].value);126 }127 catslist = goodcats.join(",");128 129 autosaveAjax.setVar("action", "autosave");130 autosaveAjax.setVar("cookie", document.cookie);131 autosaveAjax.setVar("catslist", catslist);132 autosaveAjax.setVar("post_ID", $("post_ID").value);133 autosaveAjax.setVar("post_title", form.post_title.value);134 autosaveAjax.setVar("post_type", form.post_type.value);135 if ( form.comment_status.checked )136 autosaveAjax.setVar("comment_status", 'open');137 if ( form.ping_status.checked )138 autosaveAjax.setVar("ping_status", 'open');139 if(form.excerpt)140 autosaveAjax.setVar("excerpt", form.excerpt.value);141 142 if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {143 autosaveAjax.setVar("content", form.content.value);144 } else {145 tinyMCE.wpTriggerSave();146 autosaveAjax.setVar("content", form.content.value);147 }148 149 autosaveAjax.requestFile = "<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php";150 autosaveAjax.method = "POST";151 autosaveAjax.element = null;152 autosaveAjax.onLoading = autosave_loading;153 autosaveAjax.onInteractive = autosave_loading;154 if(parseInt($("post_ID").value) < 1)155 autosaveAjax.onCompletion = autosave_update_post_ID;156 else157 autosaveAjax.onCompletion = autosave_saved;158 autosaveAjax.runAJAX();159 } -
wp-includes/script-loader.php
19 19 $mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php'); 20 20 $this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20061113' ); 21 21 $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0'); 22 $this->add( 'autosave', '/wp-includes/js/autosave .js.php', array('prototype', 'sack'), '4508');22 $this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '4508'); 23 23 $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '4459'); 24 24 $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '4583'); 25 25 $this->add( 'scriptaculous', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.6.1');