Ticket #22407: 22407.patch
File 22407.patch, 3.0 KB (added by , 12 years ago) |
---|
-
wp-includes/js/tinymce/plugins/wpview/editor_plugin_src.js
11 11 init : function( editor, url ) { 12 12 var wpView = this; 13 13 14 this.editor = editor; 15 14 16 // Check if the `wp.mce` API exists. 15 17 if ( typeof wp === 'undefined' || ! wp.mce ) 16 18 return; … … 18 20 editor.onPreInit.add( function( editor ) { 19 21 // Add elements so we can set `contenteditable` to false. 20 22 editor.schema.addValidElements('div[*],span[*]'); 23 24 editor.undoManager.onBeforeAdd.addToTop(function(undoManager, o){ 25 o.content = wp.mce.view.toText( o.content ); 26 27 console.log( 'undo.onBeforeAdd = '+o.content ) 28 }); 29 30 editor.undoManager.onRedo.addToTop(function(undoManager, o){ 31 // Add back any views that were converted to text before deleting them 32 o.content = wp.mce.view.toViews( o.content ); 33 34 console.log( 'onRedo = '+o.content ) 35 }); 21 36 }); 22 37 23 38 // When the editor's content changes, scan the new content for … … 129 144 130 145 // If delete or backspace is pressed, delete the view. 131 146 if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) { 132 if ( (instance = wp.mce.view.instance( selected )) ) { 147 if ( instance = wp.mce.view.instance( selected ) ) { 148 var dom = editor.dom, parent = selected.parentNode, html, temp, viewText; 149 150 // Get the view's HTML as string and convert it to text mode 151 html = wp.mce.view.toText( dom.getOuterHTML(selected) ); 152 153 // Create a temporary span to hold the view's text and replace the view with the temp span 154 temp = dom.create('span', {}, html); 155 dom.replace( temp, selected ); 156 157 // Run any "remove" callbacks 158 // (At this point the view has alredy been removed from the dom. Could that cause problems?) 133 159 instance.remove(); 134 160 wpView.deselect(); 161 162 // Get the text for the view again in case it has changed 163 viewText = temp.innerHTML; 164 // Remove the temp <span> leaving its content only 165 dom.remove(temp, true); 166 167 // Cancel the undo level up to this point 168 editor.execCommand('mceEndUndoLevel', false, {}, {skip_undo: true}); 169 170 // Finally delete the view's text. This will be saved in the undo level. 171 parent.innerHTML = parent.innerHTML.replace(viewText, ''); 172 editor.nodeChanged(); 135 173 } 136 174 } 137 175 … … 140 178 if ( event.metaKey || event.ctrlKey || ( keyCode >= 112 && keyCode <= 123 ) ) 141 179 return; 142 180 143 e vent.preventDefault();181 editor.dom.event.prevent(event); 144 182 }); 145 183 }, 146 184 147 185 getParentView : function( node ) { 148 while ( node ) {186 while ( node && node.nodeName != 'BODY' ) { 149 187 if ( this.isView( node ) ) 150 188 return node; 151 189 … … 185 223 186 224 // Register plugin 187 225 tinymce.PluginManager.add( 'wpview', tinymce.plugins.wpView ); 188 })(); 189 No newline at end of file 226 })();