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

2 lines
5.8 KiB
JavaScript

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