Autosave: don't create the temporary permalink if the title field had focus (the user was typing a title) at the time of the last autosave. Fixes #27503

git-svn-id: https://develop.svn.wordpress.org/trunk@27728 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2014-03-25 22:21:24 +00:00
parent 8c47b1e188
commit f2c1fcbb65

View File

@ -19,6 +19,7 @@ function array_unique_noempty(a) {
} }
( function($) { ( function($) {
var titleHasFocus = false;
tagBox = { tagBox = {
clean : function(tags) { clean : function(tags) {
@ -309,9 +310,12 @@ $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
$('#active_post_lock').val( received.new_lock ); $('#active_post_lock').val( received.new_lock );
} }
} }
}).on( 'before-autosave.update-post-slug', function() {
titleHasFocus = document.activeElement && document.activeElement.id === 'title';
}).on( 'after-autosave.update-post-slug', function() { }).on( 'after-autosave.update-post-slug', function() {
// create slug area only if not already there // Create slug area only if not already there
if ( ! $('#edit-slug-box > *').length ) { // and the title field was not focused (user was not typing a title) when autosave ran
if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) {
$.post( ajaxurl, { $.post( ajaxurl, {
action: 'sample-permalink', action: 'sample-permalink',
post_id: $('#post_ID').val(), post_id: $('#post_ID').val(),
@ -501,7 +505,7 @@ jQuery(document).ready( function($) {
// Autosave new posts after a title is typed // Autosave new posts after a title is typed
if ( $( '#auto_draft' ).val() ) { if ( $( '#auto_draft' ).val() ) {
$( '#title' ).blur( function() { $( '#title' ).blur( function() {
if ( ! this.value || $( '#auto_draft' ).val() !== '1' ) { if ( ! this.value || $('#edit-slug-box > *').length ) {
return; return;
} }