Ticket #37025: 37025.1.patch
File 37025.1.patch, 6.4 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. You can use undo and redo in the editor to get the old content back or to return to the restored version.' ); ?> 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 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() ) { … … 310 314 function checkPost() { 311 315 var content, post_title, excerpt, $notice, 312 316 postData = getSavedPostData(), 313 cookie = wpCookies.get( 'wp-saving-post' ); 317 cookie = wpCookies.get( 'wp-saving-post' ), 318 $newerAutosaveNotice = $( '#has-newer-autosave' ).parent( '.notice' ); 314 319 315 320 if ( cookie === post_id + '-saved' ) { 316 321 wpCookies.remove( 'wp-saving-post' ); … … 323 328 return; 324 329 } 325 330 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 331 content = $( '#content' ).val() || ''; 332 332 post_title = $( '#title' ).val() || ''; 333 333 excerpt = $( '#excerpt' ).val() || ''; … … 338 338 return; 339 339 } 340 340 341 restorePostData = postData;342 undoPostData = {343 content: content,344 post_title: post_title,345 excerpt: excerpt346 };347 348 341 $notice = $( '#local-storage-notice' ) 349 342 .insertAfter( $( '.wrap h1, .wrap h2' ).first() ) 350 .addClass( 'notice-warning' ) 351 .show(); 343 .addClass( 'notice-warning' ); 352 344 353 $notice.on( 'click.autosave-local', function( event ) { 354 var $target = $( event.target ); 345 if ( $newerAutosaveNotice.length ) { 346 // If there is a "server" autosave notice, hide it. 347 // The data in the session storage is either the same or newer. 348 $newerAutosaveNotice.slideUp( 150, function() { 349 $notice.slideDown( 150 ); 350 }); 351 } else { 352 $notice.slideDown( 200 ); 353 } 355 354 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(); 355 $notice.find( '.restore-backup' ).on( 'click.autosave-local', function() { 356 restorePost( postData ); 357 $notice.fadeTo( 250, 0, function() { 358 $notice.slideUp( 150 ); 359 }); 369 360 }); 370 361 } 371 362 … … 382 373 } 383 374 384 375 $( '#excerpt' ).val( postData.excerpt || '' ); 385 editor = typeof tinymce !== 'undefined' && tinymce.get('content');376 editor = getEditor(); 386 377 387 378 if ( editor && ! editor.isHidden() && typeof switchEditors !== 'undefined' ) { 379 if ( editor.settings.wpautop && postData.content ) { 380 postData.content = switchEditors.wpautop( postData.content ); 381 } 382 388 383 // Make sure there's an undo level in the editor 389 editor.undoManager.add(); 390 editor.setContent( postData.content ? switchEditors.wpautop( postData.content ) : '' ); 384 editor.undoManager.transact( function() { 385 editor.setContent( postData.content || '' ); 386 editor.nodeChanged(); 387 }); 391 388 } else { 392 389 // Make sure the Text editor is selected 393 390 $( '#content-html' ).click(); 394 $( '#content' ).val( postData.content ); 391 $( '#content' ).focus(); 392 // Using document.execCommand() will let the user undo with Command/Ctrl + Z 393 document.execCommand( 'selectAll' ); 394 document.execCommand( 'insertText', false, postData.content || '' ); 395 395 } 396 396 397 397 return true;