Ticket #27389: 27389.10.diff
File 27389.10.diff, 6.0 KB (added by , 11 years ago) |
---|
-
src/wp-includes/js/mce-view.js
41 41 doc = editor.getDoc(); 42 42 $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { 43 43 var node = $( elem ); 44 node.html( html ); 44 // The <ins> is used to mark the end of the wrapper div. Needed when comparing 45 // the content as string for preventing extra undo levels. 46 node.html( html ).append( '<ins data-wpview-end="1"></ins>' ); 45 47 $( self ).trigger( 'ready', elem ); 46 48 }); 47 49 } 48 50 }, this ); 49 } 51 }, 52 unbind: function() {} 50 53 } ); 51 54 52 55 // take advantage of the Backbone extend method … … 93 96 }, 94 97 95 98 /** 99 * wp.mce.views.unbind( editor ) 100 * 101 * The editor DOM is being rebuilt, run cleanup. 102 */ 103 unbind: function() { 104 _.each( instances, function( instance ) { 105 instance.unbind(); 106 } ); 107 }, 108 109 /** 96 110 * toViews( content ) 97 111 * Scans a `content` string for each view's pattern, replacing any 98 112 * matches with wrapper elements, and creates a new instance for … … 339 353 * @mixin 340 354 */ 341 355 wp.mce.media = { 356 loaded: false, 342 357 /** 343 358 * @global wp.shortcode 344 359 * … … 410 425 */ 411 426 wp.mce.media.View = wp.mce.View.extend({ 412 427 initialize: function( options ) { 428 this.players = []; 413 429 this.shortcode = options.shortcode; 414 430 _.bindAll( this, 'setPlayer' ); 415 431 $(this).on( 'ready', this.setPlayer ); … … 460 476 media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); 461 477 462 478 setTimeout( function() { 463 self.player = new MediaElementPlayer( media, this.mejsSettings ); 464 }, 75 ); 479 wp.mce.media.loaded = true; 480 self.players.push( new MediaElementPlayer( media, self.mejsSettings ) ); 481 }, wp.mce.media.loaded ? 10 : 500 ); 465 482 }, 466 483 467 484 /** … … 475 492 wp.media[ this.shortcode.tag ].defaults 476 493 ); 477 494 return this.template({ model: attrs }); 495 }, 496 497 unbind: function() { 498 var self = this; 499 this.pauseAllPlayers(); 500 _.each( this.players, function (player) { 501 self.removePlayer( player ); 502 } ); 503 this.players = []; 478 504 } 479 505 }); 480 506 _.extend( wp.mce.media.View.prototype, wp.media.mixin ); -
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(t) { 132 var 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);168 wp.media.mixin.removePlayer( this.player ); 169 169 this.player = false; 170 170 } 171 171 } … … 914 914 915 915 $( init ); 916 916 917 }(jQuery, _, Backbone)); 918 No newline at end of file 917 }(jQuery, _, Backbone)); -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
80 80 'contenteditable': 'true' 81 81 }, getViewText( viewNode ) ); 82 82 83 viewNode.appendChild( clipboard ); 83 // Prepend inside the wrapper 84 viewNode.insertBefore( clipboard, viewNode.firstChild ); 84 85 85 86 // Both of the following are necessary to prevent manipulating the selection/focus 86 editor.dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );87 editor.dom.bind( selected, 'beforedeactivate focusin focusout', _stop );87 dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop ); 88 dom.bind( selected, 'beforedeactivate focusin focusout', _stop ); 88 89 89 90 // Make sure that the editor is focused. 90 91 // It is possible that the editor is not focused when the mouse event fires … … 140 141 return; 141 142 } 142 143 144 // Remove the content of view wrappers from HTML string 145 function emptyViews( content ) { 146 return content.replace(/(<div[^>]+wpview-wrap[^>]+>)[\s\S]+?data-wpview-end[^>]*><\/ins><\/div>/g, '$1</div>' ); 147 } 148 149 // Prevent adding undo levels on changes inside a view wrapper 143 150 editor.on( 'BeforeAddUndo', function( event ) { 144 if ( selected && ! toRemove) {151 if ( event.lastLevel && emptyViews( event.level.content ) === emptyViews( event.lastLevel.content ) ) { 145 152 event.preventDefault(); 146 153 } 147 154 }); … … 149 156 // When the editor's content changes, scan the new content for 150 157 // matching view patterns, and transform the matches into 151 158 // view wrappers. 152 editor.on( 'BeforeSetContent', function( e ) {153 if ( ! e .content ) {159 editor.on( 'BeforeSetContent', function( event ) { 160 if ( ! event.content ) { 154 161 return; 155 162 } 156 163 157 e.content = wp.mce.views.toViews( e.content ); 164 if ( ! event.initial ) { 165 wp.mce.views.unbind( editor ); 166 } 167 168 event.content = wp.mce.views.toViews( event.content ); 158 169 }); 159 170 160 171 // When the editor's content has been updated and the DOM has been … … 162 173 editor.on( 'SetContent', function( event ) { 163 174 var body, padNode; 164 175 165 // don't (re-)render views if the format of the content is raw 166 // to avoid adding additional undo levels on undo/redo 167 if ( event.format !== 'raw' ) { 168 wp.mce.views.render(); 169 } 176 wp.mce.views.render(); 170 177 171 178 // Add padding <p> if the noneditable node is last 172 179 if ( event.load || ! event.set ) { … … 175 182 if ( isView( body.lastChild ) ) { 176 183 padNode = createPadNode(); 177 184 body.appendChild( padNode ); 178 editor.selection.setCursorLocation( padNode, 0 ); 185 186 if ( ! event.initial ) { 187 editor.selection.setCursorLocation( padNode, 0 ); 188 } 179 189 } 180 190 } 181 191 });