]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/autosave.min.js
Wordpress 3.6
[autoinstalls/wordpress.git] / wp-includes / js / autosave.min.js
index 864401f630710a93dd29063366a7313bedf5ab75..96a5bc6e36cd0f92d1a55c248ad5ca91250ea71e 100644 (file)
@@ -1 +1 @@
-var autosave,autosaveLast="",autosavePeriodical,autosaveOldMessage="",autosaveDelayPreview=false,notSaved=true,blockSave=false,fullscreen,autosaveLockRelease=true;jQuery(document).ready(function(a){autosaveLast=(a("#post #title").val()||"")+(a("#post #content").val()||"");autosavePeriodical=a.schedule({time:autosaveL10n.autosaveInterval*1000,func:function(){autosave()},repeat:true,protect:true});a("#post").submit(function(){a.cancel(autosavePeriodical);autosaveLockRelease=false});a('input[type="submit"], a.submitdelete',"#submitpost").click(function(){blockSave=true;window.onbeforeunload=null;a(":button, :submit","#submitpost").each(function(){var b=a(this);if(b.hasClass("button-primary")){b.addClass("button-primary-disabled")}else{b.addClass("button-disabled")}});if(a(this).attr("id")=="publish"){a("#major-publishing-actions .spinner").show()}else{a("#minor-publishing .spinner").show()}});window.onbeforeunload=function(){var b=typeof(tinymce)!="undefined"?tinymce.activeEditor:false,d,c;if(b&&!b.isHidden()){if(b.isDirty()){return autosaveL10n.saveAlert}}else{if(fullscreen&&fullscreen.settings.visible){d=a("#wp-fullscreen-title").val()||"";c=a("#wp_mce_fullscreen").val()||""}else{d=a("#post #title").val()||"";c=a("#post #content").val()||""}if((d||c)&&d+c!=autosaveLast){return autosaveL10n.saveAlert}}};a(window).unload(function(b){if(!autosaveLockRelease){return}if(b.target&&b.target.nodeName!="#document"){return}a.ajax({type:"POST",url:ajaxurl,async:false,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(){if(a("#auto_draft").val()=="1"&&notSaved){autosaveDelayPreview=true;autosave();return false}doPreview();return false});doPreview=function(){a("input#wp-preview").val("dopreview");a("form#post").attr("target","wp-preview").submit().attr("target","");if(a.browser.safari){a("form#post").attr("action",function(b,c){return c+"?t="+new Date().getTime()})}a("input#wp-preview").val("")};a("#title").on("keydown.editor-focus",function(c){var b;if(c.which!=9){return}if(!c.ctrlKey&&!c.altKey&&!c.shiftKey){if(typeof(tinymce)!="undefined"){b=tinymce.get("content")}if(b&&!b.isHidden()){a(this).one("keyup",function(d){a("#content_tbl td.mceToolbar > a").focus()})}else{a("#content").focus()}c.preventDefault()}});if("1"==a("#auto_draft").val()){a("#title").blur(function(){if(!this.value||a("#auto_draft").val()!="1"){return}delayed_autosave()})}});function autosave_parse_response(c){var d=wpAjax.parseAjaxResponse(c,"autosave"),e="",a,b;if(d&&d.responses&&d.responses.length){e=d.responses[0].data;if(d.responses[0].supplemental){b=d.responses[0].supplemental;if("disable"==b.disable_autosave){autosave=function(){};autosaveLockRelease=false;d={errors:true}}if(b["active-post-lock"]){jQuery("#active_post_lock").val(b["active-post-lock"])}if(b.alert){jQuery("#autosave-alert").remove();jQuery("#titlediv").after('<div id="autosave-alert" class="error below-h2"><p>'+b.alert+"</p></div>")}jQuery.each(b,function(f,g){if(f.match(/^replace-/)){jQuery("#"+f.replace("replace-","")).val(g)}})}if(!d.errors){a=parseInt(d.responses[0].id,10);if(!isNaN(a)&&a>0){autosave_update_slug(a)}}}if(e){jQuery(".autosave-message").html(e)}else{if(autosaveOldMessage&&d){jQuery(".autosave-message").html(autosaveOldMessage)}}return d}function autosave_saved(a){blockSave=false;autosave_parse_response(a);autosave_enable_buttons()}function autosave_saved_new(b){blockSave=false;var c=autosave_parse_response(b),a;if(c&&c.responses.length&&!c.errors){a=parseInt(c.responses[0].id,10);if(!isNaN(a)&&a>0){notSaved=false;jQuery("#auto_draft").val("0")}autosave_enable_buttons();if(autosaveDelayPreview){autosaveDelayPreview=false;doPreview()}}else{autosave_enable_buttons()}}function autosave_update_slug(a){if("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(b){if(b!=="-1"){jQuery("#edit-slug-box").html(b);makeSlugeditClickable()}})}}function autosave_loading(){jQuery(".autosave-message").html(autosaveL10n.savingText)}function autosave_enable_buttons(){setTimeout(function(){jQuery(":button, :submit","#submitpost").removeAttr("disabled");jQuery(".spinner","#submitpost").hide()},500)}function autosave_disable_buttons(){jQuery(":button, :submit","#submitpost").prop("disabled",true);setTimeout(autosave_enable_buttons,5000)}function delayed_autosave(){setTimeout(function(){if(blockSave){return}autosave()},200)}autosave=function(){blockSave=true;var c=(typeof tinymce!="undefined")&&tinymce.activeEditor&&!tinymce.activeEditor.isHidden(),d,f,b,e,a;autosave_disable_buttons();d={action:"autosave",post_ID:jQuery("#post_ID").val()||0,autosavenonce:jQuery("#autosavenonce").val(),post_type:jQuery("#post_type").val()||"",autosave:1};jQuery(".tags-input").each(function(){d[this.name]=this.value});f=true;if(jQuery("#TB_window").css("display")=="block"){f=false}if(c&&f){b=tinymce.activeEditor;if(b.plugins.spellchecker&&b.plugins.spellchecker.active){f=false}else{if("mce_fullscreen"==b.id||"wp_mce_fullscreen"==b.id){tinymce.get("content").setContent(b.getContent({format:"raw"}),{format:"raw"})}tinymce.triggerSave()}}if(fullscreen&&fullscreen.settings.visible){d.post_title=jQuery("#wp-fullscreen-title").val()||"";d.content=jQuery("#wp_mce_fullscreen").val()||""}else{d.post_title=jQuery("#title").val()||"";d.content=jQuery("#content").val()||""}if(jQuery("#post_name").val()){d.post_name=jQuery("#post_name").val()}if((d.post_title.length==0&&d.content.length==0)||d.post_title+d.content==autosaveLast){f=false}e=jQuery("#original_post_status").val();goodcats=([]);jQuery("[name='post_category[]']:checked").each(function(g){goodcats.push(this.value)});d.catslist=goodcats.join(",");if(jQuery("#comment_status").prop("checked")){d.comment_status="open"}if(jQuery("#ping_status").prop("checked")){d.ping_status="open"}if(jQuery("#excerpt").size()){d.excerpt=jQuery("#excerpt").val()}if(jQuery("#post_author").size()){d.post_author=jQuery("#post_author").val()}if(jQuery("#parent_id").val()){d.parent_id=jQuery("#parent_id").val()}d.user_ID=jQuery("#user-id").val();if(jQuery("#auto_draft").val()=="1"){d.auto_draft="1"}if(f){autosaveLast=d.post_title+d.content;jQuery(document).triggerHandler("wpcountwords",[d.content])}else{d.autosave=0}if(d.auto_draft=="1"){a=autosave_saved_new}else{a=autosave_saved}autosaveOldMessage=jQuery("#autosave").html();jQuery.ajax({data:d,beforeSend:f?autosave_loading:null,type:"POST",url:ajaxurl,success:a})};
\ No newline at end of file
+var autosave,autosaveLast="",autosavePeriodical,autosaveDelayPreview=false,notSaved=true,blockSave=false,fullscreen,autosaveLockRelease=true;jQuery(document).ready(function(a){if(a("#wp-content-wrap").hasClass("tmce-active")&&typeof switchEditors!="undefined"){autosaveLast=wp.autosave.getCompareString({post_title:a("#title").val()||"",content:switchEditors.pre_wpautop(a("#content").val())||"",excerpt:a("#excerpt").val()||""})}else{autosaveLast=wp.autosave.getCompareString()}autosavePeriodical=a.schedule({time:autosaveL10n.autosaveInterval*1000,func:function(){autosave()},repeat:true,protect:true});a("#post").submit(function(){a.cancel(autosavePeriodical);autosaveLockRelease=false});a('input[type="submit"], a.submitdelete',"#submitpost").click(function(){blockSave=true;window.onbeforeunload=null;a(":button, :submit","#submitpost").each(function(){var b=a(this);if(b.hasClass("button-primary")){b.addClass("button-primary-disabled")}else{b.addClass("button-disabled")}});if(a(this).attr("id")=="publish"){a("#major-publishing-actions .spinner").show()}else{a("#minor-publishing .spinner").show()}});window.onbeforeunload=function(){var b=typeof(tinymce)!="undefined"?tinymce.activeEditor:false,c;if(b&&!b.isHidden()){if(b.isDirty()){return autosaveL10n.saveAlert}}else{if(fullscreen&&fullscreen.settings.visible){c=wp.autosave.getCompareString({post_title:a("#wp-fullscreen-title").val()||"",content:a("#wp_mce_fullscreen").val()||"",excerpt:a("#excerpt").val()||""})}else{c=wp.autosave.getCompareString()}if(c!=autosaveLast){return autosaveL10n.saveAlert}}};a(window).unload(function(b){if(!autosaveLockRelease){return}if(b.target&&b.target.nodeName!="#document"){return}a.ajax({type:"POST",url:ajaxurl,async:false,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(){if(a("#auto_draft").val()=="1"&&notSaved){autosaveDelayPreview=true;autosave();return false}doPreview();return false});doPreview=function(){a("input#wp-preview").val("dopreview");a("form#post").attr("target","wp-preview").submit().attr("target","");var b=navigator.userAgent.toLowerCase();if(b.indexOf("safari")!=-1&&b.indexOf("chrome")==-1){a("form#post").attr("action",function(c,d){return d+"?t="+new Date().getTime()})}a("input#wp-preview").val("")};a("#title").on("keydown.editor-focus",function(c){var b;if(c.which!=9){return}if(!c.ctrlKey&&!c.altKey&&!c.shiftKey){if(typeof(tinymce)!="undefined"){b=tinymce.get("content")}if(b&&!b.isHidden()){a(this).one("keyup",function(d){a("#content_tbl td.mceToolbar > a").focus()})}else{a("#content").focus()}c.preventDefault()}});if("1"==a("#auto_draft").val()){a("#title").blur(function(){if(!this.value||a("#auto_draft").val()!="1"){return}delayed_autosave()})}a(document).on("heartbeat-connection-lost.autosave",function(d,b){if("timeout"===b){var c=a("#lost-connection-notice");if(!wp.autosave.local.hasStorage){c.find(".hide-if-no-sessionstorage").hide()}c.show();autosave_disable_buttons()}}).on("heartbeat-connection-restored.autosave",function(){a("#lost-connection-notice").hide();autosave_enable_buttons()})});function autosave_parse_response(b){var d=wpAjax.parseAjaxResponse(b,"autosave"),c,a;if(d&&d.responses&&d.responses.length){if(d.responses[0].supplemental){a=d.responses[0].supplemental;jQuery.each(a,function(e,f){if(e.match(/^replace-/)){jQuery("#"+e.replace("replace-","")).val(f)}})}if(!d.errors){if(c=parseInt(d.responses[0].id,10)){autosave_update_slug(c)}if(d.responses[0].data){jQuery(".autosave-message").text(d.responses[0].data)}}}return d}function autosave_saved(a){blockSave=false;autosave_parse_response(a);autosave_enable_buttons()}function autosave_saved_new(a){blockSave=false;var c=autosave_parse_response(a),b;if(c&&c.responses.length&&!c.errors){b=parseInt(c.responses[0].id,10);if(b){notSaved=false;jQuery("#auto_draft").val("0")}autosave_enable_buttons();if(autosaveDelayPreview){autosaveDelayPreview=false;doPreview()}}else{autosave_enable_buttons()}}function autosave_update_slug(a){if("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(c){if(c!=="-1"){var b=jQuery("#edit-slug-box");b.html(c);if(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");if(!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",true);setTimeout(autosave_enable_buttons,5000)}function delayed_autosave(){setTimeout(function(){if(blockSave){return}autosave()},200)}autosave=function(){var c=wp.autosave.getPostData(),b,a;blockSave=true;if(!c.autosave){return false}if(jQuery("#TB_window").css("display")=="block"){return false}b=wp.autosave.getCompareString(c);if(b==autosaveLast){return false}autosaveLast=b;jQuery(document).triggerHandler("wpcountwords",[c.content]);autosave_disable_buttons();if(c.auto_draft=="1"){a=autosave_saved_new}else{a=autosave_saved}jQuery.ajax({data:c,beforeSend:autosave_loading,type:"POST",url:ajaxurl,success:a});return true};window.wp=window.wp||{};wp.autosave=wp.autosave||{};(function(a){wp.autosave.getPostData=function(){var b=typeof tinymce!="undefined"?tinymce.activeEditor:null,d,f,c=[],e={action:"autosave",autosave:true,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(b&&!b.isHidden()){if(b.plugins.spellchecker&&b.plugins.spellchecker.active){e.autosave=false;return e}else{if("mce_fullscreen"==b.id){tinymce.get("content").setContent(b.getContent({format:"raw"}),{format:"raw"})}tinymce.triggerSave()}}if(typeof fullscreen!="undefined"&&fullscreen.settings.visible){e.post_title=a("#wp-fullscreen-title").val()||"";e.content=a("#wp_mce_fullscreen").val()||""}else{e.post_title=a("#title").val()||"";e.content=a("#content").val()||""}a('input[id^="in-category-"]:checked').each(function(){c.push(this.value)});e.catslist=c.join(",");if(d=a("#post_name").val()){e.post_name=d}if(f=a("#parent_id").val()){e.parent_id=f}if(a("#comment_status").prop("checked")){e.comment_status="open"}if(a("#ping_status").prop("checked")){e.ping_status="open"}if(a("#auto_draft").val()=="1"){e.auto_draft="1"}return e};wp.autosave.getCompareString=function(b){if(typeof b==="object"){return(b.post_title||"")+"::"+(b.content||"")+"::"+(b.excerpt||"")}return(a("#title").val()||"")+"::"+(a("#content").val()||"")+"::"+(a("#excerpt").val()||"")};wp.autosave.local={lastSavedData:"",blog_id:0,hasStorage:false,checkStorage:function(){var d=Math.random(),b=false;try{sessionStorage.setItem("wp-test",d);b=sessionStorage.getItem("wp-test")==d;sessionStorage.removeItem("wp-test")}catch(c){}this.hasStorage=b;return b},getStorage:function(){var b=false;if(this.hasStorage&&this.blog_id){b=sessionStorage.getItem("wp-autosave-"+this.blog_id);if(b){b=JSON.parse(b)}else{b={}}}return b},setStorage:function(b){var c;if(this.hasStorage&&this.blog_id){c="wp-autosave-"+this.blog_id;sessionStorage.setItem(c,JSON.stringify(b));return sessionStorage.getItem(c)!==null}return false},getData:function(){var c=this.getStorage(),b=a("#post_ID").val();if(!c||!b){return false}return c["post_"+b]||false},setData:function(b){var d=this.getStorage(),c=a("#post_ID").val();if(!d||!c){return false}if(b){d["post_"+c]=b}else{if(d.hasOwnProperty("post_"+c)){delete d["post_"+c]}else{return false}}return this.setStorage(d)},save:function(d){var b=false,e,c;if(!d){e=wp.autosave.getPostData()}else{e=this.getData()||{};a.extend(e,d);e.autosave=true}if(!e.autosave){return false}c=wp.autosave.getCompareString(e);if(c==this.lastSavedData){return false}e.save_time=(new Date()).getTime();e.status=a("#post_status").val()||"";b=this.setData(e);if(b){this.lastSavedData=c}return b},init:function(c){var b=this;if(!this.checkStorage()){return}if(!a("#content").length&&!a("#excerpt").length){return}if(c){a.extend(this,c)}if(!this.blog_id){this.blog_id=typeof window.autosaveL10n!="undefined"?window.autosaveL10n.blog_id:0}a(document).ready(function(){b.run()})},run:function(){var b=this;this.checkPost();this.schedule=a.schedule({time:15*1000,func:function(){wp.autosave.local.save()},repeat:true,protect:true});a("form#post").on("submit.autosave-local",function(){var d=typeof tinymce!="undefined"&&tinymce.get("content"),c=a("#post_ID").val()||0;if(d&&!d.isHidden()){d.onSubmit.add(function(){wp.autosave.local.save({post_title:a("#title").val()||"",content:a("#content").val()||"",excerpt:a("#excerpt").val()||""})})}else{b.save({post_title:a("#title").val()||"",content:a("#content").val()||"",excerpt:a("#excerpt").val()||""})}wpCookies.set("wp-saving-post-"+c,"check")})},compare:function(d,c){function b(e){return e.toString().replace(/[\x20\t\r\n\f]+/g,"")}return(b(d||"")==b(c||""))},checkPost:function(){var c=this,i=this.getData(),g,f,b,h,d=a("#post_ID").val()||0,e=wpCookies.get("wp-saving-post-"+d);if(!i){return}if(e){wpCookies.remove("wp-saving-post-"+d);if(e=="saved"){this.setData(false);return}}if(a("#has-newer-autosave").length){return}g=a("#content").val()||"";f=a("#title").val()||"";b=a("#excerpt").val()||"";if(a("#wp-content-wrap").hasClass("tmce-active")&&typeof switchEditors!="undefined"){g=switchEditors.pre_wpautop(g)}if(e!="check"&&this.compare(g,i.content)&&this.compare(f,i.post_title)&&this.compare(b,i.excerpt)){return}this.restore_post_data=i;this.undo_post_data={content:g,post_title:f,excerpt:b};h=a("#local-storage-notice");a(".wrap h2").first().after(h.addClass("updated").show());h.on("click",function(k){var j=a(k.target);if(j.hasClass("restore-backup")){c.restorePost(c.restore_post_data);j.parent().hide();a(this).find("p.undo-restore").show()}else{if(j.hasClass("undo-restore-backup")){c.restorePost(c.undo_post_data);j.parent().hide();a(this).find("p.local-restore").show()}}k.preventDefault()})},restorePost:function(c){var b;if(c){this.lastSavedData=wp.autosave.getCompareString(c);if(a("#title").val()!=c.post_title){a("#title").focus().val(c.post_title||"")}a("#excerpt").val(c.excerpt||"");b=typeof tinymce!="undefined"&&tinymce.get("content");if(b&&!b.isHidden()&&typeof switchEditors!="undefined"){b.undoManager.add();b.setContent(c.content?switchEditors.wpautop(c.content):"")}else{a("#content-html").click();a("#content").val(c.content)}return true}return false}};wp.autosave.local.init()}(jQuery));
\ No newline at end of file