Changeset 6546
- Timestamp:
- 01/04/2008 08:46:33 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/page-new.php
r6513 r6546 4 4 $parent_file = 'post-new.php'; 5 5 $editing = true; 6 wp_enqueue_script('prototype');7 wp_enqueue_script('jquery');8 6 wp_enqueue_script('autosave'); 9 7 require_once('admin-header.php'); -
trunk/wp-admin/page.php
r6513 r6546 53 53 } 54 54 55 if($post->post_status == 'draft') { 56 wp_enqueue_script('prototype'); 57 wp_enqueue_script('jquery'); 55 if ( 'draft' == $post->post_status ) 58 56 wp_enqueue_script('autosave'); 59 } 57 60 58 require_once('admin-header.php'); 61 59 -
trunk/wp-admin/post-new.php
r6542 r6546 4 4 $parent_file = 'post-new.php'; 5 5 $editing = true; 6 wp_enqueue_script('prototype');7 wp_enqueue_script('jquery');8 6 wp_enqueue_script('autosave'); 9 7 wp_enqueue_script('post'); -
trunk/wp-admin/post.php
r6542 r6546 61 61 wp_enqueue_script('post'); 62 62 63 if( 'draft' == $post->post_status ) { 64 wp_enqueue_script('prototype'); 63 if ( 'draft' == $post->post_status ) 65 64 wp_enqueue_script('autosave'); 66 }67 65 68 66 require_once('admin-header.php'); -
trunk/wp-includes/functions.php
r6542 r6546 969 969 function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true ) { 970 970 $name = attribute_escape( $name ); 971 echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';971 echo '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />'; 972 972 if ( $referer ) 973 973 wp_referer_field(); -
trunk/wp-includes/js/autosave.js
r6373 r6546 3 3 4 4 function autosave_start_timer() { 5 var form = $('post'); 6 autosaveLast = form.post_title.value+form.content.value; 5 autosaveLast = jQuery('#post #title').val()+jQuery('#post #content').val(); 7 6 // Keep autosave_interval in sync with edit_post(). 8 autosavePeriodical = new PeriodicalExecuter(autosave, autosaveL10n.autosaveInterval); 7 autosavePeriodical = jQuery.schedule({time: autosaveL10n.autosaveInterval * 1000, func: autosave, repeat: true, protect: true}); 8 9 9 //Disable autosave after the form has been submitted 10 if(form.addEventListener) { 11 form.addEventListener("submit", function () { autosavePeriodical.currentlyExecuting = true; }, false); 12 } 13 if(form.attachEvent) { 14 form.save ? form.save.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 15 form.submit ? form.submit.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 16 form.publish ? form.publish.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 17 form.deletepost ? form.deletepost.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null; 18 } 10 jQuery("#post #submit").submit(function() { jQuery.cancel(autosavePeriodical); }); 11 jQuery("#post #save").click(function() { jQuery.cancel(autosavePeriodical); }); 12 jQuery("#post #submit").click(function() { jQuery.cancel(autosavePeriodical); }); 13 jQuery("#post #publish").click(function() { jQuery.cancel(autosavePeriodical); }); 14 jQuery("#post #deletepost").click(function() { jQuery.cancel(autosavePeriodical); }); 19 15 } 20 16 addLoadEvent(autosave_start_timer) … … 27 23 } 28 24 29 function autosave_update_nonce() { 30 var response = nonceAjax.response; 31 document.getElementsByName('_wpnonce')[0].value = response; 32 } 33 34 function autosave_update_post_ID() { 35 var response = autosaveAjax.response; 25 function autosave_update_post_ID(response) { 36 26 var res = parseInt(response); 37 27 var message; … … 41 31 } else { 42 32 message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time()); 43 $('post_ID').name = "post_ID";44 $('post_ID').value = res;33 jQuery('#post_ID').attr({name: "post_ID"}); 34 jQuery('#post_ID').val(res); 45 35 // We need new nonces 46 nonceAjax = new sack(); 47 nonceAjax.element = null; 48 nonceAjax.setVar("action", "autosave-generate-nonces"); 49 nonceAjax.setVar("post_ID", res); 50 nonceAjax.setVar("cookie", document.cookie); 51 nonceAjax.setVar("post_type", $('post_type').value); 52 nonceAjax.requestFile = autosaveL10n.requestFile; 53 nonceAjax.onCompletion = autosave_update_nonce; 54 nonceAjax.method = "POST"; 55 nonceAjax.runAJAX(); 56 $('hiddenaction').value = 'editpost'; 36 jQuery.post(autosaveL10n.requestFile, { 37 action: "autosave-generate-nonces", 38 post_ID: res, 39 cookie: document.cookie, 40 post_type: jQuery('#post_type').val() 41 }, function(html) { 42 jQuery('#_wpnonce').val(html); 43 }); 44 jQuery('#hiddenaction').val('editpost'); 57 45 } 58 $('autosave').innerHTML = message;46 jQuery('#autosave').html(message); 59 47 autosave_enable_buttons(); 60 48 } 61 49 62 50 function autosave_loading() { 63 $('autosave').innerHTML = autosaveL10n.savingText;51 jQuery('#autosave').html(autosaveL10n.savingText); 64 52 } 65 53 66 function autosave_saved() { 67 var response = autosaveAjax.response; 54 function autosave_saved(response) { 68 55 var res = parseInt(response); 69 56 var message; … … 74 61 message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time()); 75 62 } 76 $('autosave').innerHTML = message;63 jQuery('#autosave').html(message); 77 64 autosave_enable_buttons(); 78 65 } 79 66 80 67 function autosave_disable_buttons() { 81 var form = $('post'); 82 form.save ? form.save.disabled = 'disabled' : null; 83 form.submit ? form.submit.disabled = 'disabled' : null; 84 form.publish ? form.publish.disabled = 'disabled' : null; 85 form.deletepost ? form.deletepost.disabled = 'disabled' : null; 68 jQuery("#post #save:enabled").attr('disabled', 'disabled'); 69 jQuery("#post #submit:enabled").attr('disabled', 'disabled'); 70 jQuery("#post #publish:enabled").attr('disabled', 'disabled'); 71 jQuery("#post #deletepost:enabled").attr('disabled', 'disabled'); 86 72 setTimeout('autosave_enable_buttons();', 1000); // Re-enable 1 sec later. Just gives autosave a head start to avoid collisions. 87 73 } 88 74 89 75 function autosave_enable_buttons() { 90 var form = $('post'); 91 form.save ? form.save.disabled = '' : null; 92 form.submit ? form.submit.disabled = '' : null; 93 form.publish ? form.publish.disabled = '' : null; 94 form.deletepost ? form.deletepost.disabled = '' : null; 76 jQuery("#post #save:disabled").attr('disabled', ''); 77 jQuery("#post #submit:disabled").attr('disabled', ''); 78 jQuery("#post #publish:disabled").attr('disabled', ''); 79 jQuery("#post #deletepost:disabled").attr('disabled', ''); 95 80 } 96 81 97 82 function autosave() { 98 var form = $('post');99 83 var rich = ((typeof tinyMCE != "undefined") && tinyMCE.getInstanceById('content')) ? true : false; 100 101 autosaveAjax = new sack(); 84 var post_data = { 85 action: "autosave", 86 post_ID: jQuery("#post_ID").val() || 0, 87 post_title: jQuery("#title").val() || "", 88 cookie: document.cookie, 89 tags_input: jQuery("#tags-input").val() || "", 90 post_type: jQuery('#post_type').val() || "" 91 }; 102 92 103 93 /* Gotta do this up here so we can check the length when tinyMCE is in use */ 104 94 if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) { 105 autosaveAjax.setVar("content", form.content.value);95 post_data["content"] = jQuery("#content").val(); 106 96 } else { 107 97 // Don't run while the TinyMCE spellcheck is on. 108 98 if(tinyMCE.selectedInstance.spellcheckerOn) return; 109 99 tinyMCE.wpTriggerSave(); 110 autosaveAjax.setVar("content", form.content.value);100 post_data["content"] = jQuery("#content").val(); 111 101 } 112 102 113 if( form.post_title.value.length==0 || form.content.value.length==0 || form.post_title.value+form.content.value == autosaveLast)103 if(post_data["post_title"].length==0 || post_data["content"].length==0 || post_data["post_title"] + post_data["content"] == autosaveLast) { 114 104 return; 105 } 115 106 116 107 autosave_disable_buttons(); 117 108 118 autosaveLast = form.post_title.value+form.content.value; 109 autosaveLast = jQuery("#title").val()+jQuery("#content").val(); 110 goodcats = ([]); 111 jQuery("[@name='post_category[]']:checked").each( function(i) { 112 goodcats.push(this.value); 113 } ); 114 post_data["catslist"] = goodcats.join(","); 119 115 120 cats = document.getElementsByName("post_category[]"); 121 goodcats = ([]); 122 for(i=0;i<cats.length;i++) { 123 if(cats[i].checked) 124 goodcats.push(cats[i].value); 125 } 126 catslist = goodcats.join(","); 127 128 autosaveAjax.setVar("action", "autosave"); 129 autosaveAjax.setVar("cookie", document.cookie); 130 autosaveAjax.setVar("catslist", catslist); 131 autosaveAjax.setVar("post_ID", $("post_ID").value); 132 autosaveAjax.setVar("post_title", form.post_title.value); 133 autosaveAjax.setVar("post_type", form.post_type.value); 134 autosaveAjax.setVar("tags_input", form.tags_input.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); 116 if ( jQuery("#comment_status").attr("checked") ) 117 post_data["comment_status"] = 'open'; 118 if ( jQuery("#ping_status").attr("checked") ) 119 post_data["ping_status"] = 'open'; 120 if( jQuery("#excerpt")) 121 post_data["excerpt"] = jQuery("#excerpt").val(); 141 122 142 123 if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) { 143 autosaveAjax.setVar("content", form.content.value);124 post_data["content"] = jQuery("#content").val(); 144 125 } else { 145 126 tinyMCE.wpTriggerSave(); 146 autosaveAjax.setVar("content", form.content.value);127 post_data["content"] = jQuery("#content").val(); 147 128 } 148 129 149 autosaveAjax.requestFile = autosaveL10n.requestFile; 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(); 130 if(parseInt(post_data["post_ID"]) < 1) { 131 post_data["temp_ID"] = post_data["post_ID"]; 132 jQuery.ajaxSetup({ 133 success: function(html) { autosave_update_post_ID(html); } 134 }); 135 } else { 136 jQuery.ajaxSetup({ 137 success: function(html) { autosave_saved(html); } 138 }); 139 } 140 jQuery.ajax({ 141 data: post_data, 142 beforeSend: function() { autosave_loading() }, 143 type: "POST", 144 url: autosaveL10n.requestFile 145 }); 159 146 } -
trunk/wp-includes/post.php
r6537 r6546 1003 1003 if ( !in_array($post_status, array('draft', 'pending')) ) 1004 1004 $post_date = current_time('mysql'); 1005 else 1006 $post_date = '0000-00-00 00:00:00'; 1005 1007 } 1006 1008 … … 1008 1010 if ( !in_array($post_status, array('draft', 'pending')) ) 1009 1011 $post_date_gmt = get_gmt_from_date($post_date); 1012 else 1013 $post_date_gmt = '0000-00-00 00:00:00'; 1010 1014 } 1011 1015 -
trunk/wp-includes/script-loader.php
r6544 r6546 37 37 $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); 38 38 39 $this->add( 'autosave', '/wp-includes/js/autosave.js', array(' prototype', 'sack'), '20070306');39 $this->add( 'autosave', '/wp-includes/js/autosave.js', array('jquery', 'schedule'), '20080104'); 40 40 $this->localize( 'autosave', 'autosaveL10n', array( 41 41 'autosaveInterval' => apply_filters('autosave_interval', '120'), … … 81 81 $this->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2'); 82 82 $this->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1'); 83 $this->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20'); 83 84 84 85 if ( is_admin() ) {
Note: See TracChangeset
for help on using the changeset viewer.