diff --git a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js index 14f46c94a1..9a91dc3b71 100644 --- a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js @@ -68,7 +68,13 @@ return tinymce.trim( this.getEl().firstChild.value ); }, getLinkText: function() { - return tinymce.trim( this.getEl().firstChild.nextSibling.value ); + var text = this.getEl().firstChild.nextSibling.value; + + if ( ! tinymce.trim( text ) ) { + return ''; + } + + return text.replace( /[\r\n\t ]+/g, ' ' ); }, reset: function() { var urlInput = this.getEl().firstChild; @@ -144,12 +150,15 @@ ], true ); editToolbar.on( 'show', function() { - var inputNode = editToolbar.find( 'toolbar' )[0]; - - if ( inputNode && ! tinymce.$( document.body ).hasClass( 'modal-open' ) ) { + if ( ! tinymce.$( document.body ).hasClass( 'modal-open' ) ) { window.setTimeout( function() { - inputNode.focus( true ); - }); + var element = editToolbar.$el.find( 'input.ui-autocomplete-input' )[0]; + + if ( element ) { + element.focus(); + element.select(); + } + } ); } } ); @@ -172,6 +181,8 @@ return; } + editToolbar.tempHide = false; + if ( link ) { editor.dom.setAttribs( link, { 'data-wplink-edit': true } ); } else { @@ -181,6 +192,8 @@ if ( tinymce.Env.ie ) { editor.windowManager.wplinkBookmark = editor.selection.getBookmark(); } + + editor.nodeChanged(); } } ); @@ -227,12 +240,12 @@ inputInstance.reset(); removePlaceholders(); editor.focus(); - + if ( tinymce.isIE ) { editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark ); editor.windowManager.wplinkBookmark = null; } - + editToolbar.tempHide = false; } } ); @@ -384,6 +397,7 @@ tinymce.$( input ).on( 'keydown', function( event ) { if ( event.keyCode === 13 ) { editor.execCommand( 'wp_link_apply' ); + event.preventDefault(); } } ); } diff --git a/src/wp-includes/js/wplink.js b/src/wp-includes/js/wplink.js index d1f34dd1a9..447e723e42 100644 --- a/src/wp-includes/js/wplink.js +++ b/src/wp-includes/js/wplink.js @@ -29,7 +29,8 @@ var wpLink; wpLink.setAutocomplete(); } - inputs.submit.click( function( event ) { + inputs.dialog.on( 'keydown', wpLink.keydown ); + inputs.submit.on( 'click', function( event ) { event.preventDefault(); wpLink.update(); }); @@ -210,7 +211,7 @@ var wpLink; // IE will show a flashing cursor over the dialog. window.setTimeout( function() { inputs.url.focus()[0].select(); - }, 100 ); + } ); } correctedURL = inputs.url.val().replace( /^http:\/\//, '' ); @@ -431,6 +432,29 @@ var wpLink; editor.nodeChanged(); }, + keydown: function( event ) { + var id; + + // Escape key. + if ( 27 === event.keyCode ) { + wpLink.close(); + event.stopImmediatePropagation(); + // Tab key. + } else if ( 9 === event.keyCode ) { + id = event.target.id; + + // wp-link-submit must always be the last focusable element in the dialog. + // following focusable elements will be skipped on keyboard navigation. + if ( id === 'wp-link-submit' && ! event.shiftKey ) { + inputs.close.focus(); + event.preventDefault(); + } else if ( id === 'wp-link-close' && event.shiftKey ) { + inputs.submit.focus(); + event.preventDefault(); + } + } + }, + setDefaultValues: function() { var selection, emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,