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

1 line
5.2 KiB
JavaScript
Raw Permalink Normal View History

window.autosave=function(){return!0},function(i,a){function s(t){var e=(new Date).getTime(),n=[],o=u();return o&&o.isDirty()&&!o.isHidden()&&I<e-3e3&&(o.save(),I=e),e={post_id:i("#post_ID").val()||0,post_type:i("#post_type").val()||"",post_author:i("#post_author").val()||"",post_title:i("#title").val()||"",content:i("#content").val()||"",excerpt:i("#excerpt").val()||""},"local"===t||(i('input[id^="in-category-"]:checked').each(function(){n.push(this.value)}),e.catslist=n.join(","),(t=i("#post_name").val())&&(e.post_name=t),(t=i("#parent_id").val())&&(e.parent_id=t),i("#comment_status").prop("checked")&&(e.comment_status="open"),i("#ping_status").prop("checked")&&(e.ping_status="open"),"1"===i("#auto_draft").val()&&(e.auto_draft="1")),e}function c(t){return"object"==typeof t?(t.post_title||"")+"::"+(t.content||"")+"::"+(t.excerpt||""):(i("#title").val()||"")+"::"+(i("#content").val()||"")+"::"+(i("#excerpt").val()||"")}function r(){T.trigger("autosave-disable-buttons"),setTimeout(n,5e3)}function n(){T.trigger("autosave-enable-buttons")}function u(){return"undefined"!=typeof tinymce&&tinymce.get("content")}function p(){w=!0,a.clearTimeout(e),e=a.setTimeout(function(){w=!1},1e4)}function o(){x=(new Date).getTime()+1e3*autosaveL10n.autosaveInterval||6e4}function l(){var t=!1;return t=k&&b?(t=sessionStorage.getItem("wp-autosave-"+b))?JSON.parse(t):{}:t}function v(){var t=l();return t&&S&&t["post_"+S]||!1}function d(t){var e=l();if(!e||!S)return!1;if(t)e["post_"+S]=t;else{if(!e.hasOwnProperty("post_"+S))return!1;delete e["post_"+S]}return t=e,!(!k||!b)&&(e="wp-autosave-"+b,sessionStorage.setItem(e,JSON.stringify(t)),null!==sessionStorage.getItem(e))}function f(t){var e,n;return!(C||!k)&&(t?(e=v()||{},i.extend(e,t)):e=s("local"),(t=c(e))!==(D=void 0===D?m:D)&&(e.save_time=(new Date).getTime(),e.status=i("#post_status").val()||"",(n=d(e))&&(D=t),n))}function g(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=v(),a=wpCookies.get("wp-saving-post"),s=i("#has-newer-autosave").parent(".notice");if(a===S+"-saved")return wpCookies.remove("wp-saving-post"),void d(!1);o&&(t=i("#content").val()||"",e=i("#title").val()||"",a=i("#excerpt").val()||"",g(t,o.content)&&g(e,o.post_title)&&g(a,o.excerpt)||(n=i("#local-storage-notice").insertAfter(i(".wrap h1, .wrap h2").first()).addClass("notice-warning"),s.length?s.slideUp(150,function(){n.slideDown(150)}):n.slideDown(200),n.find(".restore-backup").on("click.autosave-local",function(){var t,e;(t=o)&&(D=c(t),i("#title").val()!==t.post_title&&i("#title").focus().val(t.post_title||""),i("#excerpt").val(t.excerpt||""),(e=u())&&!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()})):(i("#content-html").click(),i("#content").focus(),document.execCommand("selectAll"),document.execCommand("insertText",!1,t.content||""))),n.fadeTo(250,0,function(){n.slideUp(150)})})))}var m,w,e,_,h,x,y,b,S,k,D,C,I,T;a.wp=a.wp||{},a.wp.autosave=(I=0,(T=i(document)).on("tinymce-editor-init.autosave",function(t,e){"content"===e.id&&a.setTimeout(function(){e.save(),m=c()},1e3)}).ready(function(){m=c()}),{getPostData:s,getCompareString:c,disableButtons:r,enableButtons:n,local:(C=!1,b=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 k=e}()&&b&&(i("#content").length||i("#excerpt").length)&&T.ready(function(){S=i("#post_ID").val()||0,i("#wp-content-wrap").hasClass("tmce-active")?T.on("tinymce-editor-init.autosave",function(){a.setTimeout(function(){t()},1500)}):t(),a.setInterval(f,15e3),i("form#post").on("submit.autosave-local",function(){var t=u(),e=i("#post_ID").val()||0;t&&!t.isHidden()?t.on("submit",function(){f({post_title:i("#title").val()||"",content:i("#content").val()||"",excerpt:i("#excerpt").val()||""})}):f({post_t