-
+ 0D8FC61C9C9C1450534A7512952DABD2319C8C4DD0A4174E3C89AE8A3B6F93CED030E7C25A6E4B690E4ECF845CB4F163B9A3EC4A722999A56317CC76E2929F70
mp-wp/wp-includes/js/autosave.js
(0 . 0)(1 . 209)
99364 var autosaveLast = '';
99365 var autosavePeriodical;
99366 var autosaveOldMessage = '';
99367 var autosaveDelayPreview = false;
99368 var autosaveFirst = true;
99369
99370 jQuery(function($) {
99371 autosaveLast = $('#post #title').val()+$('#post #content').val();
99372 autosavePeriodical = $.schedule({time: autosaveL10n.autosaveInterval * 1000, func: function() { autosave(); }, repeat: true, protect: true});
99373
99374 //Disable autosave after the form has been submitted
99375 $("#post").submit(function() { $.cancel(autosavePeriodical); });
99376 });
99377
99378 function autosave_parse_response(response) {
99379 var res = wpAjax.parseAjaxResponse(response, 'autosave'); // parse the ajax response
99380 var message = '';
99381
99382 if ( res && res.responses && res.responses.length ) {
99383 message = res.responses[0].data; // The saved message or error.
99384 // someone else is editing: disable autosave, set errors
99385 if ( res.responses[0].supplemental ) {
99386 if ( 'disable' == res.responses[0].supplemental['disable_autosave'] ) {
99387 autosave = function() {};
99388 res = { errors: true };
99389 }
99390 jQuery.each(res.responses[0].supplemental, function(selector, value) {
99391 if ( selector.match(/^replace-/) ) {
99392 jQuery('#'+selector.replace('replace-', '')).val(value);
99393 }
99394 });
99395 }
99396
99397 // if no errors: add slug UI
99398 if ( !res.errors ) {
99399 var postID = parseInt( res.responses[0].id );
99400 if ( !isNaN(postID) && postID > 0 ) {
99401 autosave_update_slug(postID);
99402 }
99403 }
99404 }
99405 if ( message ) { jQuery('#autosave').html(message); } // update autosave message
99406 else if ( autosaveOldMessage && res ) { jQuery('#autosave').html( autosaveOldMessage ); }
99407 return res;
99408 }
99409
99410 // called when autosaving pre-existing post
99411 function autosave_saved(response) {
99412 autosave_parse_response(response); // parse the ajax response
99413 autosave_enable_buttons(); // re-enable disabled form buttons
99414 }
99415
99416 // called when autosaving new post
99417 function autosave_saved_new(response) {
99418 var res = autosave_parse_response(response); // parse the ajax response
99419 // if no errors: update post_ID from the temporary value, grab new save-nonce for that new ID
99420 if ( res && res.responses.length && !res.errors ) {
99421 var tempID = jQuery('#post_ID').val();
99422 var postID = parseInt( res.responses[0].id );
99423 autosave_update_post_ID( postID ); // disabled form buttons are re-enabled here
99424 if ( tempID < 0 && postID > 0 ) // update media buttons
99425 jQuery('#media-buttons a').each(function(){
99426 this.href = this.href.replace(tempID, postID);
99427 });
99428 // activate preview
99429 autosaveFirst = false;
99430 if ( autosaveDelayPreview )
99431 jQuery('#post-preview').click();
99432 } else {
99433 autosave_enable_buttons(); // re-enable disabled form buttons
99434 }
99435 }
99436
99437 function autosave_update_post_ID( postID ) {
99438 if ( !isNaN(postID) && postID > 0 ) {
99439 if ( postID == parseInt(jQuery('#post_ID').val()) ) { return; } // no need to do this more than once
99440 jQuery('#post_ID').attr({name: "post_ID"});
99441 jQuery('#post_ID').val(postID);
99442 // We need new nonces
99443 jQuery.post(autosaveL10n.requestFile, {
99444 action: "autosave-generate-nonces",
99445 post_ID: postID,
99446 autosavenonce: jQuery('#autosavenonce').val(),
99447 post_type: jQuery('#post_type').val()
99448 }, function(html) {
99449 jQuery('#_wpnonce').val(html);
99450 autosave_enable_buttons(); // re-enable disabled form buttons
99451 });
99452 jQuery('#hiddenaction').val('editpost');
99453 }
99454 }
99455
99456 function autosave_update_slug(post_id) {
99457 // create slug area only if not already there
99458 if ( jQuery.isFunction(make_slugedit_clickable) && !jQuery('#edit-slug-box > *').size() ) {
99459 jQuery.post(
99460 slugL10n.requestFile,
99461 {
99462 action: 'sample-permalink',
99463 post_id: post_id,
99464 new_title: jQuery('#title').val(),
99465 samplepermalinknonce: jQuery('#samplepermalinknonce').val()
99466 },
99467 function(data) {
99468 jQuery('#edit-slug-box').html(data);
99469 make_slugedit_clickable();
99470 }
99471 );
99472 }
99473 }
99474
99475 function autosave_loading() {
99476 jQuery('#autosave').html(autosaveL10n.savingText);
99477 }
99478
99479 function autosave_enable_buttons() {
99480 jQuery("#submitpost :button:disabled, #submitpost :submit:disabled").attr('disabled', '');
99481 }
99482
99483 function autosave_disable_buttons() {
99484 jQuery("#submitpost :button:enabled, #submitpost :submit:enabled").attr('disabled', 'disabled');
99485 setTimeout(autosave_enable_buttons, 5000); // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions.
99486 }
99487
99488 var autosave = function() {
99489 // (bool) is rich editor enabled and active
99490 var rich = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden();
99491 var post_data = {
99492 action: "autosave",
99493 post_ID: jQuery("#post_ID").val() || 0,
99494 post_title: jQuery("#title").val() || "",
99495 autosavenonce: jQuery('#autosavenonce').val(),
99496 tags_input: jQuery("#tags-input").val() || "",
99497 post_type: jQuery('#post_type').val() || "",
99498 autosave: 1
99499 };
99500
99501 // We always send the ajax request in order to keep the post lock fresh.
99502 // This (bool) tells whether or not to write the post to the DB during the ajax request.
99503 var doAutoSave = true;
99504
99505 // No autosave while thickbox is open (media buttons)
99506 if ( jQuery("#TB_window").css('display') == 'block' )
99507 doAutoSave = false;
99508
99509 /* Gotta do this up here so we can check the length when tinyMCE is in use */
99510 if ( rich ) {
99511 var ed = tinyMCE.activeEditor;
99512 if ( 'mce_fullscreen' == ed.id )
99513 tinyMCE.get('content').setContent(ed.getContent({format : 'raw'}), {format : 'raw'});
99514 tinyMCE.get('content').save();
99515 }
99516
99517 post_data["content"] = jQuery("#content").val();
99518 if ( jQuery('#post_name').val() )
99519 post_data["post_name"] = jQuery('#post_name').val();
99520
99521 // Nothing to save or no change.
99522 if( (post_data["post_title"].length==0 && post_data["content"].length==0) || post_data["post_title"] + post_data["content"] == autosaveLast) {
99523 doAutoSave = false
99524 }
99525
99526 autosave_disable_buttons();
99527
99528 var origStatus = jQuery('#original_post_status').val();
99529
99530 autosaveLast = jQuery("#title").val()+jQuery("#content").val();
99531 goodcats = ([]);
99532 jQuery("[@name='post_category[]']:checked").each( function(i) {
99533 goodcats.push(this.value);
99534 } );
99535 post_data["catslist"] = goodcats.join(",");
99536
99537 if ( jQuery("#comment_status").attr("checked") )
99538 post_data["comment_status"] = 'open';
99539 if ( jQuery("#ping_status").attr("checked") )
99540 post_data["ping_status"] = 'open';
99541 if ( jQuery("#excerpt").size() )
99542 post_data["excerpt"] = jQuery("#excerpt").val();
99543 if ( jQuery("#post_author").size() )
99544 post_data["post_author"] = jQuery("#post_author").val();
99545 post_data["user_ID"] = jQuery("#user-id").val();
99546
99547 // Don't run while the TinyMCE spellcheck is on. Why? Who knows.
99548 if ( rich && tinyMCE.activeEditor.plugins.spellchecker && tinyMCE.activeEditor.plugins.spellchecker.active ) {
99549 doAutoSave = false;
99550 }
99551
99552 if(parseInt(post_data["post_ID"]) < 1) {
99553 post_data["temp_ID"] = post_data["post_ID"];
99554 var successCallback = autosave_saved_new; // new post
99555 } else {
99556 var successCallback = autosave_saved; // pre-existing post
99557 }
99558
99559 if ( !doAutoSave ) {
99560 post_data['autosave'] = 0;
99561 }
99562
99563 autosaveOldMessage = jQuery('#autosave').html();
99564
99565 jQuery.ajax({
99566 data: post_data,
99567 beforeSend: doAutoSave ? autosave_loading : null,
99568 type: "POST",
99569 url: autosaveL10n.requestFile,
99570 success: successCallback
99571 });
99572 }