From 3d244e1fed3a73a6099c2f94b1562ae61b96f47e Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 14 Mar 2014 13:16:07 +0000 Subject: [PATCH] Rather than extending `wp.media.mixin`, only borrow `coerce` when necessary in `wp.media.audio|video|collection`. `wp.media.mixin` will make sense to be mixed in for classes that expect to interact with the player. More universal methods can be added and inherited by all those who extend their prototype with it. Assuming someone had implemented players in the editor, pause all players when switching between editor tabs. A method, `pauseAllPlayers`, has been added to `wp.media.mixin`. See #27389. git-svn-id: https://develop.svn.wordpress.org/trunk@27537 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-editor.js | 82 ++++++++++++++++++------------ 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/src/wp-includes/js/media-editor.js b/src/wp-includes/js/media-editor.js index bdb72abb32..1f3208a23b 100644 --- a/src/wp-includes/js/media-editor.js +++ b/src/wp-includes/js/media-editor.js @@ -296,13 +296,23 @@ attrs[ key ] = false; } return attrs[ key ]; + }, + + pauseAllPlayers: function () { + var p; + if ( window.mejs && window.mejs.players ) { + for ( p in window.mejs.players ) { + window.mejs.players[p].pause(); + } + } } }; wp.media.collection = function(attributes) { var collections = {}; - return _.extend( attributes, wp.media.mixin, { + return _.extend( attributes, { + coerce : wp.media.mixin.coerce, /** * Retrieve attachments based on the properties of the passed shortcode * @@ -558,7 +568,9 @@ /** * @namespace */ - wp.media.audio = _.extend({ + wp.media.audio = { + coerce : wp.media.mixin.coerce, + defaults : { id : wp.media.view.settings.post.id, src : '', @@ -597,12 +609,14 @@ attrs: shortcode }); } - }, wp.media.mixin); + }; /** * @namespace */ - wp.media.video = _.extend({ + wp.media.video = { + coerce : wp.media.mixin.coerce, + defaults : { id : wp.media.view.settings.post.id, src : '', @@ -649,7 +663,7 @@ content: content }); } - }, wp.media.mixin); + }; /** * wp.media.featuredImage @@ -1111,38 +1125,40 @@ * @global wp.media.view.l10n */ init: function() { - $(document.body).on( 'click', '.insert-media', function( event ) { - var elem = $( event.currentTarget ), - editor = elem.data('editor'), - options = { - frame: 'post', - state: 'insert', - title: wp.media.view.l10n.addMedia, - multiple: true - }; + $(document.body) + .on( 'click', '.insert-media', function( event ) { + var elem = $( event.currentTarget ), + editor = elem.data('editor'), + options = { + frame: 'post', + state: 'insert', + title: wp.media.view.l10n.addMedia, + multiple: true + }; - event.preventDefault(); + event.preventDefault(); - // Remove focus from the `.insert-media` button. - // Prevents Opera from showing the outline of the button - // above the modal. - // - // See: http://core.trac.wordpress.org/ticket/22445 - elem.blur(); + // Remove focus from the `.insert-media` button. + // Prevents Opera from showing the outline of the button + // above the modal. + // + // See: http://core.trac.wordpress.org/ticket/22445 + elem.blur(); - if ( elem.hasClass( 'gallery' ) ) { - options.state = 'gallery'; - options.title = wp.media.view.l10n.createGalleryTitle; - } else if ( elem.hasClass( 'playlist' ) ) { - options.state = 'playlist'; - options.title = wp.media.view.l10n.createPlaylistTitle; - } else if ( elem.hasClass( 'video-playlist' ) ) { - options.state = 'video-playlist'; - options.title = wp.media.view.l10n.createVideoPlaylistTitle; - } + if ( elem.hasClass( 'gallery' ) ) { + options.state = 'gallery'; + options.title = wp.media.view.l10n.createGalleryTitle; + } else if ( elem.hasClass( 'playlist' ) ) { + options.state = 'playlist'; + options.title = wp.media.view.l10n.createPlaylistTitle; + } else if ( elem.hasClass( 'video-playlist' ) ) { + options.state = 'video-playlist'; + options.title = wp.media.view.l10n.createVideoPlaylistTitle; + } - wp.media.editor.open( editor, options ); - }); + wp.media.editor.open( editor, options ); + }) + .on( 'click', '.wp-switch-editor', wp.media.mixin.pauseAllPlayers ); // Initialize and render the Editor drag-and-drop uploader. new wp.media.view.EditorUploader().render();