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

1 line
5.4 KiB
JavaScript

window.autosave=function(){return!0},function(s,a){function i(t){var e=(new Date).getTime(),n=[],o="undefined"!=typeof tinymce&&tinymce.get("content");return o&&!o.isHidden()&&j<e-3e3&&(o.save(),j=e),e={post_id:s("#post_ID").val()||0,post_type:s("#post_type").val()||"",post_author:s("#post_author").val()||"",post_title:s("#title").val()||"",content:s("#content").val()||"",excerpt:s("#excerpt").val()||""},"local"===t||(s('input[id^="in-category-"]:checked').each(function(){n.push(this.value)}),e.catslist=n.join(","),(t=s("#post_name").val())&&(e.post_name=t),(t=s("#parent_id").val())&&(e.parent_id=t),s("#comment_status").prop("checked")&&(e.comment_status="open"),s("#ping_status").prop("checked")&&(e.ping_status="open"),"1"===s("#auto_draft").val()&&(e.auto_draft="1")),e}function r(t){return"object"==typeof t?(t.post_title||"")+"::"+(t.content||"")+"::"+(t.excerpt||""):(s("#title").val()||"")+"::"+(s("#content").val()||"")+"::"+(s("#excerpt").val()||"")}function c(){B.trigger("autosave-disable-buttons"),setTimeout(n,5e3)}function n(){B.trigger("autosave-enable-buttons")}function u(){m=!0,a.clearTimeout(e),e=a.setTimeout(function(){m=!1},1e4)}function o(){y=(new Date).getTime()+1e3*autosaveL10n.autosaveInterval||6e4}function p(){var t=!1;return t=I&&C?(t=sessionStorage.getItem("wp-autosave-"+C))?JSON.parse(t):{}:t}function l(){var t=p();return t&&k&&t["post_"+k]||!1}function v(t){var e=p();if(!e||!k)return!1;if(t)e["post_"+k]=t;else{if(!e.hasOwnProperty("post_"+k))return!1;delete e["post_"+k]}return t=e,!(!I||!C)&&(e="wp-autosave-"+C,sessionStorage.setItem(e,JSON.stringify(t)),null!==sessionStorage.getItem(e))}function d(t){var e,n;return!(T||!I)&&(t?(e=l()||{},s.extend(e,t)):e=i("local"),(t=r(e))!==(D=void 0===D?w:D)&&(e.save_time=(new Date).getTime(),e.status=s("#post_status").val()||"",(n=v(e))&&(D=t),n))}function f(t,e){function n(t){return t.toString().replace(/[\x20\t\r\n\f]+/g,"")}return n(t||"")===n(e||"")}function t(){var t,e,n,o,a=l();if(wpCookies.get("wp-saving-post")===k+"-saved")return wpCookies.remove("wp-saving-post"),void v(!1);a&&(s("#has-newer-autosave").length||(t=s("#content").val()||"",e=s("#title").val()||"",n=s("#excerpt").val()||"",f(t,a.content)&&f(e,a.post_title)&&f(n,a.excerpt)||(x=a,S={content:t,post_title:e,excerpt:n},(o=s("#local-storage-notice").insertAfter(s(".wrap h1, .wrap h2").first()).addClass("notice-warning").show()).on("click.autosave-local",function(t){var e=s(t.target);e.hasClass("restore-backup")?(g(x),e.parent().hide(),s(this).find("p.undo-restore").show(),o.removeClass("notice-warning").addClass("notice-success")):e.hasClass("undo-restore-backup")&&(g(S),e.parent().hide(),s(this).find("p.local-restore").show(),o.removeClass("notice-success").addClass("notice-warning")),t.preventDefault()}))))}function g(t){var e;return t&&(D=r(t),s("#title").val()!==t.post_title&&s("#title").focus().val(t.post_title||""),s("#excerpt").val(t.excerpt||""),(e="undefined"!=typeof tinymce&&tinymce.get("content"))&&!e.isHidden()&&"undefined"!=typeof switchEditors?(e.undoManager.add(),e.setContent(t.content?switchEditors.wpautop(t.content):"")):(s("#content-html").click(),s("#content").val(t.content)),1)}var w,m,e,h,_,y,b,x,S,C,k,I,D,T,j,B;a.wp=a.wp||{},a.wp.autosave=(j=0,(B=s(document)).on("tinymce-editor-init.autosave",function(t,e){"content"===e.id&&a.setTimeout(function(){e.save(),w=r()},1e3)}).ready(function(){w=r()}),{getPostData:i,getCompareString:r,disableButtons:c,enableButtons:n,local:(T=!1,C=void 0!==a.autosaveL10n&&a.autosaveL10n.blog_id,function(){var t=Math.random().toString(),e=!1;try{a.sessionStorage.setItem("wp-test",t),e=a.sessionStorage.getItem("wp-test")===t,a.sessionStorage.removeItem("wp-test")}catch(t){}return I=e}()&&C&&(s("#content").length||s("#excerpt").length)&&B.ready(function(){k=s("#post_ID").val()||0,s("#wp-content-wrap").hasClass("tmce-active")?B.on("tinymce-editor-init.autosave",function(){a.setTimeout(function(){t()},1500)}):t(),a.setInterval(d,15e3),s("form#post").on("submit.autosave-local",function(){var t="undefined"!=typeof tinymce&&tinymce.get("content"),e=s("#post_ID").val()||0;t&&!t.isHidden()?t.on("submit",function(){d({post_title:s("#title").val()||"",content:s("#content").val()||"",excerpt:s("#excerpt").val()||""})}):d({post_title:s("#title").val()||"",content:s("#content").val()||"",excerpt:s("#excerpt").val()||""});t="https:"===a.location.protocol;wpCookies.set("wp-saving-post",e+"-check",86400,!1,!1,t)})}),{hasStorage:I,getSavedPostData:l,save:d,suspend:function(){T=!0},resume:function(){T=!1}}),server:(y=0,b=!1,B.on("heartbeat-send.autosave",function(t,e){var n,o,n=!(b||m||!a.autosave())&&(!((new Date).getTime()<y)&&((o=r(n=i()))!==(_=void 0===_?w:_)&&(h=o,u(),c(),B.trigger("wpcountwords",[n.content]).trigger("before-autosave",[n]),n._wpnonce=s("#_wpnonce").val()||"",n)));n&&(e.wp_autosave=n)}).on("heartbeat-tick.autosave",function(t,e){e.wp_autosave&&(e=e.wp_autosave,o(),m=!1,_=h,h="",B.trigger("after-autosave",[e]),n(),e.success&&s("#auto_draft").val(""))}).on("heartbeat-connection-lost.autosave",function(t,e,n){"timeout"!==e&&603!==n||(n=s("#lost-connection-notice"),wp.autosave.local.hasStorage||n.find(".hide-if-no-sessionstorage").hide(),n.show(),c())}).on("heartbeat-connection-restored.autosave",function(){s("#lost-connection-notice").hide(),n()}).ready(function(){o()}),{tempBlockSave:u,triggerSave:function(){y=0,wp.heartbeat.connectNow()},postChanged:function(){return r()!==w},suspend:function(){b=!0},resume:function(){b=!1}})})}(jQuery,window);