Ticket #31412: 31412.12.patch
File 31412.12.patch, 4.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
163 163 /** 164 164 * Get a view instance. 165 165 * 166 * @param {(String|HTMLElement)} object The textual representation of the view or the view node. 167 */ 168 getInstance: function( object ) { 169 if ( typeof object === 'string' ) { 170 return instances[ encodeURIComponent( object ) ]; 171 } 172 173 return instances[ $( object ).data( 'wpview-text' ) ]; 174 }, 175 176 /** 177 * Given a view node, get the view's text. 178 * 166 179 * @param {String} text The textual representation of the view. 167 180 */ 168 get Instance: function( text) {169 return instances[ encodeURIComponent( text ) ];181 getText: function( node ) { 182 return decodeURIComponent( $( node ).data( 'wpview-text' ) || '' ); 170 183 }, 171 184 172 185 /** … … 188 201 * @param {HTMLElement} node The view node to update. 189 202 */ 190 203 update: function( text, editor, node ) { 191 var oldText = decodeURIComponent( $( node ).data( 'wpview-text' ) ), 192 instance = this.getInstance( oldText ); 204 var instance = this.getInstance( node ); 193 205 194 206 if ( instance ) { 195 207 instance.update( text, editor, node ); … … 203 215 * @param {HTMLElement} node The view node to edit. 204 216 */ 205 217 edit: function( editor, node ) { 206 var text = decodeURIComponent( $( node ).data( 'wpview-text' ) ), 207 instance = this.getInstance( text ); 218 var instance = this.getInstance( node ); 208 219 209 220 if ( instance && instance.edit ) { 210 instance.edit( text, function( text ) {221 instance.edit( instance.text, function( text ) { 211 222 instance.update( text, editor, node ); 212 223 } ); 213 224 } 225 }, 226 227 /** 228 * Remove a given view node from the DOM. 229 * 230 * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. 231 * @param {HTMLElement} node The view node to remove. 232 */ 233 remove: function( editor, node ) { 234 var instance = this.getInstance( node ); 235 236 if ( instance ) { 237 instance.remove( editor, node ); 238 } 214 239 } 215 240 }; 216 241 … … 218 243 * A Backbone-like View constructor intended for use when rendering a TinyMCE View. 219 244 * The main difference is that the TinyMCE View is not tied to a particular DOM node. 220 245 * 221 * @param {Object} Options.246 * @param {Object} options Options. 222 247 */ 223 248 wp.mce.View = function( options ) { 224 249 _.extend( this, options ); … … 631 656 $( node ).data( 'rendered', false ); 632 657 editor.dom.setAttrib( node, 'data-wpview-text', encodeURIComponent( text ) ); 633 658 wp.mce.views.createInstance( this.type, text, this.match( text ).options ).render(); 659 }, 660 661 /** 662 * Remove a given view node from the DOM. 663 * 664 * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. 665 * @param {HTMLElement} node The view node to remove. 666 */ 667 remove: function( editor, node ) { 668 this.unbindNodes( editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); 669 editor.dom.remove( node ); 634 670 } 635 671 } ); 636 672 } )( window, window.wp, window.jQuery ); -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
72 72 } 73 73 74 74 function removeView( view ) { 75 // TODO: trigger an event to run a clean up function.76 // Maybe `jQuery( view ).trigger( 'remove' );`?77 75 editor.undoManager.transact( function() { 78 76 handleEnter( view ); 79 editor.dom.remove(view );77 wp.mce.views.remove( editor, view ); 80 78 }); 81 79 } 82 80 … … 107 105 clipboard = dom.create( 'div', { 108 106 'class': 'wpview-clipboard', 109 107 'contenteditable': 'true' 110 }, decodeURIComponent( editor.dom.getAttrib( viewNode, 'data-wpview-text' )) );108 }, wp.mce.views.getText( viewNode ) ); 111 109 112 110 editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard ); 113 111