From 3b14a06c8cb187d8abd3d4af8ea9c0ea3a475228 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 24 Jan 2019 11:20:25 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@44696 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/lib/link.js | 40 +++++++++---------- .../vendor/tinymce/plugins/wplink/plugin.js | 27 ++++--------- 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/js/_enqueues/lib/link.js b/src/js/_enqueues/lib/link.js index ff9b3c441d..8b6a93795a 100644 --- a/src/js/_enqueues/lib/link.js +++ b/src/js/_enqueues/lib/link.js @@ -5,7 +5,7 @@ /* global wpLink */ ( 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, urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i, inputs = {}, @@ -13,7 +13,11 @@ isTouch = ( 'ontouchend' in document ); 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 = { @@ -97,13 +101,12 @@ } }, - open: function( editorId, url, text, node ) { + open: function( editorId, url, text ) { var ed, $body = $( document.body ); $body.addClass( 'modal-open' ); wpLink.modalOpen = true; - linkNode = node; wpLink.range = null; @@ -205,10 +208,10 @@ return false; } - if ( linkNode ) { - nodes = linkNode.childNodes; + if ( linkNode.length ) { + nodes = linkNode[0].childNodes; - if ( nodes.length === 0 ) { + if ( ! nodes || ! nodes.length ) { return false; } @@ -229,9 +232,9 @@ linkNode = getLink(), onlyText = this.hasSelectedText( linkNode ); - if ( linkNode ) { - linkText = linkNode.textContent || linkNode.innerText; - href = editor.dom.getAttrib( linkNode, 'href' ); + if ( linkNode.length ) { + linkText = linkNode.text(); + href = linkNode.attr( 'href' ); if ( ! $.trim( linkText ) ) { linkText = text || ''; @@ -243,7 +246,7 @@ if ( href !== '_wp_link_placeholder' ) { 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 ); } else { this.setDefaultValues( linkText ); @@ -414,7 +417,7 @@ return; } - $link = editor.$( getLink() ); + $link = getLink(); editor.undoManager.transact( function() { if ( ! $link.length ) { @@ -437,7 +440,7 @@ } attrs['data-wplink-edit'] = null; - attrs['data-mce-href'] = null; // attrs.href + attrs['data-mce-href'] = attrs.href; $link.attr( attrs ); } } ); @@ -446,14 +449,7 @@ editor.focus(); 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.collapse(); if ( editor.plugins.wplink ) { editor.plugins.wplink.checkLink( $link[0] ); @@ -468,6 +464,10 @@ updateFields: function( e, li ) { 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 ) { diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js index 2314d835a9..890ebe86c2 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js @@ -226,15 +226,15 @@ linkNode = getSelectedLink(); editToolbar.tempHide = false; - if ( linkNode ) { - editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } ); - } else { + if ( ! linkNode ) { removePlaceholders(); editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } ); linkNode = editor.$( 'a[href="_wp_link_placeholder"]' )[0]; editor.nodeChanged(); } + + editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } ); } ); editor.addCommand( 'wp_link_apply', function() { @@ -284,8 +284,9 @@ } ); editor.addCommand( 'wp_link_cancel', function() { + inputInstance.reset(); + if ( ! editToolbar.tempHide ) { - inputInstance.reset(); removePlaceholders(); } } ); @@ -583,24 +584,10 @@ var url = inputInstance.getURL() || null, text = inputInstance.getLinkText() || null; - /* - * 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 - } + window.wpLink.open( editor.id, url, text ); editToolbar.tempHide = true; - window.wpLink.open( editor.id, url, text, linkNode ); - - inputInstance.reset(); + editToolbar.hide(); } } } );