Ticket #24756: 24756-6.patch
File 24756-6.patch, 6.3 KB (added by , 11 years ago) |
---|
-
wp-includes/js/autosave.js
246 246 247 247 function autosave_enable_buttons() { 248 248 jQuery(document).trigger('autosave-enable-buttons'); 249 if ( ! wp.heartbeat .hasConnectionError() ) {249 if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) { 250 250 // delay that a bit to avoid some rare collisions while the DOM is being updated. 251 251 setTimeout(function(){ 252 252 var parent = jQuery('#submitpost'); … … 388 388 389 389 lastsaveddata: '', 390 390 blog_id: 0, 391 ajaxurl: window.ajaxurl || 'wp-admin/admin-ajax.php',392 391 hasStorage: false, 393 392 394 393 // Check if the browser supports sessionStorage and it's not disabled … … 492 491 * @return bool 493 492 */ 494 493 save: function( data ) { 495 var result = false ;494 var result = false, post_data; 496 495 497 496 if ( ! data ) { 498 497 post_data = wp.autosave.getPostData(); … … 502 501 post_data.autosave = true; 503 502 } 504 503 505 // If the content and titledid not change since the last save, don't save again506 if ( post_data.post_title + ': ' + post_data.content== this.lastsaveddata )504 // If the content, title and excerpt did not change since the last save, don't save again 505 if ( ( post_data.post_title || '' ) + ( post_data.content || '' ) + ( post_data.excerpt || '' ) == this.lastsaveddata ) 507 506 return false; 508 507 509 508 // Cannot get the post data at the moment … … 515 514 result = this.setData( post_data ); 516 515 517 516 if ( result ) 518 this.lastsaveddata = post_data.post_title + ': ' + post_data.content;517 this.lastsaveddata = ( post_data.post_title || '' ) + ( post_data.content || '' ) + ( post_data.excerpt || '' ); 519 518 520 519 return result; 521 520 }, … … 524 523 init: function( settings ) { 525 524 var self = this; 526 525 527 // Check if the browser supports sessionStorage and editor.js is loaded528 if ( ! this.checkStorage() || typeof switchEditors == 'undefined')526 // Check if the browser supports sessionStorage and it's not disabled 527 if ( ! this.checkStorage() ) 529 528 return; 530 529 531 530 // Don't run if the post type supports neither 'editor' (textarea#content) nor 'excerpt'. … … 538 537 if ( !this.blog_id ) 539 538 this.blog_id = typeof window.autosaveL10n != 'undefined' ? window.autosaveL10n.blog_id : 0; 540 539 541 this.checkPost();542 540 $(document).ready( function(){ self.run(); } ); 543 541 }, 544 542 545 543 // Run on DOM ready 546 544 run: function() { 547 var self = this , post_data;545 var self = this; 548 546 549 // Set the comparison string 550 if ( !this.lastsaveddata ) { 551 post_data = wp.autosave.getPostData(); 547 // Check if the local post data is different than the loaded post data. 548 this.checkPost(); 552 549 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 else556 this.lastsaveddata = post_data.post_title + ': ' + post_data.content;557 }558 559 550 // Set the schedule 560 551 this.schedule = $.schedule({ 561 552 time: 15 * 1000, … … 605 596 * @return void 606 597 */ 607 598 checkPost: function() { 608 var self = this, post_data = this.getData(), content, check_data, strip_tags = false, notice,599 var self = this, post_data = this.getData(), content, post_title, excerpt, notice, 609 600 post_id = $('#post_ID').val() || 0, cookie = wpCookies.get( 'wp-saving-post-' + post_id ); 610 601 611 602 if ( ! post_data ) … … 625 616 if ( $('#has-newer-autosave').length ) 626 617 return; 627 618 628 // 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 ); 619 content = $('#content').val() || ''; 620 post_title = $('#title').val() || ''; 621 excerpt = $('#excerpt').val() || ''; 632 622 633 if ( $('#wp-content-wrap').hasClass('tmce-active'))634 623 if ( $('#wp-content-wrap').hasClass('tmce-active') && typeof switchEditors != 'undefined' ) 624 content = switchEditors.pre_wpautop( content ); 635 625 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; 626 // cookie == 'check' means the post was not saved properly, always show #local-storage-notice 627 if ( cookie != 'check' && this.compare( content, post_data.content ) && this.compare( title, post_data.post_title ) && this.compare( excerpt, post_data.excerpt ) ) { 628 return; 638 629 } 639 630 640 631 this.restore_post_data = post_data; 641 this.undo_post_data = wp.autosave.getPostData(); 632 this.undo_post_data = { 633 content: content, 634 post_title: post_title, 635 excerpt: excerpt 636 }; 642 637 643 638 notice = $('#local-storage-notice'); 644 639 $('.wrap h2').first().after( notice.addClass('updated').show() ); … … 666 661 667 662 if ( post_data ) { 668 663 // Set the last saved data 669 this.lastsaveddata = post_data.post_title + ': ' + post_data.content;664 this.lastsaveddata = ( post_data.post_title || '' ) + ( post_data.content || '' ) + ( post_data.excerpt || '' ); 670 665 671 666 if ( $('#title').val() != post_data.post_title ) 672 667 $('#title').focus().val( post_data.post_title || '' ); … … 674 669 $('#excerpt').val( post_data.excerpt || '' ); 675 670 editor = typeof tinymce != 'undefined' && tinymce.get('content'); 676 671 677 if ( editor && ! editor.isHidden() ) {672 if ( editor && ! editor.isHidden() && typeof switchEditors != 'undefined' ) { 678 673 // Make sure there's an undo level in the editor 679 674 editor.undoManager.add(); 680 675 editor.setContent( post_data.content ? switchEditors.wpautop( post_data.content ) : '' ); -
wp-includes/script-loader.php
103 103 'dismiss' => __('Dismiss'), 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 ); 109 109 did_action( 'init' ) && $scripts->localize( 'heartbeat', 'heartbeatSettings',