Ticket #27389: 27389-why-god-why.2.diff
File 27389-why-god-why.2.diff, 4.6 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
42 42 $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { 43 43 var node = $( elem ); 44 44 node.html( html ); 45 elem.reinit = false; 45 46 $( self ).trigger( 'ready', elem ); 46 47 }); 47 48 } 48 49 }, this ); 50 }, 51 reinit: function() { 52 // Search all tinymce editor instances and update the placeholders 53 _.each( tinymce.editors, function( editor ) { 54 var doc, self = this; 55 if ( editor.plugins.wpview ) { 56 doc = editor.getDoc(); 57 $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { 58 elem.reinit = true; 59 $( self ).trigger( 'ready', elem ); 60 }); 61 } 62 }, this ); 63 49 64 } 50 65 } ); 51 66 … … 209 224 wp.mce.views.render(); 210 225 }, 211 226 227 /** 228 * Trigger event that individual views can use to initialize any event bindings 229 * 230 * Note: Great care needs to be taken to avoid memory leaks when binding events directly to view nodes. 231 */ 232 reinitializeViews: function() { 233 _.each( instances, function( instance ) { 234 instance.reinit(); 235 } ); 236 }, 237 212 238 getInstance: function( encodedText ) { 213 239 return instances[ encodedText ]; 214 240 }, … … 408 434 */ 409 435 wp.mce.media.View = wp.mce.View.extend({ 410 436 initialize: function( options ) { 437 this.player = []; 411 438 this.shortcode = options.shortcode; 412 439 _.bindAll( this, 'setPlayer' ); 413 440 $(this).on( 'ready', this.setPlayer ); 414 441 }, 415 442 443 reinitPlayer: function(t, node) { 444 var domNode, 445 className = '.wp-' + this.shortcode.tag + '-shortcode'; 446 447 this.cleanupPlayer( t ); 448 449 domNode = $( node ).find( this.shortcode.tag + className ).clone(); 450 domNode.removeAttr( 'src style' ); 451 $( node ).find( 'div' + className ).replaceWith( domNode ); 452 }, 453 416 454 /** 417 455 * Creates the player instance for the current node 418 456 * … … 428 466 return; 429 467 } 430 468 431 var self = this, 469 var t, 470 self = this, 432 471 media, 433 472 firefox = this.ua.is( 'ff' ), 434 473 className = '.wp-' + this.shortcode.tag + '-shortcode'; 435 474 436 if ( this.player ) { 437 this.unsetPlayer(); 475 if ( node.reinit && node !== this.lastNode ) { 476 t = _.isArray( this.player ) ? this.player.shift() : this.player; 477 if ( t ) { 478 this.reinitPlayer( t, node ); 479 } 480 } else { 481 if ( this.player.length ) { 482 this.unsetPlayer(); 483 } 438 484 } 439 485 486 this.lastNode = node; 440 487 media = $( node ).find( className ); 441 488 442 489 if ( ! this.isCompatible( media ) ) { … … 458 505 media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); 459 506 460 507 setTimeout( function() { 461 self.player = new MediaElementPlayer( media, this.mejsSettings);508 self.player.push( new MediaElementPlayer( media, this.mejsSettings ) ); 462 509 }, 75 ); 463 510 }, 464 511 -
src/wp-includes/js/media-audiovideo.js
122 122 123 123 return test; 124 124 }, 125 126 125 /** 127 126 * Override the MediaElement method for removing a player. 128 127 * MediaElement tries to pull the audio/video tag out of 129 128 * its container and re-add it to the DOM. 130 129 */ 131 removePlayer: function() { 132 var t = this.player, featureIndex, feature; 133 130 cleanupPlayer: function(t) { 131 var featureIndex, feature; 134 132 // invoke features cleanup 135 133 for ( featureIndex in t.options.features ) { 136 134 feature = t.options.features[featureIndex]; … … 165 163 unsetPlayer : function() { 166 164 if ( this.player ) { 167 165 wp.media.mixin.pauseAllPlayers(); 168 wp.media.mixin.removePlayer.apply( this ); 169 this.player = false; 166 if ( _.isArray( this.player ) ) { 167 _.each( this.player, function ( player ) { 168 wp.media.mixin.cleanupPlayer( player ); 169 } ); 170 this.player = []; 171 } else { 172 wp.media.mixin.cleanupPlayer( this.player ); 173 this.player = false; 174 } 170 175 } 171 176 } 172 177 }; -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
166 166 // to avoid adding additional undo levels on undo/redo 167 167 if ( event.format !== 'raw' ) { 168 168 wp.mce.views.render(); 169 } else { 170 wp.mce.views.reinitializeViews(); 169 171 } 170 172 171 173 // Add padding <p> if the noneditable node is last