Changeset 24774
- Timestamp:
- 07/23/2013 03:05:21 AM (11 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/autosave.js
r24749 r24774 8 8 editor.onLoad.add( function() { 9 9 editor.save(); 10 autosaveLast = ( $('#title').val() || '' ) + ( $('#content').val() || '');10 autosaveLast = wp.autosave.getCompareString(); 11 11 }); 12 12 } 13 13 }); 14 14 } else { 15 autosaveLast = ( $('#title').val() || '' ) + ( $('#content').val() || '');15 autosaveLast = wp.autosave.getCompareString(); 16 16 } 17 17 … … 41 41 42 42 window.onbeforeunload = function(){ 43 var mce = typeof(tinymce) != 'undefined' ? tinymce.activeEditor : false, title, content;44 45 if ( mce && !mce.isHidden() ) {46 if ( mce.isDirty() )43 var editor = typeof(tinymce) != 'undefined' ? tinymce.activeEditor : false, compareString; 44 45 if ( editor && ! editor.isHidden() ) { 46 if ( editor.isDirty() ) 47 47 return autosaveL10n.saveAlert; 48 48 } else { 49 49 if ( fullscreen && fullscreen.settings.visible ) { 50 title = $('#wp-fullscreen-title').val() || ''; 51 content = $("#wp_mce_fullscreen").val() || ''; 50 compareString = wp.autosave.getCompareString({ 51 post_title: $('#wp-fullscreen-title').val() || '', 52 content: $('#wp_mce_fullscreen').val() || '', 53 excerpt: $('#excerpt').val() || '' 54 }); 52 55 } else { 53 title = $('#post #title').val() || ''; 54 content = $('#post #content').val() || ''; 55 } 56 57 if ( ( title || content ) && title + content != autosaveLast ) 56 compareString = wp.autosave.getCompareString(); 57 } 58 59 if ( compareString != autosaveLast ) 58 60 return autosaveL10n.saveAlert; 59 61 } … … 247 249 function autosave_enable_buttons() { 248 250 jQuery(document).trigger('autosave-enable-buttons'); 249 if ( ! wp.heartbeat .hasConnectionError() ) {251 if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) { 250 252 // delay that a bit to avoid some rare collisions while the DOM is being updated. 251 253 setTimeout(function(){ … … 274 276 autosave = function() { 275 277 var post_data = wp.autosave.getPostData(), 276 doAutoSave = post_data.autosave,278 compareString, 277 279 successCallback; 278 280 279 281 blockSave = true; 282 283 // post_data.content cannot be retrieved at the moment 284 if ( ! post_data.autosave ) 285 return false; 280 286 281 287 // No autosave while thickbox is open (media buttons) 282 288 if ( jQuery("#TB_window").css('display') == 'block' ) 283 doAutoSave = false; 289 return false; 290 291 compareString = wp.autosave.getCompareString( post_data ); 284 292 285 293 // Nothing to save or no change. 286 if ( ( post_data["post_title"].length == 0 && post_data["content"].length == 0 ) || post_data["post_title"] + post_data["content"] == autosaveLast ) { 287 doAutoSave = false; 288 } 289 290 if ( doAutoSave ) { 291 autosaveLast = post_data["post_title"] + post_data["content"]; 292 jQuery(document).triggerHandler('wpcountwords', [ post_data["content"] ]); 293 } else { 294 if ( compareString == autosaveLast ) 294 295 return false; 295 } 296 297 autosaveLast = compareString; 298 jQuery(document).triggerHandler('wpcountwords', [ post_data["content"] ]); 296 299 297 300 // Disable buttons until we know the save completed. … … 306 309 jQuery.ajax({ 307 310 data: post_data, 308 beforeSend: doAutoSave ? autosave_loading : null,311 beforeSend: autosave_loading, 309 312 type: "POST", 310 313 url: ajaxurl, … … 383 386 384 387 return data; 385 } 388 }; 389 390 // Concatenate title, content and excerpt. Used to track changes when auto-saving. 391 wp.autosave.getCompareString = function( post_data ) { 392 if ( typeof post_data === 'object' ) { 393 return ( post_data.post_title || '' ) + '::' + ( post_data.content || '' ) + '::' + ( post_data.excerpt || '' ); 394 } 395 396 return ( $('#title').val() || '' ) + '::' + ( $('#content').val() || '' ) + '::' + ( $('#excerpt').val() || '' ); 397 }; 386 398 387 399 wp.autosave.local = { 388 400 389 last saveddata: '',401 lastSavedData: '', 390 402 blog_id: 0, 391 ajaxurl: window.ajaxurl || 'wp-admin/admin-ajax.php',392 403 hasStorage: false, 393 404 … … 493 504 */ 494 505 save: function( data ) { 495 var result = false ;506 var result = false, post_data, compareString; 496 507 497 508 if ( ! data ) { … … 503 514 } 504 515 505 // If the content and title did not change since the last save, don't save again506 if ( post_data.post_title + ': ' + post_data.content == this.lastsaveddata)516 // Cannot get the post data at the moment 517 if ( ! post_data.autosave ) 507 518 return false; 508 519 509 // Cannot get the post data at the moment 510 if ( !post_data.autosave ) 520 compareString = wp.autosave.getCompareString( post_data ); 521 522 // If the content, title and excerpt did not change since the last save, don't save again 523 if ( compareString == this.lastSavedData ) 511 524 return false; 512 525 … … 516 529 517 530 if ( result ) 518 this.last saveddata = post_data.post_title + ': ' + post_data.content;531 this.lastSavedData = compareString; 519 532 520 533 return result; … … 525 538 var self = this; 526 539 527 // Check if the browser supports sessionStorage and editor.js is loaded528 if ( ! this.checkStorage() || typeof switchEditors == 'undefined')540 // Check if the browser supports sessionStorage and it's not disabled 541 if ( ! this.checkStorage() ) 529 542 return; 530 543 … … 539 552 this.blog_id = typeof window.autosaveL10n != 'undefined' ? window.autosaveL10n.blog_id : 0; 540 553 541 this.checkPost();542 554 $(document).ready( function(){ self.run(); } ); 543 555 }, … … 545 557 // Run on DOM ready 546 558 run: function() { 547 var self = this, post_data; 548 549 // Set the comparison string 550 if ( !this.lastsaveddata ) { 551 post_data = wp.autosave.getPostData(); 552 553 if ( post_data.content && $('#wp-content-wrap').hasClass('tmce-active') ) 554 this.lastsaveddata = post_data.post_title + ': ' + switchEditors.pre_wpautop( post_data.content ); 555 else 556 this.lastsaveddata = post_data.post_title + ': ' + post_data.content; 557 } 559 var self = this; 560 561 // Check if the local post data is different than the loaded post data. 562 this.checkPost(); 558 563 559 564 // Set the schedule … … 606 611 */ 607 612 checkPost: function() { 608 var self = this, post_data = this.getData(), content, check_data, strip_tags = false, notice,613 var self = this, post_data = this.getData(), content, post_title, excerpt, notice, 609 614 post_id = $('#post_ID').val() || 0, cookie = wpCookies.get( 'wp-saving-post-' + post_id ); 610 615 … … 626 631 return; 627 632 633 content = $('#content').val() || ''; 634 post_title = $('#title').val() || ''; 635 excerpt = $('#excerpt').val() || ''; 636 637 if ( $('#wp-content-wrap').hasClass('tmce-active') && typeof switchEditors != 'undefined' ) 638 content = switchEditors.pre_wpautop( content ); 639 628 640 // cookie == 'check' means the post was not saved properly, always show #local-storage-notice 629 if ( cookie != 'check' ) { 630 content = $('#content').val(); 631 check_data = $.extend( {}, post_data ); 632 633 if ( $('#wp-content-wrap').hasClass('tmce-active') ) 634 content = switchEditors.pre_wpautop( content ); 635 636 if ( this.compare( content, check_data.content ) && this.compare( $('#title').val(), check_data.post_title ) && this.compare( $('#excerpt').val(), check_data.excerpt ) ) 637 return; 641 if ( cookie != 'check' && this.compare( content, post_data.content ) && this.compare( post_title, post_data.post_title ) && this.compare( excerpt, post_data.excerpt ) ) { 642 return; 638 643 } 639 644 640 645 this.restore_post_data = post_data; 641 this.undo_post_data = wp.autosave.getPostData(); 646 this.undo_post_data = { 647 content: content, 648 post_title: post_title, 649 excerpt: excerpt 650 }; 642 651 643 652 notice = $('#local-storage-notice'); … … 667 676 if ( post_data ) { 668 677 // Set the last saved data 669 this.last saveddata = post_data.post_title + ': ' + post_data.content;678 this.lastSavedData = wp.autosave.getCompareString( post_data ); 670 679 671 680 if ( $('#title').val() != post_data.post_title ) … … 675 684 editor = typeof tinymce != 'undefined' && tinymce.get('content'); 676 685 677 if ( editor && ! editor.isHidden() ) {686 if ( editor && ! editor.isHidden() && typeof switchEditors != 'undefined' ) { 678 687 // Make sure there's an undo level in the editor 679 688 editor.undoManager.add(); … … 690 699 return false; 691 700 } 692 } 701 }; 693 702 694 703 wp.autosave.local.init(); -
trunk/wp-includes/script-loader.php
r24755 r24774 104 104 ) ); 105 105 106 $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response' , 'editor'), false, 1 );106 $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), false, 1 ); 107 107 108 108 $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array('jquery'), false, 1 );
Note: See TracChangeset
for help on using the changeset viewer.