]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/autosave.min.js
WordPress 3.9
[autoinstalls/wordpress.git] / wp-includes / js / autosave.min.js
index 492ef044f9580d0535e118a0d36f51e30f7145e6..45d24f9a9bf7a6bf22f907566885567b83787eec 100644 (file)
@@ -1 +1 @@
-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 b,c="undefined"!=typeof tinymce?tinymce.activeEditor:!1;if(c&&!c.isHidden()){if(c.isDirty())return autosaveL10n.saveAlert}else if(b=fullscreen&&fullscreen.settings.visible?wp.autosave.getCompareString({post_title:a("#wp-fullscreen-title").val()||"",content:a("#wp_mce_fullscreen").val()||"",excerpt:a("#excerpt").val()||""}):wp.autosave.getCompareString(),b!=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",function(b){var c;9==b.which&&(b.ctrlKey||b.altKey||b.shiftKey||("undefined"!=typeof tinymce&&(c=tinymce.get("content")),c&&!c.isHidden()?a(this).one("keyup",function(){a("#content_tbl td.mceToolbar > a").focus()}):a("#content").focus(),b.preventDefault()))}),"1"==a("#auto_draft").val()&&a("#title").blur(function(){this.value&&"1"==a("#auto_draft").val()&&delayed_autosave()}),a(document).on("heartbeat-connection-lost.autosave",function(b,c,d){if("timeout"===c||503==d){var e=a("#lost-connection-notice");wp.autosave.local.hasStorage||e.find(".hide-if-no-sessionstorage").hide(),e.show(),autosave_disable_buttons()}}).on("heartbeat-connection-restored.autosave",function(){a("#lost-connection-notice").hide(),autosave_enable_buttons()})}),autosave=function(){var a,b,c=wp.autosave.getPostData();return blockSave=!0,c.autosave?"block"==jQuery("#TB_window").css("display")?!1:(a=wp.autosave.getCompareString(c),a==autosaveLast?!1:(autosaveLast=a,jQuery(document).triggerHandler("wpcountwords",[c.content]),autosave_disable_buttons(),b="1"==c.auto_draft?autosave_saved_new:autosave_saved,jQuery.ajax({data:c,beforeSend:autosave_loading,type:"POST",url:ajaxurl,success:b}),!0)):!1},window.wp=window.wp||{},wp.autosave=wp.autosave||{},function(a){wp.autosave.getPostData=function(){var b,c,d="undefined"!=typeof tinymce?tinymce.activeEditor:null,e=[],f={action:"autosave",autosave:!0,post_id:a("#post_ID").val()||0,autosavenonce:a("#autosavenonce").val()||"",post_type:a("#post_type").val()||"",post_author:a("#post_author").val()||"",excerpt:a("#excerpt").val()||""};if(d&&!d.isHidden()){if(d.plugins.spellchecker&&d.plugins.spellchecker.active)return f.autosave=!1,f;"mce_fullscreen"==d.id&&tinymce.get("content").setContent(d.getContent({format:"raw"}),{format:"raw"}),tinymce.triggerSave()}return"undefined"!=typeof fullscreen&&fullscreen.settings.visible?(f.post_title=a("#wp-fullscreen-title").val()||"",f.content=a("#wp_mce_fullscreen").val()||""):(f.post_title=a("#title").val()||"",f.content=a("#content").val()||""),a('input[id^="in-category-"]:checked').each(function(){e.push(this.value)}),f.catslist=e.join(","),(b=a("#post_name").val())&&(f.post_name=b),(c=a("#parent_id").val())&&(f.parent_id=c),a("#comment_status").prop("checked")&&(f.comment_status="open"),a("#ping_status").prop("checked")&&(f.ping_status="open"),"1"==a("#auto_draft").val()&&(f.auto_draft="1"),f},wp.autosave.getCompareString=function(b){return"object"==typeof b?(b.post_title||"")+"::"+(b.content||"")+"::"+(b.excerpt||""):(a("#title").val()||"")+"::"+(a("#content").val()||"")+"::"+(a("#excerpt").val()||"")},wp.autosave.local={lastSavedData:"",blog_id:0,hasStorage:!1,checkStorage:function(){var a=Math.random(),b=!1;try{sessionStorage.setItem("wp-test",a),b=sessionStorage.getItem("wp-test")==a,sessionStorage.removeItem("wp-test")}catch(c){}return this.hasStorage=b,b},getStorage:function(){var a=!1;return this.hasStorage&&this.blog_id&&(a=sessionStorage.getItem("wp-autosave-"+this.blog_id),a=a?JSON.parse(a):{}),a},setStorage:function(a){var b;return this.hasStorage&&this.blog_id?(b="wp-autosave-"+this.blog_id,sessionStorage.setItem(b,JSON.stringify(a)),null!==sessionStorage.getItem(b)):!1},getData:function(){var b=this.getStorage(),c=a("#post_ID").val();return b&&c?b["post_"+c]||!1:!1},setData:function(b){var c=this.getStorage(),d=a("#post_ID").val();if(!c||!d)return!1;if(b)c["post_"+d]=b;else{if(!c.hasOwnProperty("post_"+d))return!1;delete c["post_"+d]}return this.setStorage(c)},save:function(b){var c,d,e=!1;return b?(c=this.getData()||{},a.extend(c,b),c.autosave=!0):c=wp.autosave.getPostData(),c.autosave?(d=wp.autosave.getCompareString(c),d==this.lastSavedData?!1:(c.save_time=(new Date).getTime(),c.status=a("#post_status").val()||"",e=this.setData(c),e&&(this.lastSavedData=d),e)):!1},init:function(b){var c=this;this.checkStorage()&&(a("#content").length||a("#excerpt").length)&&(b&&a.extend(this,b),this.blog_id||(this.blog_id="undefined"!=typeof window.autosaveL10n?window.autosaveL10n.blog_id:0),a(document).ready(function(){c.run()}))},run:function(){var b=this;this.checkPost(),this.schedule=a.schedule({time:15e3,func:function(){wp.autosave.local.save()},repeat:!0,protect:!0}),a("form#post").on("submit.autosave-local",function(){var c="undefined"!=typeof tinymce&&tinymce.get("content"),d=a("#post_ID").val()||0;c&&!c.isHidden()?c.onSubmit.add(function(){wp.autosave.local.save({post_title:a("#title").val()||"",content:a("#content").val()||"",excerpt:a("#excerpt").val()||""})}):b.save({post_title:a("#title").val()||"",content:a("#content").val()||"",excerpt:a("#excerpt").val()||""}),wpCookies.set("wp-saving-post-"+d,"check")})},compare:function(a,b){function c(a){return a.toString().replace(/[\x20\t\r\n\f]+/g,"")}return c(a||"")==c(b||"")},checkPost:function(){var b,c,d,e,f=this,g=this.getData(),h=a("#post_ID").val()||0,i=wpCookies.get("wp-saving-post-"+h);if(g)return i&&(wpCookies.remove("wp-saving-post-"+h),"saved"==i)?(this.setData(!1),void 0):(a("#has-newer-autosave").length||(b=a("#content").val()||"",c=a("#title").val()||"",d=a("#excerpt").val()||"",a("#wp-content-wrap").hasClass("tmce-active")&&"undefined"!=typeof switchEditors&&(b=switchEditors.pre_wpautop(b)),"check"!=i&&this.compare(b,g.content)&&this.compare(c,g.post_title)&&this.compare(d,g.excerpt)||(this.restore_post_data=g,this.undo_post_data={content:b,post_title:c,excerpt:d},e=a("#local-storage-notice"),a(".wrap h2").first().after(e.addClass("updated").show()),e.on("click",function(b){var c=a(b.target);c.hasClass("restore-backup")?(f.restorePost(f.restore_post_data),c.parent().hide(),a(this).find("p.undo-restore").show()):c.hasClass("undo-restore-backup")&&(f.restorePost(f.undo_post_data),c.parent().hide(),a(this).find("p.local-restore").show()),b.preventDefault()}))),void 0)},restorePost:function(b){var c;return b?(this.lastSavedData=wp.autosave.getCompareString(b),a("#title").val()!=b.post_title&&a("#title").focus().val(b.post_title||""),a("#excerpt").val(b.excerpt||""),c="undefined"!=typeof tinymce&&tinymce.get("content"),c&&!c.isHidden()&&"undefined"!=typeof switchEditors?(c.undoManager.add(),c.setContent(b.content?switchEditors.wpautop(b.content):"")):(a("#content-html").click(),a("#content").val(b.content)),!0):!1}},wp.autosave.local.init()}(jQuery);
\ No newline at end of file
+window.autosave=function(){return!0},function(a,b){function c(){function c(b){var c,d,e,f=(new Date).getTime(),g=[],h="undefined"!=typeof tinymce&&tinymce.get("content");return h&&!h.isHidden()&&f-3e3>j&&(h.save(),j=f),e={post_id:a("#post_ID").val()||0,post_type:a("#post_type").val()||"",post_author:a("#post_author").val()||"",post_title:a("#title").val()||"",content:a("#content").val()||"",excerpt:a("#excerpt").val()||""},"local"===b?e:(a('input[id^="in-category-"]:checked').each(function(){g.push(this.value)}),e.catslist=g.join(","),(c=a("#post_name").val())&&(e.post_name=c),(d=a("#parent_id").val())&&(e.parent_id=d),a("#comment_status").prop("checked")&&(e.comment_status="open"),a("#ping_status").prop("checked")&&(e.ping_status="open"),"1"===a("#auto_draft").val()&&(e.auto_draft="1"),e)}function d(b){return"object"==typeof b?(b.post_title||"")+"::"+(b.content||"")+"::"+(b.excerpt||""):(a("#title").val()||"")+"::"+(a("#content").val()||"")+"::"+(a("#excerpt").val()||"")}function e(){k.trigger("autosave-disable-buttons"),setTimeout(f,5e3)}function f(){k.trigger("autosave-enable-buttons")}function g(){function e(){var a=Math.random().toString(),c=!1;try{b.sessionStorage.setItem("wp-test",a),c=b.sessionStorage.getItem("wp-test")===a,b.sessionStorage.removeItem("wp-test")}catch(d){}return w=c,c}function f(){var a=!1;return w&&u&&(a=sessionStorage.getItem("wp-autosave-"+u),a=a?JSON.parse(a):{}),a}function g(a){var b;return w&&u?(b="wp-autosave-"+u,sessionStorage.setItem(b,JSON.stringify(a)),null!==sessionStorage.getItem(b)):!1}function h(){var a=f();return a&&v?a["post_"+v]||!1:!1}function j(a){var b=f();if(!b||!v)return!1;if(a)b["post_"+v]=a;else{if(!b.hasOwnProperty("post_"+v))return!1;delete b["post_"+v]}return g(b)}function l(){z=!0}function m(){z=!1}function n(b){var e,f,g=!1;return z?!1:(b?(e=h()||{},a.extend(e,b)):e=c("local"),f=d(e),"undefined"==typeof y&&(y=i),f===y?!1:(e.save_time=(new Date).getTime(),e.status=a("#post_status").val()||"",g=j(e),g&&(y=f),g))}function o(){v=a("#post_ID").val()||0,a("#wp-content-wrap").hasClass("tmce-active")?k.on("tinymce-editor-init.autosave",function(){b.setTimeout(function(){q()},1500)}):q(),x=b.setInterval(n,15e3),a("form#post").on("submit.autosave-local",function(){var b="undefined"!=typeof tinymce&&tinymce.get("content"),c=a("#post_ID").val()||0;b&&!b.isHidden()?b.on("submit",function(){n({post_title:a("#title").val()||"",content:a("#content").val()||"",excerpt:a("#excerpt").val()||""})}):n({post_title:a("#title").val()||"",content:a("#content").val()||"",excerpt:a("#excerpt").val()||""}),wpCookies.set("wp-saving-post-"+c,"check")})}function p(a,b){function c(a){return a.toString().replace(/[\x20\t\r\n\f]+/g,"")}return c(a||"")===c(b||"")}function q(){var b,c,d,e,f=h(),g=wpCookies.get("wp-saving-post-"+v);if(f)return g&&(wpCookies.remove("wp-saving-post-"+v),"saved"===g)?void j(!1):void(a("#has-newer-autosave").length||(b=a("#content").val()||"",c=a("#title").val()||"",d=a("#excerpt").val()||"","check"!==g&&p(b,f.content)&&p(c,f.post_title)&&p(d,f.excerpt)||(s=f,t={content:b,post_title:c,excerpt:d},e=a("#local-storage-notice"),a(".wrap h2").first().after(e.addClass("updated").show()),e.on("click.autosave-local",function(b){var c=a(b.target);c.hasClass("restore-backup")?(r(s),c.parent().hide(),a(this).find("p.undo-restore").show()):c.hasClass("undo-restore-backup")&&(r(t),c.parent().hide(),a(this).find("p.local-restore").show()),b.preventDefault()}))))}function r(b){var c;return b?(y=d(b),a("#title").val()!==b.post_title&&a("#title").focus().val(b.post_title||""),a("#excerpt").val(b.excerpt||""),c="undefined"!=typeof tinymce&&tinymce.get("content"),c&&!c.isHidden()&&"undefined"!=typeof switchEditors?(c.undoManager.add(),c.setContent(b.content?switchEditors.wpautop(b.content):"")):(a("#content-html").click(),a("#content").val(b.content)),!0):!1}var s,t,u,v,w,x,y,z=!1;return u="undefined"!=typeof b.autosaveL10n&&b.autosaveL10n.blog_id,e()&&u&&(a("#content").length||a("#excerpt").length)?(k.ready(o),{hasStorage:w,getSavedPostData:h,save:n,suspend:l,resume:m}):void 0}function h(){function g(){q=!0,b.clearTimeout(r),r=b.setTimeout(function(){q=!1},1e4)}function h(){v=!0}function j(){v=!1}function l(b){p(),q=!1,t=s,s="",k.trigger("after-autosave",[b]),f(),b.success&&a("#auto_draft").val("")}function m(){u=0,wp.heartbeat.connectNow()}function n(){return d()!==i}function o(){var f,h;return v||q||!b.autosave()?!1:(new Date).getTime()<u?!1:(f=c(),h=d(f),"undefined"==typeof t&&(t=i),h===t?!1:(s=h,g(),e(),k.trigger("wpcountwords",[f.content]).trigger("before-autosave",[f]),f._wpnonce=a("#_wpnonce").val()||"",f))}function p(){u=(new Date).getTime()+1e3*autosaveL10n.autosaveInterval||6e4}var q,r,s,t,u=0,v=!1;return k.on("heartbeat-send.autosave",function(a,b){var c=o();c&&(b.wp_autosave=c)}).on("heartbeat-tick.autosave",function(a,b){b.wp_autosave&&l(b.wp_autosave)}).on("heartbeat-connection-lost.autosave",function(b,c,d){if("timeout"===c||603===d){var f=a("#lost-connection-notice");wp.autosave.local.hasStorage||f.find(".hide-if-no-sessionstorage").hide(),f.show(),e()}}).on("heartbeat-connection-restored.autosave",function(){a("#lost-connection-notice").hide(),f()}).ready(function(){p()}),{tempBlockSave:g,triggerSave:m,postChanged:n,suspend:h,resume:j}}var i,j=0,k=a(document);return k.on("tinymce-editor-init.autosave",function(a,c){"content"===c.id&&b.setTimeout(function(){c.save(),i=d()},1e3)}).ready(function(){i=d()}),{getPostData:c,getCompareString:d,disableButtons:e,enableButtons:f,local:g(),server:h()}}b.wp=b.wp||{},b.wp.autosave=c()}(jQuery,window);
\ No newline at end of file