Ticket #27389: 27389-why-god-why.diff
File 27389-why-god-why.diff, 5.1 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 featureIndex, feature, domNode, 445 className = '.wp-' + this.shortcode.tag + '-shortcode'; 446 447 // invoke features cleanup 448 for ( featureIndex in t.options.features ) { 449 feature = t.options.features[featureIndex]; 450 if ( t['clean' + feature] ) { 451 try { 452 t['clean' + feature](t); 453 } catch (e) {} 454 } 455 } 456 457 if ( ! t.isDynamic ) { 458 domNode = $( node ).find( this.shortcode.tag + className ).clone(); 459 domNode.removeAttr( 'src style' ); 460 _.each( domNode.find( 'source' ), function (source) { 461 source.src = source.src.replace(/_=\d+&?/, ''); 462 } ); 463 $( node ).find( 'div' + className ).replaceWith( domNode ); 464 } 465 466 if ( 'native' !== t.media.pluginType ) { 467 t.media.remove(); 468 } 469 470 delete window.mejs.players[t.id]; 471 472 t.container.remove(); 473 t.globalUnbind(); 474 delete t.node.player; 475 }, 476 416 477 /** 417 478 * Creates the player instance for the current node 418 479 * … … 428 489 return; 429 490 } 430 491 431 var self = this, 492 var t, 493 self = this, 432 494 media, 433 495 firefox = this.ua.is( 'ff' ), 434 496 className = '.wp-' + this.shortcode.tag + '-shortcode'; 435 497 436 if ( this.player ) { 437 this.unsetPlayer(); 498 if ( node.reinit && node !== this.lastNode ) { 499 t = _.isArray( this.player ) ? this.player.shift() : this.player; 500 if ( t ) { 501 this.reinitPlayer( t, node ); 502 } 503 } else { 504 if ( this.player.length ) { 505 this.unsetPlayer(); 506 } 438 507 } 439 508 509 this.lastNode = node; 440 510 media = $( node ).find( className ); 441 511 442 512 if ( ! this.isCompatible( media ) ) { … … 458 528 media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); 459 529 460 530 setTimeout( function() { 461 self.player = new MediaElementPlayer( media, this.mejsSettings);531 self.player.push( new MediaElementPlayer( media, this.mejsSettings ) ); 462 532 }, 75 ); 463 533 }, 464 534 -
src/wp-includes/js/media-audiovideo.js
128 128 * MediaElement tries to pull the audio/video tag out of 129 129 * its container and re-add it to the DOM. 130 130 */ 131 removePlayer: function( ) {132 var t = this.player, featureIndex, feature;131 removePlayer: function(player) { 132 var t = player || this.player, featureIndex, feature; 133 133 134 134 // invoke features cleanup 135 135 for ( featureIndex in t.options.features ) { … … 165 165 unsetPlayer : function() { 166 166 if ( this.player ) { 167 167 wp.media.mixin.pauseAllPlayers(); 168 wp.media.mixin.removePlayer.apply( this ); 169 this.player = false; 168 if ( _.isArray( this.player ) ) { 169 _.each( this.player, function ( player ) { 170 wp.media.mixin.removePlayer( player ); 171 } ); 172 this.player = []; 173 } else { 174 wp.media.mixin.removePlayer.apply( this ); 175 this.player = false; 176 } 170 177 } 171 178 } 172 179 }; -
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