Make WordPress Core

Ticket #33301: 33301.patch

File 33301.patch, 4.1 KB (added by iseulde, 8 years ago)
  • src/wp-includes/js/tinymce/plugins/wordpress/plugin.js

     
    848848
    849849                        editor.fire( 'wptoolbar', args );
    850850
    851                         currentSelection = args.selection || args.element;
    852 
    853                         if ( activeToolbar ) {
    854                                 activeToolbar.hide();
    855                         }
    856 
    857                         if ( args.toolbar ) {
    858                                 activeToolbar = args.toolbar;
    859                                 activeToolbar.show();
    860                         } else {
    861                                 activeToolbar = false;
    862                         }
     851                        setActiveToolbar( args.toolbar, args.selection || args.element );
    863852                } );
    864853
     854                function setActiveToolbar( toolbar, selection ) {
     855                        selection && ( currentSelection = selection );
     856                        activeToolbar && activeToolbar.hide();
     857                        activeToolbar = toolbar;
     858                        activeToolbar && activeToolbar.show();
     859                }
     860
    865861                editor.on( 'focus', function() {
    866862                        if ( activeToolbar ) {
    867863                                activeToolbar.show();
     
    898894
    899895                editor.wp = editor.wp || {};
    900896                editor.wp._createToolbar = create;
     897                editor.wp._setActiveToolbar = setActiveToolbar;
    901898        }, true );
    902899
    903900        function noop() {}
  • 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                        // window.wpLink && window.wpLink.open( editor.id );
     83                        // editor.execCommand( 'mceInsertLink', false, { href: '#' } );
     84
     85                        editor.wp._setActiveToolbar( editToolbar, editor.selection.getRng() );
     86
     87                        var node = editToolbar.find( 'toolbar' )[0];
     88                        node && node.focus( true );
    5589                });
    5690
    5791                // WP default shortcut
     
    123157                        }
    124158                } );
    125159
     160                editor.addButton( 'wp_link_input', {
     161                        type: 'WPLinkInput',
     162                        onPostRender: function() {
     163                                var self = this;
     164                                var input = this.getEl().firstChild;
     165
     166                                editor.on( 'init', function() {
     167                                        tinymce.$( input ).on( 'keydown', function( event ) {
     168                                                event.keyCode === 13 && editToolbar.hide();
     169                                        } );
     170
     171                                        editToolbar.on( 'hide', function() {
     172                                                var link = editor.dom.getParent( editor.selection.getNode(), 'a' );
     173
     174                                                if ( link ) {
     175                                                        editor.dom.setAttribs( link, { href: input.value } );
     176                                                } else {
     177                                                        editor.execCommand( 'mceInsertLink', false, { href: input.value } );
     178                                                }
     179                                        } );
     180                                } );
     181
     182                                editor.on( 'wptoolbar', function( event ) {
     183                                        var anchor = editor.dom.getParent( event.element, 'a' ),
     184                                                $anchor,
     185                                                href;
     186
     187                                        if ( anchor ) {
     188                                                $anchor = editor.$( anchor );
     189                                                href = $anchor.attr( 'href' );
     190
     191                                                if ( href && ! $anchor.find( 'img' ).length ) {
     192                                                        self.setURL( href );
     193                                                }
     194                                        }
     195                                } );
     196                        }
     197                } );
     198
    126199                editor.addButton( 'wp_link_edit', {
    127200                        tooltip: 'Edit ', // trailing space is needed, used for context
    128201                        icon: 'dashicon dashicons-edit',
     
    134207                        icon: 'dashicon dashicons-no',
    135208                        cmd: 'unlink'
    136209                } );
    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                 } );
    147210        } );
    148211} )( window.tinymce );