var postData, compareString,
result = false;
- if ( isSuspended ) {
+ if ( isSuspended || ! hasStorage ) {
return false;
}
});
}
- wpCookies.set( 'wp-saving-post-' + post_id, 'check' );
+ wpCookies.set( 'wp-saving-post', post_id + '-check', 24 * 60 * 60 );
});
}
function checkPost() {
var content, post_title, excerpt, $notice,
postData = getSavedPostData(),
- cookie = wpCookies.get( 'wp-saving-post-' + post_id );
+ cookie = wpCookies.get( 'wp-saving-post' );
- if ( ! postData ) {
+ if ( cookie === post_id + '-saved' ) {
+ wpCookies.remove( 'wp-saving-post' );
+ // The post was saved properly, remove old data and bail
+ setData( false );
return;
}
- if ( cookie ) {
- wpCookies.remove( 'wp-saving-post-' + post_id );
-
- if ( cookie === 'saved' ) {
- // The post was saved properly, remove old data and bail
- setData( false );
- return;
- }
+ if ( ! postData ) {
+ return;
}
// There is a newer autosave. Don't show two "restore" notices at the same time.
post_title = $( '#title' ).val() || '';
excerpt = $( '#excerpt' ).val() || '';
- // cookie == 'check' means the post was not saved properly, always show #local-storage-notice
- if ( cookie !== 'check' && compare( content, postData.content ) &&
- compare( post_title, postData.post_title ) && compare( excerpt, postData.excerpt ) ) {
+ if ( compare( content, postData.content ) && compare( post_title, postData.post_title ) &&
+ compare( excerpt, postData.excerpt ) ) {
return;
}
return false;
}
- // Initialize and run checkPost() on loading the script (before TinyMCE init)
blog_id = typeof window.autosaveL10n !== 'undefined' && window.autosaveL10n.blog_id;
- // Check if the browser supports sessionStorage and it's not disabled
- if ( ! checkStorage() ) {
- return;
- }
-
+ // Check if the browser supports sessionStorage and it's not disabled,
+ // then initialize and run checkPost().
// Don't run if the post type supports neither 'editor' (textarea#content) nor 'excerpt'.
- if ( ! blog_id || ( ! $('#content').length && ! $('#excerpt').length ) ) {
- return;
+ if ( checkStorage() && blog_id && ( $('#content').length || $('#excerpt').length ) ) {
+ $document.ready( run );
}
- $document.ready( run );
-
return {
hasStorage: hasStorage,
getSavedPostData: getSavedPostData,