Make WordPress Core

Changeset 38808


Ignore:
Timestamp:
10/17/2016 08:00:53 PM (8 years ago)
Author:
azaozz
Message:

TinyMCE wplink:

  • Remove the calls to getBookmark() and moveToBookmark() in IE. This is handled automatically when blurring and focusing the editor.
  • When inserting a link, move it out of the caret position element. If not, it may be removed with that element on clean-up before save.

Fixes #38335.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/wplink.js

    r38126 r38808  
    125125                } else {
    126126                    editor = null;
    127                 }
    128 
    129                 if ( editor && window.tinymce.isIE ) {
    130                     editor.windowManager.wplinkBookmark = editor.selection.getBookmark();
    131127                }
    132128            }
     
    307303            wpLink.correctURL();
    308304
    309             return {
    310                 href: $.trim( inputs.url.val() ),
    311                 target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
     305            var attrs = {
     306                href: $.trim( inputs.url.val() )
    312307            };
     308
     309            if ( inputs.openInNewTab.prop( 'checked' ) ) {
     310                attrs.target = '_blank';
     311            }
     312
     313            return attrs;
    313314        },
    314315
     
    392393        mceUpdate: function() {
    393394            var attrs = wpLink.getAttrs(),
    394                 link, text;
    395 
    396             if ( window.tinymce.isIE && editor.windowManager.wplinkBookmark ) {
    397                 editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );
    398                 editor.windowManager.wplinkBookmark = null;
    399             }
     395                $link, text, hasText, $mceCaret;
    400396
    401397            if ( ! attrs.href ) {
     
    405401            }
    406402
    407             link = getLink();
    408 
    409             if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
    410                 text = inputs.text.val() || attrs.href;
    411             }
    412 
    413             if ( link ) {
    414                 if ( text ) {
    415                     if ( 'innerText' in link ) {
    416                         link.innerText = text;
    417                     } else {
    418                         link.textContent = text;
     403            $link = editor.$( getLink() );
     404
     405            editor.undoManager.transact( function() {
     406                if ( ! $link.length ) {
     407                    editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder', 'data-wp-temp-link': 1 } );
     408                    $link = editor.$( 'a[data-wp-temp-link="1"]' ).removeAttr( 'data-wp-temp-link' );
     409                    hasText = $.trim( $link.text() );
     410                }
     411
     412                if ( ! $link.length ) {
     413                    editor.execCommand( 'unlink' );
     414                } else {
     415                    if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
     416                        text = inputs.text.val();
     417
     418                        if ( text ) {
     419                            $link.text( text );
     420                        } else if ( ! hasText ) {
     421                            $link.text( attrs.href );
     422                        }
    419423                    }
    420                 }
    421 
    422                 // Not editing any more
    423                 attrs['data-wplink-edit'] = null;
    424                 editor.dom.setAttribs( link, attrs );
    425             } else {
    426                 if ( text ) {
    427                     editor.selection.setNode( editor.dom.create( 'a', attrs, editor.dom.encode( text ) ) );
    428                 } else {
    429                     editor.execCommand( 'mceInsertLink', false, attrs );
    430                 }
    431             }
     424
     425                    attrs['data-wplink-edit'] = null;
     426                    attrs['data-mce-href'] = null; // attrs.href
     427                    $link.attr( attrs );
     428                }
     429            } );
    432430
    433431            wpLink.close( 'noReset' );
    434432            editor.focus();
     433
     434            if ( $link.length ) {
     435                $mceCaret = $link.parent( '#_mce_caret' );
     436
     437                if ( $mceCaret.length ) {
     438                    $mceCaret.before( $link.removeAttr( 'data-mce-bogus' ) );
     439                }
     440
     441                editor.selection.select( $link[0] );
     442                editor.selection.collapse();
     443
     444                if ( editor.plugins.wplink ) {
     445                    editor.plugins.wplink.checkLink( $link[0] );
     446                }
     447            }
     448
    435449            editor.nodeChanged();
    436 
    437             if ( link && editor.plugins.wplink ) {
    438                 editor.plugins.wplink.checkLink( link );
    439             }
    440450
    441451            // Audible confirmation message when a link has been inserted in the Editor.
Note: See TracChangeset for help on using the changeset viewer.