Ticket #33301: 33301.patch
File 33301.patch, 4.1 KB (added by , 8 years ago) |
---|
-
src/wp-includes/js/tinymce/plugins/wordpress/plugin.js
848 848 849 849 editor.fire( 'wptoolbar', args ); 850 850 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 ); 863 852 } ); 864 853 854 function setActiveToolbar( toolbar, selection ) { 855 selection && ( currentSelection = selection ); 856 activeToolbar && activeToolbar.hide(); 857 activeToolbar = toolbar; 858 activeToolbar && activeToolbar.show(); 859 } 860 865 861 editor.on( 'focus', function() { 866 862 if ( activeToolbar ) { 867 863 activeToolbar.show(); … … 898 894 899 895 editor.wp = editor.wp || {}; 900 896 editor.wp._createToolbar = create; 897 editor.wp._setActiveToolbar = setActiveToolbar; 901 898 }, true ); 902 899 903 900 function noop() {} -
src/wp-includes/js/tinymce/plugins/wplink/plugin.js
47 47 } 48 48 } ); 49 49 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 50 64 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 } ); 52 80 53 81 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 ); 55 89 }); 56 90 57 91 // WP default shortcut … … 123 157 } 124 158 } ); 125 159 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 126 199 editor.addButton( 'wp_link_edit', { 127 200 tooltip: 'Edit ', // trailing space is needed, used for context 128 201 icon: 'dashicon dashicons-edit', … … 134 207 icon: 'dashicon dashicons-no', 135 208 cmd: 'unlink' 136 209 } ); 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 } );147 210 } ); 148 211 } )( window.tinymce );