Ticket #31669: 31669.4.patch
File 31669.4.patch, 5.2 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
77 77 */ 78 78 unbind: function() { 79 79 _.each( instances, function( instance ) { 80 instance.unbind ();80 instance.unbindAll(); 81 81 } ); 82 82 }, 83 83 … … 139 139 return _.pluck( pieces, 'content' ).join( '' ); 140 140 }, 141 141 142 reset: function( content ) { 143 function callback() { 144 return '<p>' + decodeURIComponent( arguments[1] ) + '</p>'; 145 } 146 147 content = content.replace( /<[^>]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^>]+>[^>]+>/g, callback ); 148 content = content.replace( /<[^>]+data-wpview-marker="([^"]+)"[^>]*>[^>]+>/g, callback ); 149 150 return content; 151 }, 152 142 153 /** 143 154 * Create a view instance. 144 155 * … … 307 318 } 308 319 309 320 // We're about to rerender all views of this instance, so unbind rendered views. 310 force && this.unbind ();321 force && this.unbindAll(); 311 322 312 323 // Replace any left over markers. 313 324 this.replaceMarkers(); 314 325 315 326 if ( this.getContent() ) { 316 327 this.setContent( this.getContent(), function( editor, node ) { 317 $( node ).data( 'rendered', true ).trigger( 'wp-mce-view-bind' ); 328 $( node ).data( 'rendered', true ); 329 this.bind.apply( this, arguments ); 318 330 }, force ? null : false ); 319 331 } else { 320 332 this.setLoader(); … … 322 334 }, 323 335 324 336 /** 337 * Binds a given node after its content is added to the DOM. 338 */ 339 bind: function() {}, 340 341 /** 342 * Unbinds a given node before its content is removed from the DOM. 343 */ 344 unbind: function() {}, 345 346 /** 325 347 * Unbinds all view nodes tied to this view instance. 326 348 * Runs before their content is removed from the DOM. 327 349 */ 328 unbind : function() {350 unbindAll: function() { 329 351 this.getNodes( function( editor, node ) { 352 this.unbind.apply( this, arguments ); 330 353 $( node ).trigger( 'wp-mce-view-unbind' ); 331 354 }, true ); 332 355 }, … … 461 484 * @param {Boolean} rendered Only set for (un)rendered nodes. Optional. 462 485 */ 463 486 setIframes: function( head, body, callback, rendered ) { 464 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; 487 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, 488 self = this; 465 489 466 490 this.getNodes( function( editor, node, content ) { 467 491 // Seems Firefox needs a bit of time to insert/set the view nodes, … … 582 606 editor.off( 'wp-body-class-change', classChange ); 583 607 } ); 584 608 585 callback && callback.apply( this, arguments );609 callback && callback.apply( self, arguments ); 586 610 }, 50 ); 587 611 }, rendered ); 588 612 }, … … 663 687 * @param {HTMLElement} node The view node to remove. 664 688 */ 665 689 remove: function( editor, node ) { 690 this.unbind.call( this, editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); 666 691 $( node ).trigger( 'wp-mce-view-unbind' ); 667 692 editor.dom.remove( node ); 668 693 } -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
151 151 }; 152 152 } 153 153 154 // Remove the content of view wrappers from HTML string155 function emptyViews( content ) {156 return content.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g, '$1' );157 }158 159 154 // Prevent adding undo levels on changes inside a view wrapper 160 155 editor.on( 'BeforeAddUndo', function( event ) { 161 if ( event.lastLevel && emptyViews( event.level.content ) === emptyViews( event.lastLevel.content ) ) {156 if ( event.lastLevel && wp.mce.views.reset( event.level.content ) === wp.mce.views.reset( event.lastLevel.content ) ) { 162 157 event.preventDefault(); 163 158 } 164 } );159 } ); 165 160 166 161 // When the editor's content changes, scan the new content for 167 162 // matching view patterns, and transform the matches into … … 169 164 editor.on( 'BeforeSetContent', function( event ) { 170 165 var node; 171 166 167 if ( ! event.selection ) { 168 wp.mce.views.unbind(); 169 } 170 172 171 if ( ! event.content ) { 173 172 return; 174 173 } … … 330 329 } 331 330 }); 332 331 333 editor.on( 'PreProcess', function( event ) { 334 // Empty the wpview wrap nodes 335 tinymce.each( editor.dom.select( 'div[data-wpview-text]', event.node ), function( node ) { 336 node.textContent = node.innerText = '\u00a0'; 337 }); 338 }); 332 editor.on( 'PostProcess', function( event ) { 333 event.content = wp.mce.views.reset( event.content ); 334 } ); 339 335 340 editor.on( 'PostProcess', function( event ) { 341 if ( event.content ) { 342 event.content = event.content.replace( /<div [^>]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) { 343 if ( shortcode ) { 344 return '<p>' + window.decodeURIComponent( shortcode ) + '</p>'; 345 } 346 return ''; // If error, remove the view wrapper 347 }); 348 } 349 }); 336 editor.on( 'hide', function() { 337 editor.setContent( '' ); 338 } ); 350 339 351 340 // Excludes arrow keys, delete, backspace, enter, space bar. 352 341 // Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode