From f2c1fcbb65700e357c78e9bcee521feebeea2b00 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 25 Mar 2014 22:21:24 +0000 Subject: [PATCH] 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 --- src/wp-admin/js/post.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/js/post.js b/src/wp-admin/js/post.js index c847cd4134..3dcebfe9a0 100644 --- a/src/wp-admin/js/post.js +++ b/src/wp-admin/js/post.js @@ -18,7 +18,8 @@ function array_unique_noempty(a) { return out; } -(function($){ +( function($) { + var titleHasFocus = false; tagBox = { clean : function(tags) { @@ -309,9 +310,12 @@ $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) { $('#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() { - // create slug area only if not already there - if ( ! $('#edit-slug-box > *').length ) { + // Create slug area only if not already there + // and the title field was not focused (user was not typing a title) when autosave ran + if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) { $.post( ajaxurl, { action: 'sample-permalink', post_id: $('#post_ID').val(), @@ -501,7 +505,7 @@ jQuery(document).ready( function($) { // Autosave new posts after a title is typed if ( $( '#auto_draft' ).val() ) { $( '#title' ).blur( function() { - if ( ! this.value || $( '#auto_draft' ).val() !== '1' ) { + if ( ! this.value || $('#edit-slug-box > *').length ) { return; }