Make WordPress Core

Changeset 44696


Ignore:
Timestamp:
01/24/2019 11:20:25 AM (6 years ago)
Author:
azaozz
Message:

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.

Location:
trunk/src/js/_enqueues
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/link.js

    r43577 r44696  
    66
    77( function( $, wpLinkL10n, wp ) {
    8     var editor, searchTimer, River, Query, correctedURL, linkNode,
     8    var editor, searchTimer, River, Query, correctedURL,
    99        emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i,
    1010        urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i,
     
    1414
    1515    function getLink() {
    16         return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
     16        if ( editor ) {
     17            return editor.$( 'a[data-wplink-edit="true"]' );
     18        }
     19
     20        return null;
    1721    }
    1822
     
    98102        },
    99103
    100         open: function( editorId, url, text, node ) {
     104        open: function( editorId, url, text ) {
    101105            var ed,
    102106                $body = $( document.body );
     
    104108            $body.addClass( 'modal-open' );
    105109            wpLink.modalOpen = true;
    106             linkNode = node;
    107110
    108111            wpLink.range = null;
     
    206209            }
    207210
    208             if ( linkNode ) {
    209                 nodes = linkNode.childNodes;
    210 
    211                 if ( nodes.length === 0 ) {
     211            if ( linkNode.length ) {
     212                nodes = linkNode[0].childNodes;
     213
     214                if ( ! nodes || ! nodes.length ) {
    212215                    return false;
    213216                }
     
    230233                onlyText = this.hasSelectedText( linkNode );
    231234
    232             if ( linkNode ) {
    233                 linkText = linkNode.textContent || linkNode.innerText;
    234                 href = editor.dom.getAttrib( linkNode, 'href' );
     235            if ( linkNode.length ) {
     236                linkText = linkNode.text();
     237                href = linkNode.attr( 'href' );
    235238
    236239                if ( ! $.trim( linkText ) ) {
     
    244247                if ( href !== '_wp_link_placeholder' ) {
    245248                    inputs.url.val( href );
    246                     inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
     249                    inputs.openInNewTab.prop( 'checked', '_blank' === linkNode.attr( 'target' ) );
    247250                    inputs.submit.val( wpLinkL10n.update );
    248251                } else {
     
    415418            }
    416419
    417             $link = editor.$( getLink() );
     420            $link = getLink();
    418421
    419422            editor.undoManager.transact( function() {
     
    438441
    439442                    attrs['data-wplink-edit'] = null;
    440                     attrs['data-mce-href'] = null; // attrs.href
     443                    attrs['data-mce-href'] = attrs.href;
    441444                    $link.attr( attrs );
    442445                }
     
    447450
    448451            if ( $link.length ) {
    449                 $mceCaret = $link.parent( '#_mce_caret' );
    450 
    451                 if ( $mceCaret.length ) {
    452                     $mceCaret.before( $link.removeAttr( 'data-mce-bogus' ) );
    453                 }
    454 
    455452                editor.selection.select( $link[0] );
    456                 editor.selection.collapse();
    457453
    458454                if ( editor.plugins.wplink ) {
     
    469465        updateFields: function( e, li ) {
    470466            inputs.url.val( li.children( '.item-permalink' ).val() );
     467
     468            if ( inputs.wrap.hasClass( 'has-text-field' ) && ! inputs.text.val() ) {
     469                inputs.text.val( li.children( '.item-title' ).text() );
     470            }
    471471        },
    472472
  • trunk/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js

    r43309 r44696  
    227227            editToolbar.tempHide = false;
    228228
    229             if ( linkNode ) {
    230                 editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } );
    231             } else {
     229            if ( ! linkNode ) {
    232230                removePlaceholders();
    233231                editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } );
     
    236234                editor.nodeChanged();
    237235            }
     236
     237            editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } );
    238238        } );
    239239
     
    285285
    286286        editor.addCommand( 'wp_link_cancel', function() {
     287            inputInstance.reset();
     288
    287289            if ( ! editToolbar.tempHide ) {
    288                 inputInstance.reset();
    289290                removePlaceholders();
    290291            }
     
    584585                        text = inputInstance.getLinkText() || null;
    585586
    586                     /*
    587                      * Accessibility note: moving focus back to the editor confuses
    588                      * screen readers. They will announce again the Editor ARIA role
    589                      * `application` and the iframe `title` attribute.
    590                      *
    591                      * Unfortunately IE looses the selection when the editor iframe
    592                      * looses focus, so without returning focus to the editor, the code
    593                      * in the modal will not be able to get the selection, place the caret
    594                      * at the same location, etc.
    595                      */
    596                     if ( tinymce.Env.ie ) {
    597                         editor.focus(); // Needed for IE
    598                     }
     587                    window.wpLink.open( editor.id, url, text );
    599588
    600589                    editToolbar.tempHide = true;
    601                     window.wpLink.open( editor.id, url, text, linkNode );
    602 
    603                     inputInstance.reset();
     590                    editToolbar.hide();
    604591                }
    605592            }
Note: See TracChangeset for help on using the changeset viewer.