From c2bd765b3294f27ba0da914f52b826d9a0ed6879 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 22 Jul 2014 21:48:41 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@29272 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/mce-view.js | 37 +++++++++++++++------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 56a858307a..fa1ed4402b 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -504,15 +504,15 @@ window.wp = window.wp || {}; this.shortcode = options.shortcode; - _.bindAll( this, 'setIframes', 'setNodes', 'fetch', 'pausePlayers' ); + _.bindAll( this, 'setIframes', 'setNodes', 'fetch', 'stopPlayers' ); $( this ).on( 'ready', this.setNodes ); - $( document ).on( 'media:edit', this.pausePlayers ); + $( document ).on( 'media:edit', this.stopPlayers ); this.fetch(); 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 ) { var p, win, iframe = $( 'iframe.wpview-sandbox', content ).get(0); if ( iframe && ( win = iframe.contentWindow ) && win.mejs ) { - for ( p in win.mejs.players ) { - win.mejs.players[p].pause(); - } - } - }); - }, + // Sometimes ME.js may show a "Download File" placeholder and player.remove() doesn't exist there. + try { + for ( p in win.mejs.players ) { + win.mejs.players[p].pause(); - unsetPlayers: function() { - this.getNodes( function( editor, node, content ) { - var p, win, - iframe = $( 'iframe.wpview-sandbox', content ).get(0); - - if ( iframe && ( win = iframe.contentWindow ) && win.mejs ) { - for ( p in win.mejs.players ) { - win.mejs.players[p].remove(); - } + if ( rem ) { + win.mejs.players[p].remove(); + } + } + } catch( er ) {} } }); }, unbind: function() { - this.pausePlayers(); - this.unsetPlayers(); + this.stopPlayers( 'remove' ); } },