diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php
index b328bd19d9..9659336fe9 100644
--- a/src/wp-includes/class-wp-editor.php
+++ b/src/wp-includes/class-wp-editor.php
@@ -1376,7 +1376,7 @@ final class _WP_Editors {
diff --git a/src/wp-includes/js/wplink.js b/src/wp-includes/js/wplink.js
index 22cd1296f4..9cc73173be 100644
--- a/src/wp-includes/js/wplink.js
+++ b/src/wp-includes/js/wplink.js
@@ -2,7 +2,10 @@
var wpLink;
( function( $ ) {
- var inputs = {}, rivers = {}, editor, searchTimer, River, Query;
+ var editor, searchTimer, River, Query,
+ inputs = {},
+ rivers = {},
+ isTouch = ( 'ontouchend' in document );
wpLink = {
timeToTriggerRiver: 150,
@@ -53,7 +56,7 @@ var wpLink;
rivers.elements.on( 'river-select', wpLink.updateFields );
// Display 'hint' message when search field or 'query-results' box are focused
- inputs.search.add( rivers.elements ).on( 'focus.wplink', function() {
+ inputs.search.on( 'focus.wplink', function() {
inputs.queryNoticeTextDefault.hide();
inputs.queryNoticeTextHint.removeClass( 'screen-reader-text' ).show();
} ).on( 'blur.wplink', function() {
@@ -120,18 +123,26 @@ var wpLink;
rivers.search.refresh();
rivers.recent.refresh();
- if ( wpLink.isMCE() )
+ if ( wpLink.isMCE() ) {
wpLink.mceRefresh();
- else
+ } else {
wpLink.setDefaultValues();
+ }
+
+ if ( isTouch ) {
+ // Close the onscreen keyboard
+ inputs.url.focus().blur();
+ } else {
+ // Focus the URL field and highlight its contents.
+ // If this is moved above the selection changes,
+ // IE will show a flashing cursor over the dialog.
+ inputs.url.focus()[0].select();
+ }
- // Focus the URL field and highlight its contents.
- // If this is moved above the selection changes,
- // IE will show a flashing cursor over the dialog.
- inputs.url.focus()[0].select();
// Load the most recent results if this is the first time opening the panel.
- if ( ! rivers.recent.ul.children().length )
+ if ( ! rivers.recent.ul.children().length ) {
rivers.recent.ajax();
+ }
},
mceRefresh: function() {
@@ -274,11 +285,9 @@ var wpLink;
editor.selection.collapse();
},
- updateFields: function( e, li, originalEvent ) {
+ updateFields: function( e, li ) {
inputs.url.val( li.children( '.item-permalink' ).val() );
inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
- if ( originalEvent && originalEvent.type == 'click' )
- inputs.url.focus();
},
setDefaultValues: function() {
@@ -364,7 +373,8 @@ var wpLink;
return;
}
- if ( inputs.url.is( ':focus' ) || inputs.title.is( ':focus' ) ) {
+ if ( document.activeElement &&
+ ( document.activeElement.id === 'link-title-field' || document.activeElement.id === 'url-field' ) ) {
return;
}