Local autosave: remove the locally stored data after a post is saved. This prevents false positives when several users edit the same post multiple times. See #23220
git-svn-id: http://core.svn.wordpress.org/trunk@23796 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a279b11cbb
commit
94553917a1
|
@ -423,8 +423,11 @@ wp.autosave.local = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set (save) post data in the storage
|
* Set (save or delete) post data in the storage.
|
||||||
*
|
*
|
||||||
|
* If stored_data evaluates to 'false' the storage key for the current post will be removed
|
||||||
|
*
|
||||||
|
* $param stored_data The post data to store or null/false/empty to delete the key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
setData: function( stored_data ) {
|
setData: function( stored_data ) {
|
||||||
|
@ -433,7 +436,12 @@ wp.autosave.local = {
|
||||||
if ( !stored || !post_id )
|
if ( !stored || !post_id )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
stored[ 'post_' + post_id ] = stored_data;
|
if ( stored_data )
|
||||||
|
stored[ 'post_' + post_id ] = stored_data;
|
||||||
|
else if ( stored.hasOwnProperty( 'post_' + post_id ) )
|
||||||
|
delete stored[ 'post_' + post_id ];
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
return this.setStorage(stored);
|
return this.setStorage(stored);
|
||||||
},
|
},
|
||||||
|
@ -470,8 +478,8 @@ wp.autosave.local = {
|
||||||
result = this.setData( post_data );
|
result = this.setData( post_data );
|
||||||
|
|
||||||
// temp logging
|
// temp logging
|
||||||
if ( this.debug )
|
if ( typeof console != 'undefined' )
|
||||||
console.log( 'saved, post content = %s', post_data.content );
|
console.log( 'Local autosave: saved, post content = %s', post_data.content );
|
||||||
|
|
||||||
if ( result )
|
if ( result )
|
||||||
this.lastsaveddata = post_data.post_title + ': ' + post_data.content;
|
this.lastsaveddata = post_data.post_title + ': ' + post_data.content;
|
||||||
|
@ -566,23 +574,29 @@ wp.autosave.local = {
|
||||||
var self = this, post_data = this.getData(), content, check_data, strip_tags = false, notice,
|
var self = this, post_data = this.getData(), content, check_data, strip_tags = false, notice,
|
||||||
post_id = $('#post_ID').val() || 0, cookie = wpCookies.get( 'wp-saving-post-' + post_id );
|
post_id = $('#post_ID').val() || 0, cookie = wpCookies.get( 'wp-saving-post-' + post_id );
|
||||||
|
|
||||||
|
// temp logging
|
||||||
|
if ( typeof console != 'undefined' )
|
||||||
|
console.log( 'Local autosave: checkPost, cookie = %s, post content = %s', cookie, post_data && post_data.content );
|
||||||
|
|
||||||
if ( ! post_data )
|
if ( ! post_data )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( cookie )
|
if ( cookie ) {
|
||||||
wpCookies.remove( 'wp-saving-post-' + post_id );
|
wpCookies.remove( 'wp-saving-post-' + post_id );
|
||||||
|
|
||||||
|
if ( cookie == 'saved' ) {
|
||||||
|
// The post was saved properly, remove old data and bail
|
||||||
|
this.setData( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// There is a newer autosave. Don't show two "restore" notices at the same time.
|
// There is a newer autosave. Don't show two "restore" notices at the same time.
|
||||||
if ( $('#has-newer-autosave').length )
|
if ( $('#has-newer-autosave').length )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// temp logging
|
// cookie == 'check' means the post was not saved properly, always show #local-storage-notice
|
||||||
if ( typeof console != 'undefined' )
|
if ( cookie != 'check' ) {
|
||||||
console.log( 'checkPost, post content = %s', post_data.content );
|
|
||||||
|
|
||||||
if ( cookie == 'saved' ) {
|
|
||||||
return;
|
|
||||||
} else if ( cookie != 'check' ) {
|
|
||||||
content = $('#content').val();
|
content = $('#content').val();
|
||||||
check_data = $.extend( {}, post_data );
|
check_data = $.extend( {}, post_data );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue