Ticket #37025: 37025.patch
File 37025.patch, 5.6 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/template.php
2003 2003 */ 2004 2004 function _local_storage_notice() { 2005 2005 ?> 2006 <div id="local-storage-notice" class="hidden notice ">2006 <div id="local-storage-notice" class="hidden notice is-dismissible"> 2007 2007 <p class="local-restore"> 2008 <?php _e( 'The backup of this post in your browser is different from the version below.'); ?>2009 < a class="restore-backup" href="#"><?php _e('Restore the backup.'); ?></a>2008 <?php _e( 'The backup of this post in your browser is different from the version below.' ); ?> 2009 <button type="button" class="button restore-backup"><?php _e('Restore the backup'); ?></button> 2010 2010 </p> 2011 <p class="undo-restore hidden"> 2012 <?php _e('Post restored successfully.'); ?> 2013 <a class="undo-restore-backup" href="#"><?php _e('Undo.'); ?></a> 2011 <p class="help"> 2012 <?php _e( 'This will replace the current editor content with the last backup version. Use undo in the editor to revert it.' ); ?> 2014 2013 </p> 2015 2014 </div> 2016 2015 <?php -
src/wp-includes/js/autosave.js
7 7 ( function( $, window ) { 8 8 function autosave() { 9 9 var initialCompareString, 10 lastTriggerSave = 0,11 $document = $(document);10 lastTriggerSave = 0, 11 $document = $(document); 12 12 13 13 /** 14 14 * Returns the data saved in both local and remote autosave … … 19 19 var post_name, parent_id, data, 20 20 time = ( new Date() ).getTime(), 21 21 cats = [], 22 editor = typeof tinymce !== 'undefined' && tinymce.get('content');22 editor = getEditor(); 23 23 24 24 // Don't run editor.save() more often than every 3 sec. 25 25 // It is resource intensive and might slow down typing in long posts on slow devices. 26 if ( editor && ! editor.isHidden() && time - 3000 > lastTriggerSave ) {26 if ( editor && editor.isDirty() && ! editor.isHidden() && time - 3000 > lastTriggerSave ) { 27 27 editor.save(); 28 28 lastTriggerSave = time; 29 29 } … … 88 88 $document.trigger( 'autosave-enable-buttons' ); 89 89 } 90 90 91 function getEditor() { 92 return typeof tinymce !== 'undefined' && tinymce.get('content'); 93 } 94 91 95 // Autosave in localStorage 92 96 function autosaveLocal() { 93 var restorePostData, undoPostData,blog_id, post_id, hasStorage, intervalTimer,97 var restorePostData, blog_id, post_id, hasStorage, intervalTimer, 94 98 lastCompareString, 95 99 isSuspended = false; 96 100 … … 266 270 intervalTimer = window.setInterval( save, 15000 ); 267 271 268 272 $( 'form#post' ).on( 'submit.autosave-local', function() { 269 var editor = typeof tinymce !== 'undefined' && tinymce.get('content'),273 var editor = getEditor(), 270 274 post_id = $('#post_ID').val() || 0; 271 275 272 276 if ( editor && ! editor.isHidden() ) { … … 323 327 return; 324 328 } 325 329 326 // There is a newer autosave. Don't show two "restore" notices at the same time.327 if ( $( '#has-newer-autosave' ).length ) {328 return;329 }330 331 330 content = $( '#content' ).val() || ''; 332 331 post_title = $( '#title' ).val() || ''; 333 332 excerpt = $( '#excerpt' ).val() || ''; … … 339 338 } 340 339 341 340 restorePostData = postData; 342 undoPostData = {343 content: content,344 post_title: post_title,345 excerpt: excerpt346 };347 341 342 // If there is a "server" autosave notice, hide it. 343 // The data in the session storage is fresher. 344 $( '#has-newer-autosave' ).hide(); 345 348 346 $notice = $( '#local-storage-notice' ) 349 347 .insertAfter( $( '.wrap h1, .wrap h2' ).first() ) 350 348 .addClass( 'notice-warning' ) 351 349 .show(); 352 350 353 $notice.on( 'click.autosave-local', function( event ) { 354 var $target = $( event.target ); 355 356 if ( $target.hasClass( 'restore-backup' ) ) { 357 restorePost( restorePostData ); 358 $target.parent().hide(); 359 $(this).find( 'p.undo-restore' ).show(); 360 $notice.removeClass( 'notice-warning' ).addClass( 'notice-success' ); 361 } else if ( $target.hasClass( 'undo-restore-backup' ) ) { 362 restorePost( undoPostData ); 363 $target.parent().hide(); 364 $(this).find( 'p.local-restore' ).show(); 365 $notice.removeClass( 'notice-success' ).addClass( 'notice-warning' ); 366 } 367 368 event.preventDefault(); 351 $notice.find( '.restore-backup' ).on( 'click.autosave-local', function() { 352 restorePost( postData ); 369 353 }); 370 354 } 371 355 … … 382 366 } 383 367 384 368 $( '#excerpt' ).val( postData.excerpt || '' ); 385 editor = typeof tinymce !== 'undefined' && tinymce.get('content');369 editor = getEditor(); 386 370 387 371 if ( editor && ! editor.isHidden() && typeof switchEditors !== 'undefined' ) { 372 if ( editor.settings.wpautop && postData.content ) { 373 postData.content = switchEditors.wpautop( postData.content ); 374 } 375 388 376 // Make sure there's an undo level in the editor 389 editor.undoManager.add(); 390 editor.setContent( postData.content ? switchEditors.wpautop( postData.content ) : '' ); 377 editor.undoManager.transact( function() { 378 editor.setContent( postData.content || '' ); 379 editor.nodeChanged(); 380 }); 391 381 } else { 392 382 // Make sure the Text editor is selected 393 383 $( '#content-html' ).click(); 394 $( '#content' ).val( postData.content ); 384 $( '#content' ).focus(); 385 // Using document.execCommand() will let the user undo with Command/Ctrl + Z 386 document.execCommand( 'selectAll' ); 387 document.execCommand( 'insertText', false, postData.content || '' ); 395 388 } 396 389 397 390 return true;