Ticket #33301: 33301.2.patch
File 33301.2.patch, 4.9 KB (added by , 7 years ago) |
---|
-
src/wp-includes/js/tinymce/plugins/wordpress/plugin.js
850 850 851 851 currentSelection = args.selection || args.element; 852 852 853 if ( activeToolbar ) {853 if ( activeToolbar && activeToolbar !== args.toolbar ) { 854 854 activeToolbar.hide(); 855 855 } 856 856 857 857 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 } 860 864 } else { 861 865 activeToolbar = false; 862 866 } -
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 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(); 55 91 }); 56 92 57 93 // WP default shortcut … … 99 135 } 100 136 } ); 101 137 138 var previewInstance, inputInstance; 139 102 140 editor.addButton( 'wp_link_preview', { 103 141 type: 'WPLinkPreview', 104 142 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; 106 153 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 } ); 120 173 } 121 } 174 175 a = false; 176 177 editor.nodeChanged(); 178 editor.focus(); 179 } ); 122 180 } ); 123 181 } 124 182 } ); 125 183 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 126 209 editor.addButton( 'wp_link_edit', { 127 210 tooltip: 'Edit ', // trailing space is needed, used for context 128 211 icon: 'dashicon dashicons-edit', … … 134 217 icon: 'dashicon dashicons-no', 135 218 cmd: 'unlink' 136 219 } ); 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 220 } ); 148 221 } )( window.tinymce );