TinyMCE, inline link:

- Fix applying the changes when pressing the Enter key in Firefox. No longer inserts new paragraph in the editor.
- Fix empty check when getting text from the dialog.
- Always focus the URL field when opening the dialog.
- Add back the keydown events in the modal.

See #33301.

git-svn-id: https://develop.svn.wordpress.org/trunk@36743 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2016-02-27 00:51:41 +00:00
parent be3ba15eec
commit d8c52aba85
2 changed files with 48 additions and 10 deletions

View File

@ -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();
}
} );
}

View File

@ -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,