TinyMCE Classic Block: fix the Advanced Link modal (accessible when clicking on the cogwheel in the inline link modal in a Classic Block).

Fixes #46071.
Built from https://develop.svn.wordpress.org/trunk@44696


git-svn-id: http://core.svn.wordpress.org/trunk@44527 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2019-01-24 11:21:50 +00:00
parent 6bd203bb50
commit a6e8abca83
6 changed files with 31 additions and 44 deletions

View File

@ -226,15 +226,15 @@
linkNode = getSelectedLink(); linkNode = getSelectedLink();
editToolbar.tempHide = false; editToolbar.tempHide = false;
if ( linkNode ) { if ( ! linkNode ) {
editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } );
} else {
removePlaceholders(); removePlaceholders();
editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } ); editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } );
linkNode = editor.$( 'a[href="_wp_link_placeholder"]' )[0]; linkNode = editor.$( 'a[href="_wp_link_placeholder"]' )[0];
editor.nodeChanged(); editor.nodeChanged();
} }
editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } );
} ); } );
editor.addCommand( 'wp_link_apply', function() { editor.addCommand( 'wp_link_apply', function() {
@ -284,8 +284,9 @@
} ); } );
editor.addCommand( 'wp_link_cancel', function() { editor.addCommand( 'wp_link_cancel', function() {
inputInstance.reset();
if ( ! editToolbar.tempHide ) { if ( ! editToolbar.tempHide ) {
inputInstance.reset();
removePlaceholders(); removePlaceholders();
} }
} ); } );
@ -583,24 +584,10 @@
var url = inputInstance.getURL() || null, var url = inputInstance.getURL() || null,
text = inputInstance.getLinkText() || null; text = inputInstance.getLinkText() || null;
/* window.wpLink.open( editor.id, url, text );
* Accessibility note: moving focus back to the editor confuses
* screen readers. They will announce again the Editor ARIA role
* `application` and the iframe `title` attribute.
*
* Unfortunately IE looses the selection when the editor iframe
* looses focus, so without returning focus to the editor, the code
* in the modal will not be able to get the selection, place the caret
* at the same location, etc.
*/
if ( tinymce.Env.ie ) {
editor.focus(); // Needed for IE
}
editToolbar.tempHide = true; editToolbar.tempHide = true;
window.wpLink.open( editor.id, url, text, linkNode ); editToolbar.hide();
inputInstance.reset();
} }
} }
} ); } );

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
/* global wpLink */ /* global wpLink */
( function( $, wpLinkL10n, wp ) { ( function( $, wpLinkL10n, wp ) {
var editor, searchTimer, River, Query, correctedURL, linkNode, var editor, searchTimer, River, Query, correctedURL,
emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i, emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i,
urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i, urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i,
inputs = {}, inputs = {},
@ -13,7 +13,11 @@
isTouch = ( 'ontouchend' in document ); isTouch = ( 'ontouchend' in document );
function getLink() { function getLink() {
return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' ); if ( editor ) {
return editor.$( 'a[data-wplink-edit="true"]' );
}
return null;
} }
window.wpLink = { window.wpLink = {
@ -97,13 +101,12 @@
} }
}, },
open: function( editorId, url, text, node ) { open: function( editorId, url, text ) {
var ed, var ed,
$body = $( document.body ); $body = $( document.body );
$body.addClass( 'modal-open' ); $body.addClass( 'modal-open' );
wpLink.modalOpen = true; wpLink.modalOpen = true;
linkNode = node;
wpLink.range = null; wpLink.range = null;
@ -205,10 +208,10 @@
return false; return false;
} }
if ( linkNode ) { if ( linkNode.length ) {
nodes = linkNode.childNodes; nodes = linkNode[0].childNodes;
if ( nodes.length === 0 ) { if ( ! nodes || ! nodes.length ) {
return false; return false;
} }
@ -229,9 +232,9 @@
linkNode = getLink(), linkNode = getLink(),
onlyText = this.hasSelectedText( linkNode ); onlyText = this.hasSelectedText( linkNode );
if ( linkNode ) { if ( linkNode.length ) {
linkText = linkNode.textContent || linkNode.innerText; linkText = linkNode.text();
href = editor.dom.getAttrib( linkNode, 'href' ); href = linkNode.attr( 'href' );
if ( ! $.trim( linkText ) ) { if ( ! $.trim( linkText ) ) {
linkText = text || ''; linkText = text || '';
@ -243,7 +246,7 @@
if ( href !== '_wp_link_placeholder' ) { if ( href !== '_wp_link_placeholder' ) {
inputs.url.val( href ); inputs.url.val( href );
inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) ); inputs.openInNewTab.prop( 'checked', '_blank' === linkNode.attr( 'target' ) );
inputs.submit.val( wpLinkL10n.update ); inputs.submit.val( wpLinkL10n.update );
} else { } else {
this.setDefaultValues( linkText ); this.setDefaultValues( linkText );
@ -414,7 +417,7 @@
return; return;
} }
$link = editor.$( getLink() ); $link = getLink();
editor.undoManager.transact( function() { editor.undoManager.transact( function() {
if ( ! $link.length ) { if ( ! $link.length ) {
@ -437,7 +440,7 @@
} }
attrs['data-wplink-edit'] = null; attrs['data-wplink-edit'] = null;
attrs['data-mce-href'] = null; // attrs.href attrs['data-mce-href'] = attrs.href;
$link.attr( attrs ); $link.attr( attrs );
} }
} ); } );
@ -446,14 +449,7 @@
editor.focus(); editor.focus();
if ( $link.length ) { if ( $link.length ) {
$mceCaret = $link.parent( '#_mce_caret' );
if ( $mceCaret.length ) {
$mceCaret.before( $link.removeAttr( 'data-mce-bogus' ) );
}
editor.selection.select( $link[0] ); editor.selection.select( $link[0] );
editor.selection.collapse();
if ( editor.plugins.wplink ) { if ( editor.plugins.wplink ) {
editor.plugins.wplink.checkLink( $link[0] ); editor.plugins.wplink.checkLink( $link[0] );
@ -468,6 +464,10 @@
updateFields: function( e, li ) { updateFields: function( e, li ) {
inputs.url.val( li.children( '.item-permalink' ).val() ); inputs.url.val( li.children( '.item-permalink' ).val() );
if ( inputs.wrap.hasClass( 'has-text-field' ) && ! inputs.text.val() ) {
inputs.text.val( li.children( '.item-title' ).text() );
}
}, },
getUrlFromSelection: function( selection ) { getUrlFromSelection: function( selection ) {

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.1-beta2-44695'; $wp_version = '5.1-beta2-44696';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.