Make WordPress Core

Changeset 27537


Ignore:
Timestamp:
03/14/2014 01:16:07 PM (12 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-editor.js

    r27530 r27537  
    297297                        }
    298298                        return attrs[ key ];
     299                },
     300
     301                pauseAllPlayers: function () {
     302                        var p;
     303                        if ( window.mejs && window.mejs.players ) {
     304                                for ( p in window.mejs.players ) {
     305                                        window.mejs.players[p].pause();
     306                                }
     307                        }
    299308                }
    300309        };
     
    303312                var collections = {};
    304313
    305                 return _.extend( attributes, wp.media.mixin, {
     314                return _.extend( attributes, {
     315                        coerce : wp.media.mixin.coerce,
    306316                        /**
    307317                         * Retrieve attachments based on the properties of the passed shortcode
     
    559569         * @namespace
    560570         */
    561         wp.media.audio = _.extend({
     571        wp.media.audio = {
     572                coerce : wp.media.mixin.coerce,
     573
    562574                defaults : {
    563575                        id : wp.media.view.settings.post.id,
     
    598610                        });
    599611                }
    600         }, wp.media.mixin);
     612        };
    601613
    602614        /**
    603615         * @namespace
    604616         */
    605         wp.media.video = _.extend({
     617        wp.media.video = {
     618                coerce : wp.media.mixin.coerce,
     619
    606620                defaults : {
    607621                        id : wp.media.view.settings.post.id,
     
    650664                        });
    651665                }
    652         }, wp.media.mixin);
     666        };
    653667
    654668        /**
     
    11121126                 */
    11131127                init: function() {
    1114                         $(document.body).on( 'click', '.insert-media', function( event ) {
    1115                                 var elem = $( event.currentTarget ),
    1116                                         editor = elem.data('editor'),
    1117                                         options = {
    1118                                                 frame:    'post',
    1119                                                 state:    'insert',
    1120                                                 title:    wp.media.view.l10n.addMedia,
    1121                                                 multiple: true
    1122                                         };
    1123 
    1124                                 event.preventDefault();
    1125 
    1126                                 // Remove focus from the `.insert-media` button.
    1127                                 // Prevents Opera from showing the outline of the button
    1128                                 // above the modal.
    1129                                 //
    1130                                 // See: http://core.trac.wordpress.org/ticket/22445
    1131                                 elem.blur();
    1132 
    1133                                 if ( elem.hasClass( 'gallery' ) ) {
    1134                                         options.state = 'gallery';
    1135                                         options.title = wp.media.view.l10n.createGalleryTitle;
    1136                                 } else if ( elem.hasClass( 'playlist' ) ) {
    1137                                         options.state = 'playlist';
    1138                                         options.title = wp.media.view.l10n.createPlaylistTitle;
    1139                                 } else if ( elem.hasClass( 'video-playlist' ) ) {
    1140                                         options.state = 'video-playlist';
    1141                                         options.title = wp.media.view.l10n.createVideoPlaylistTitle;
    1142                                 }
    1143 
    1144                                 wp.media.editor.open( editor, options );
    1145                         });
     1128                        $(document.body)
     1129                                .on( 'click', '.insert-media', function( event ) {
     1130                                        var elem = $( event.currentTarget ),
     1131                                                editor = elem.data('editor'),
     1132                                                options = {
     1133                                                        frame:    'post',
     1134                                                        state:    'insert',
     1135                                                        title:    wp.media.view.l10n.addMedia,
     1136                                                        multiple: true
     1137                                                };
     1138
     1139                                        event.preventDefault();
     1140
     1141                                        // Remove focus from the `.insert-media` button.
     1142                                        // Prevents Opera from showing the outline of the button
     1143                                        // above the modal.
     1144                                        //
     1145                                        // See: http://core.trac.wordpress.org/ticket/22445
     1146                                        elem.blur();
     1147
     1148                                        if ( elem.hasClass( 'gallery' ) ) {
     1149                                                options.state = 'gallery';
     1150                                                options.title = wp.media.view.l10n.createGalleryTitle;
     1151                                        } else if ( elem.hasClass( 'playlist' ) ) {
     1152                                                options.state = 'playlist';
     1153                                                options.title = wp.media.view.l10n.createPlaylistTitle;
     1154                                        } else if ( elem.hasClass( 'video-playlist' ) ) {
     1155                                                options.state = 'video-playlist';
     1156                                                options.title = wp.media.view.l10n.createVideoPlaylistTitle;
     1157                                        }
     1158
     1159                                        wp.media.editor.open( editor, options );
     1160                                })
     1161                                .on( 'click', '.wp-switch-editor', wp.media.mixin.pauseAllPlayers );
    11461162
    11471163                        // Initialize and render the Editor drag-and-drop uploader.
Note: See TracChangeset for help on using the changeset viewer.