Make WordPress Core

Ticket #33301: 33301.2.patch

File 33301.2.patch, 4.9 KB (added by iseulde, 7 years ago)
  • src/wp-includes/js/tinymce/plugins/wordpress/plugin.js

     
    850850
    851851                        currentSelection = args.selection || args.element;
    852852
    853                         if ( activeToolbar ) {
     853                        if ( activeToolbar && activeToolbar !== args.toolbar ) {
    854854                                activeToolbar.hide();
    855855                        }
    856856
    857857                        if ( args.toolbar ) {
    858                                 activeToolbar = args.toolbar;
    859                                 activeToolbar.show();
     858                                if ( activeToolbar !== args.toolbar ) {
     859                                        activeToolbar = args.toolbar;
     860                                        activeToolbar.show();
     861                                } else {
     862                                        activeToolbar.reposition();
     863                                }
    860864                        } else {
    861865                                activeToolbar = false;
    862866                        }
  • src/wp-includes/js/tinymce/plugins/wplink/plugin.js

     
    4747                }
    4848        } );
    4949
     50        tinymce.ui.WPLinkInput = tinymce.ui.Control.extend( {
     51                url: '',
     52                renderHtml: function() {
     53                        return (
     54                                '<div id="' + this._id + '" class="wp-link-preview">' +
     55                                        '<input type="text" value="' + this.url + '" tabindex="-1" />' +
     56                                '</div>'
     57                        );
     58                },
     59                setURL: function( url ) {
     60                        this.getEl().firstChild.value = url;
     61                }
     62        } );
     63
    5064        tinymce.PluginManager.add( 'wplink', function( editor ) {
    51                 var toolbar;
     65                var toolbar, editToolbar;
     66
     67                editor.on( 'preinit', function() {
     68                        if ( editor.wp && editor.wp._createToolbar ) {
     69                                toolbar = editor.wp._createToolbar( [
     70                                        'wp_link_preview',
     71                                        'wp_link_edit',
     72                                        'wp_link_remove'
     73                                ], true );
     74
     75                                editToolbar = editor.wp._createToolbar( [
     76                                        'wp_link_input'
     77                                ], true );
     78                        }
     79                } );
    5280
    5381                editor.addCommand( 'WP_Link', function() {
    54                         window.wpLink && window.wpLink.open( editor.id );
     82                        var a = editor.dom.getParent( editor.selection.getNode(), 'a' );
     83
     84                        if ( a ) {
     85                                editor.dom.setAttribs( a, { 'data-wp-edit': true } );
     86                        } else {
     87                                editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } );
     88                        }
     89
     90                        editor.nodeChanged();
    5591                });
    5692
    5793                // WP default shortcut
     
    99135                        }
    100136                } );
    101137
     138                var previewInstance, inputInstance;
     139
    102140                editor.addButton( 'wp_link_preview', {
    103141                        type: 'WPLinkPreview',
    104142                        onPostRender: function() {
    105                                 var self = this;
     143                                previewInstance = this;
     144                        }
     145                } );
     146
     147                editor.addButton( 'wp_link_input', {
     148                        type: 'WPLinkInput',
     149                        onPostRender: function() {
     150                                inputInstance = this;
     151
     152                                var input = this.getEl().firstChild;
    106153
    107                                 editor.on( 'wptoolbar', function( event ) {
    108                                         var anchor = editor.dom.getParent( event.element, 'a' ),
    109                                                 $anchor,
    110                                                 href;
    111 
    112                                         if ( anchor ) {
    113                                                 $anchor = editor.$( anchor );
    114                                                 href = $anchor.attr( 'href' );
    115 
    116                                                 if ( href && ! $anchor.find( 'img' ).length ) {
    117                                                         self.setURL( href );
    118                                                         event.element = anchor;
    119                                                         event.toolbar = toolbar;
     154                                editor.on( 'init', function() {
     155                                        var a;
     156
     157                                        tinymce.$( input ).on( 'keydown', function( event ) {
     158                                                event.keyCode === 13 && editToolbar.hide();
     159                                        } );
     160
     161                                        editToolbar.on( 'show', function() {
     162                                                a = editor.dom.getParent( editor.selection.getNode(), 'a' );
     163                                        } );
     164
     165                                        editToolbar.on( 'hide', function(event) {
     166                                                if ( ! input.value ) {
     167                                                        editor.dom.remove( a, true );
     168                                                        return;
     169                                                }
     170
     171                                                if ( a ) {
     172                                                        editor.dom.setAttribs( a, { href: input.value, 'data-wp-edit': null } );
    120173                                                }
    121                                         }
     174
     175                                                a = false;
     176
     177                                                editor.nodeChanged();
     178                                                editor.focus();
     179                                        } );
    122180                                } );
    123181                        }
    124182                } );
    125183
     184                editor.on( 'wptoolbar', function( event ) {
     185                        var anchor = editor.dom.getParent( event.element, 'a' ),
     186                                $anchor,
     187                                href, edit, node;
     188
     189                        if ( anchor ) {
     190                                $anchor = editor.$( anchor );
     191                                href = $anchor.attr( 'href' );
     192                                edit = $anchor.attr( 'data-wp-edit' );
     193
     194                                if ( href === '_wp_link_placeholder' || edit ) {
     195                                        inputInstance.setURL( edit ? href : '' );
     196                                        event.element = anchor;
     197                                        event.toolbar = editToolbar;
     198                                        // move
     199                                        node = editToolbar.find( 'toolbar' )[0];
     200                                        node && node.focus( true );
     201                                } else if ( href && ! $anchor.find( 'img' ).length ) {
     202                                        previewInstance.setURL( href );
     203                                        event.element = anchor;
     204                                        event.toolbar = toolbar;
     205                                }
     206                        }
     207                } );
     208
    126209                editor.addButton( 'wp_link_edit', {
    127210                        tooltip: 'Edit ', // trailing space is needed, used for context
    128211                        icon: 'dashicon dashicons-edit',
     
    134217                        icon: 'dashicon dashicons-no',
    135218                        cmd: 'unlink'
    136219                } );
    137 
    138                 editor.on( 'preinit', function() {
    139                         if ( editor.wp && editor.wp._createToolbar ) {
    140                                 toolbar = editor.wp._createToolbar( [
    141                                         'wp_link_preview',
    142                                         'wp_link_edit',
    143                                         'wp_link_remove'
    144                                 ], true );
    145                         }
    146                 } );
    147220        } );
    148221} )( window.tinymce );