Ticket #31412: 31412.14.patch
File 31412.14.patch, 5.5 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} text The textual representation of the view.166 * @param {(String|HTMLElement)} object The textual representation of the view or the view node. 167 167 */ 168 getInstance: function( text ) { 169 return instances[ encodeURIComponent( text ) ]; 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 * 179 * @param {HTMLElement} node The view node. 180 */ 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 ); … … 277 302 if ( this.getContent() ) { 278 303 this.setContent( this.getContent(), function( editor, node ) { 279 304 $( node ).data( 'rendered', true ); 280 this.bindNode s.apply( this, arguments );305 this.bindNode.apply( this, arguments ); 281 306 }, force ? null : false ); 282 307 } else { 283 308 this.setLoader(); … … 292 317 * @param {HTMLElement} node The view node. 293 318 * @param {HTMLElement} contentNode The view's content node. 294 319 */ 295 bindNode s: function( /* editor, node, contentNode */ ) {},320 bindNode: function( /* editor, node, contentNode */ ) {}, 296 321 297 322 /** 298 323 * Unbinds all view nodes tied to this view instance. … … 300 325 */ 301 326 unbind: function() { 302 327 this.getNodes( function() { 303 this.unbindNode s.apply( this, arguments );328 this.unbindNode.apply( this, arguments ); 304 329 }, true ); 305 330 }, 306 331 … … 312 337 * @param {HTMLElement} node The view node. 313 338 * @param {HTMLElement} contentNode The view's content node. 314 339 */ 315 unbindNode s: function( /* editor, node, contentNode */ ) {},340 unbindNode: function( /* editor, node, contentNode */ ) {}, 316 341 317 342 /** 318 343 * Gets all the TinyMCE editor instances that support views. … … 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.unbindNode( 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 … … 348 346 }); 349 347 350 348 editor.on( 'PreProcess', function( event ) { 349 wp.mce.views.unbind(); 350 351 351 // Empty the wpview wrap nodes 352 352 tinymce.each( editor.dom.select( 'div[data-wpview-text]', event.node ), function( node ) { 353 353 node.textContent = node.innerText = '\u00a0';