WordPress/wp-includes/js/autosave.min.js

1 line
9.8 KiB
JavaScript
Raw Normal View History

function autosave_parse_response(a){var b,c,d=wpAjax.parseAjaxResponse(a,"autosave");return d&&d.responses&&d.responses.length&&(d.responses[0].supplemental&&(c=d.responses[0].supplemental,jQuery.each(c,function(a,b){a.match(/^replace-/)&&jQuery("#"+a.replace("replace-","")).val(b)})),d.errors||((b=parseInt(d.responses[0].id,10))&&autosave_update_slug(b),d.responses[0].data&&jQuery(".autosave-message").text(d.responses[0].data))),d}function autosave_saved(a){blockSave=!1,autosave_parse_response(a),autosave_enable_buttons()}function autosave_saved_new(a){blockSave=!1;var b,c=autosave_parse_response(a);c&&c.responses.length&&!c.errors?(b=parseInt(c.responses[0].id,10),b&&(notSaved=!1,jQuery("#auto_draft").val("0")),autosave_enable_buttons(),autosaveDelayPreview&&(autosaveDelayPreview=!1,doPreview())):autosave_enable_buttons()}function autosave_update_slug(a){"undefined"!=makeSlugeditClickable&&jQuery.isFunction(makeSlugeditClickable)&&!jQuery("#edit-slug-box > *").size()&&jQuery.post(ajaxurl,{action:"sample-permalink",post_id:a,new_title:fullscreen&&fullscreen.settings.visible?jQuery("#wp-fullscreen-title").val():jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(a){if("-1"!==a){var b=jQuery("#edit-slug-box");b.html(a),b.hasClass("hidden")&&b.fadeIn("fast",function(){b.removeClass("hidden")}),makeSlugeditClickable()}})}function autosave_loading(){jQuery(".autosave-message").html(autosaveL10n.savingText)}function autosave_enable_buttons(){jQuery(document).trigger("autosave-enable-buttons"),wp.heartbeat&&wp.heartbeat.hasConnectionError()||setTimeout(function(){var a=jQuery("#submitpost");a.find(":button, :submit").removeAttr("disabled"),a.find(".spinner").hide()},500)}function autosave_disable_buttons(){jQuery(document).trigger("autosave-disable-buttons"),jQuery("#submitpost").find(":button, :submit").prop("disabled",!0),setTimeout(autosave_enable_buttons,5e3)}function delayed_autosave(){setTimeout(function(){blockSave||autosave()},200)}var autosave,autosavePeriodical,fullscreen,doPreview,autosaveLast="",autosaveDelayPreview=!1,notSaved=!0,blockSave=!1,autosaveLockRelease=!0;jQuery(document).ready(function(a){autosaveLast=a("#wp-content-wrap").hasClass("tmce-active")&&"undefined"!=typeof switchEditors?wp.autosave.getCompareString({post_title:a("#title").val()||"",content:switchEditors.pre_wpautop(a("#content").val())||"",excerpt:a("#excerpt").val()||""}):wp.autosave.getCompareString(),autosavePeriodical=a.schedule({time:1e3*autosaveL10n.autosaveInterval,func:function(){autosave()},repeat:!0,protect:!0}),a("#post").submit(function(){a.cancel(autosavePeriodical),autosaveLockRelease=!1}),a('input[type="submit"], a.submitdelete',"#submitpost").click(function(){blockSave=!0,window.onbeforeunload=null,a(":button, :submit","#submitpost").each(function(){var b=a(this);b.hasClass("button-primary")?b.addClass("button-primary-disabled"):b.addClass("button-disabled")}),"publish"==a(this).attr("id")?a("#major-publishing-actions .spinner").show():a("#minor-publishing .spinner").show()}),window.onbeforeunload=function(){var a="undefined"!=typeof tinymce?tinymce.activeEditor:!1;if(a&&!a.isHidden()){if(a.isDirty())return autosaveL10n.saveAlert}else if(wp.autosave.getCompareString()!=autosaveLast)return autosaveL10n.saveAlert},a(window).unload(function(b){autosaveLockRelease&&(b.target&&"#document"!=b.target.nodeName||a.ajax({type:"POST",url:ajaxurl,async:!1,data:{action:"wp-remove-post-lock",_wpnonce:a("#_wpnonce").val(),post_ID:a("#post_ID").val(),active_post_lock:a("#active_post_lock").val()}}))}),a("#post-preview").click(function(){return"1"==a("#auto_draft").val()&&notSaved?(autosaveDelayPreview=!0,autosave(),!1):(doPreview(),!1)}),doPreview=function(){a("input#wp-preview").val("dopreview"),a("form#post").attr("target","wp-preview").submit().attr("target","");var b=navigator.userAgent.toLowerCase();-1!=b.indexOf("safari")&&-1==b.indexOf("chrome")&&a("form#post").attr("action",function(a,b){return b+"?t="+(new Date).getTime()}),a("input#wp-preview").val("")},a("#title").on("keydown.editor-focus",f