WordPress/wp-includes/js/autosave.js

1 line
6.4 KiB
JavaScript
Raw Normal View History

var autosave,autosaveLast="",autosavePeriodical,autosaveOldMessage="",autosaveDelayPreview=false,notSaved=true,blockSave=false,interimLogin=false;jQuery(document).ready(function($){var dotabkey=true;autosaveLast=$("#post #title").val()+$("#post #content").val();autosavePeriodical=$.schedule({time:autosaveL10n.autosaveInterval*1000,func:function(){autosave()},repeat:true,protect:true});$("#post").submit(function(){$.cancel(autosavePeriodical)});$('input[type="submit"], a.submitdelete',"#submitpost").click(function(){blockSave=true;window.onbeforeunload=null;$(":button, :submit","#submitpost").each(function(){var t=$(this);if(t.hasClass("button-primary")){t.addClass("button-primary-disabled")}else{t.addClass("button-disabled")}});$("#ajax-loading").css("visibility","visible")});window.onbeforeunload=function(){var mce=typeof(tinyMCE)!="undefined"?tinyMCE.activeEditor:false,title,content;if(mce&&!mce.isHidden()){if(mce.isDirty()){return autosaveL10n.saveAlert}}else{title=$("#post #title").val(),content=$("#post #content").val();if((title||content)&&title+content!=autosaveLast){return autosaveL10n.saveAlert}}};$("#post-preview").click(function(){if($("#auto_draft").val()=="1"&&notSaved){autosaveDelayPreview=true;autosave();return false}doPreview();return false});doPreview=function(){$("input#wp-preview").val("dopreview");$("form#post").attr("target","wp-preview").submit().attr("target","");$("input#wp-preview").val("")};if(typeof tinyMCE!="undefined"){$("#title")[$.browser.opera?"keypress":"keydown"](function(e){if(e.which==9&&!e.shiftKey&&!e.controlKey&&!e.altKey){if(($("#auto_draft").val()=="1")&&($("#title").val().length>0)){autosave()}if(tinyMCE.activeEditor&&!tinyMCE.activeEditor.isHidden()&&dotabkey){e.preventDefault();dotabkey=false;tinyMCE.activeEditor.focus();return false}}})}if("1"==$("#auto_draft").val()){$("#title").blur(function(){if(!this.value||$("#auto_draft").val()!="1"){return}delayed_autosave()})}});function autosave_parse_response(response){var res=wpAjax.parseAjaxResponse(response,"autosave"),message="",postID,sup,url;if(res&&res.responses&&res.responses.length){message=res.responses[0].data;if(res.responses[0].supplemental){sup=res.responses[0].supplemental;if("disable"==sup.disable_autosave){autosave=function(){};res={errors:true}}if(sup.session_expired&&(url=sup.session_expired)){if(!interimLogin||interimLogin.closed){interimLogin=window.open(url,"login","width=600,height=450,resizable=yes,scrollbars=yes,status=yes");interimLogin.focus()}delete sup.session_expired}jQuery.each(sup,function(selector,value){if(selector.match(/^replace-/)){jQuery("#"+selector.replace("replace-","")).val(value)}})}if(!res.errors){postID=parseInt(res.responses[0].id,10);if(!isNaN(postID)&&postID>0){autosave_update_slug(postID)}}}if(message){jQuery("#autosave").html(message)}else{if(autosaveOldMessage&&res){jQuery("#autosave").html(autosaveOldMessage)}}return res}function autosave_saved(response){blockSave=false;autosave_parse_response(response);autosave_enable_buttons()}function autosave_saved_new(response){blockSave=false;var res=autosave_parse_response(response),tempID,postID;if(res&&res.responses.length&&!res.errors){postID=parseInt(res.responses[0].id,10);autosave_update_post_ID(postID);if(autosaveDelayPreview){autosaveDelayPreview=false;doPreview()}}else{autosave_enable_buttons()}}function autosave_update_post_ID(postID){if(!isNaN(postID)&&postID>0){if(postID==parseInt(jQuery("#post_ID").val(),10)){return}notSaved=false;autosave_enable_buttons();jQuery("#delete-action a.submitdelete").fadeIn();jQuery("#hiddenaction").val("editpost");jQuery("#auto_draft").val("0")}}function autosave_update_slug(post_id){if("undefined"!=makeSlugeditClickable&&jQuery.isFunction(makeSlugeditClickable)&&!jQuery("#edit-slug-box > *").size()){jQuery.post(ajaxurl,{action:"sample-permalink",post_id:post_id,new_title:jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(data){jQuery("#edit-slug-box").html(data);makeSlugeditClickable()})}}function autosave_loading(){jQuery("#autosave").html(autosaveL10n.savi