wpView: consolidate pausePlayers() and unsetPlayers(), they are almost the same. Prevent errors when instead of a player ME.js shows only a "Download File" placeholder (in IE). See #28905.

Built from https://develop.svn.wordpress.org/trunk@29272


git-svn-id: http://core.svn.wordpress.org/trunk@29054 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-07-22 21:49:16 +00:00
parent 270a57075c
commit c40feac4d9
2 changed files with 17 additions and 22 deletions

View File

@ -504,15 +504,15 @@ window.wp = window.wp || {};
this.shortcode = options.shortcode; this.shortcode = options.shortcode;
_.bindAll( this, 'setIframes', 'setNodes', 'fetch', 'pausePlayers' ); _.bindAll( this, 'setIframes', 'setNodes', 'fetch', 'stopPlayers' );
$( this ).on( 'ready', this.setNodes ); $( this ).on( 'ready', this.setNodes );
$( document ).on( 'media:edit', this.pausePlayers ); $( document ).on( 'media:edit', this.stopPlayers );
this.fetch(); this.fetch();
this.getEditors( function( editor ) { this.getEditors( function( editor ) {
editor.on( 'hide', self.pausePlayers ); editor.on( 'hide', self.stopPlayers );
}); });
}, },
@ -553,35 +553,30 @@ window.wp = window.wp || {};
} ); } );
}, },
pausePlayers: function() { stopPlayers: function( remove ) {
var rem = remove === 'remove';
this.getNodes( function( editor, node, content ) { this.getNodes( function( editor, node, content ) {
var p, win, var p, win,
iframe = $( 'iframe.wpview-sandbox', content ).get(0); iframe = $( 'iframe.wpview-sandbox', content ).get(0);
if ( iframe && ( win = iframe.contentWindow ) && win.mejs ) { if ( iframe && ( win = iframe.contentWindow ) && win.mejs ) {
for ( p in win.mejs.players ) { // Sometimes ME.js may show a "Download File" placeholder and player.remove() doesn't exist there.
win.mejs.players[p].pause(); try {
} for ( p in win.mejs.players ) {
} win.mejs.players[p].pause();
});
},
unsetPlayers: function() { if ( rem ) {
this.getNodes( function( editor, node, content ) { win.mejs.players[p].remove();
var p, win, }
iframe = $( 'iframe.wpview-sandbox', content ).get(0); }
} catch( er ) {}
if ( iframe && ( win = iframe.contentWindow ) && win.mejs ) {
for ( p in win.mejs.players ) {
win.mejs.players[p].remove();
}
} }
}); });
}, },
unbind: function() { unbind: function() {
this.pausePlayers(); this.stopPlayers( 'remove' );
this.unsetPlayers();
} }
}, },

File diff suppressed because one or more lines are too long