diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index c578619357..05ff0453e3 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -364,7 +364,7 @@ window.wp = window.wp || {}; edit: function( node ) { var media = wp.media[ this.shortcode ], self = this, - frame, data; + frame, data, callback; wp.media.mixin.pauseAllPlayers(); @@ -373,12 +373,20 @@ window.wp = window.wp || {}; frame.on( 'close', function() { frame.detach(); } ); - frame.state( self.state ).on( 'update', function( selection ) { + + callback = function( selection ) { var shortcode = wp.media[ self.shortcode ].shortcode( selection ).string(); $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); wp.mce.views.refreshView( self, shortcode ); frame.detach(); - } ); + }; + if ( _.isArray( self.state ) ) { + _.each( self.state, function (state) { + frame.state( state ).on( 'update', callback ); + } ); + } else { + frame.state( self.state ).on( 'update', callback ); + } frame.open(); } }; @@ -531,7 +539,7 @@ window.wp = window.wp || {}; * Asynchronously fetch the shortcode's attachments */ fetch: function() { - this.attachments = wp.media[ this.shortcode.tag ].attachments( this.shortcode ); + this.attachments = wp.media.playlist.attachments( this.shortcode ); this.attachments.more().done( this.setPlayer ); }, @@ -579,8 +587,7 @@ window.wp = window.wp || {}; */ getHtml: function() { var data = this.shortcode.attrs.named, - model = wp.media[ this.shortcode.tag ], - type = 'playlist' === this.shortcode.tag ? 'audio' : 'video', + model = wp.media.playlist, options, attachments, tracks = []; @@ -596,7 +603,7 @@ window.wp = window.wp || {}; attachments = this.attachments.toJSON(); options = { - type: type, + type: data.type, style: data.style, tracklist: data.tracklist, tracknumbers: data.tracknumbers, @@ -614,7 +621,7 @@ window.wp = window.wp || {}; meta : attachment.meta }; - if ( 'video' === type ) { + if ( 'video' === data.type ) { size.width = attachment.width; size.height = attachment.height; if ( media.view.settings.contentWidth ) { @@ -659,20 +666,8 @@ window.wp = window.wp || {}; */ wp.mce.playlist = _.extend( {}, wp.mce.media, { shortcode: 'playlist', - state: 'playlist-edit', + state: ['playlist-edit', 'video-playlist-edit'], View: wp.mce.media.PlaylistView } ); wp.mce.views.register( 'playlist', wp.mce.playlist ); - - /** - * TinyMCE handler for the video-playlist shortcode - * - * @mixes wp.mce.media - */ - wp.mce['video-playlist'] = _.extend( {}, wp.mce.media, { - shortcode: 'video-playlist', - state: 'video-playlist-edit', - View: wp.mce.media.PlaylistView - } ); - wp.mce.views.register( 'video-playlist', wp.mce['video-playlist'] ); }(jQuery)); diff --git a/src/wp-includes/js/media-audiovideo.js b/src/wp-includes/js/media-audiovideo.js index 0993b2c2f3..7462ae117d 100644 --- a/src/wp-includes/js/media-audiovideo.js +++ b/src/wp-includes/js/media-audiovideo.js @@ -176,7 +176,6 @@ */ wp.media.playlist = new wp.media.collection({ tag: 'playlist', - type : 'audio', editTitle : l10n.editPlaylistTitle, defaults : { id: wp.media.view.settings.post.id, @@ -184,20 +183,8 @@ tracklist: true, tracknumbers: true, images: true, - artists: true - } - }); - - wp.media['video-playlist'] = new wp.media.collection({ - tag: 'video-playlist', - type : 'video', - editTitle : l10n.editVideoPlaylistTitle, - defaults : { - id: wp.media.view.settings.post.id, - style: 'light', - tracklist: false, - tracknumbers: false, - images: true + artists: true, + type: 'audio' } }); @@ -953,96 +940,10 @@ counts.audio = a; counts.video = v; - + return counts; }; - }(media.view.settings)), - - /** - * Return the playlist states for MediaFrame.Post - * - * @param {Object} options - * @returns {Array} - */ - states : function(options) { - return [ - new media.controller.Library({ - id: 'playlist', - title: l10n.createPlaylistTitle, - priority: 60, - toolbar: 'main-playlist', - filterable: 'uploaded', - multiple: 'add', - editable: false, - - library: media.query( _.defaults({ - type: 'audio' - }, options.library ) ) - }), - - // Playlist states. - new media.controller.CollectionEdit({ - type: 'audio', - collectionType: 'playlist', - title: l10n.editPlaylistTitle, - SettingsView: media.view.Settings.Playlist, - library: options.selection, - editing: options.editing, - menu: 'playlist', - dragInfoText: l10n.playlistDragInfo, - dragInfo: false - }), - - new media.controller.CollectionAdd({ - type: 'audio', - collectionType: 'playlist', - title: l10n.addToPlaylistTitle - }) - ]; - }, - - /** - * Return the video-playlist states for MediaFrame.Post - * - * @param {Object} options - * @returns {Array} - */ - videoStates : function(options) { - return [ - new media.controller.Library({ - id: 'video-playlist', - title: l10n.createVideoPlaylistTitle, - priority: 60, - toolbar: 'main-video-playlist', - filterable: 'uploaded', - multiple: 'add', - editable: false, - - library: media.query( _.defaults({ - type: 'video' - }, options.library ) ) - }), - - // Video Playlist states. - new media.controller.CollectionEdit({ - type: 'video', - collectionType: 'video-playlist', - title: l10n.editVideoPlaylistTitle, - SettingsView: media.view.Settings.Playlist, - library: options.selection, - editing: options.editing, - menu: 'video-playlist', - dragInfoText: l10n.videoPlaylistDragInfo, - dragInfo: false - }), - - new media.controller.CollectionAdd({ - type: 'video', - collectionType: 'video-playlist', - title: l10n.addToVideoPlaylistTitle - }) - ]; - } + }(media.view.settings)) } ); /** diff --git a/src/wp-includes/js/media-editor.js b/src/wp-includes/js/media-editor.js index b65a499b19..293d7f8060 100644 --- a/src/wp-includes/js/media-editor.js +++ b/src/wp-includes/js/media-editor.js @@ -405,6 +405,11 @@ attrs = _.pick( props, 'orderby', 'order' ), shortcode, clone, self = this; + if ( attachments.type ) { + attrs.type = attachments.type; + delete attachments.type; + } + if ( attachments[this.tag] ) { _.extend( attrs, attachments[this.tag].toJSON() ); } @@ -477,7 +482,7 @@ edit: function( content ) { var shortcode = wp.shortcode.next( this.tag, content ), defaultPostId = this.defaults.id, - attachments, selection; + attachments, selection, state; // Bail if we didn't match the shortcode or all of the content. if ( ! shortcode || shortcode.content !== content ) { @@ -514,10 +519,16 @@ this.frame.dispose(); } - // Store the current gallery frame. + if ( shortcode.attrs.named.type && 'video' === shortcode.attrs.named.type ) { + state = 'video-' + this.tag + '-edit'; + } else { + state = this.tag + '-edit'; + } + + // Store the current frame. this.frame = wp.media({ frame: 'post', - state: this.tag + '-edit', + state: state, title: this.editTitle, editing: true, multiple: true, @@ -786,7 +797,7 @@ /** * @this wp.media.editor */ - this.insert( wp.media['video-playlist'].shortcode( selection ).string() ); + this.insert( wp.media.playlist.shortcode( selection ).string() ); }, this ); workflow.state('embed').on( 'select', function() { diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index fd40f31579..4ff825ac2f 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -793,6 +793,10 @@ initialize: function() { var collectionType = this.get('collectionType'); + if ( 'video' === this.get( 'type' ) ) { + collectionType = 'video-' + collectionType; + } + this.set( 'id', collectionType + '-edit' ); this.set( 'toolbar', collectionType + '-edit' ); @@ -1886,7 +1890,7 @@ }, createStates: function() { - var options = this.options, counts; + var options = this.options; // Add the default states. this.states.add([ @@ -1946,19 +1950,74 @@ type: 'image', collectionType: 'gallery', title: l10n.addToGalleryTitle + }), + + new media.controller.Library({ + id: 'playlist', + title: l10n.createPlaylistTitle, + priority: 60, + toolbar: 'main-playlist', + filterable: 'uploaded', + multiple: 'add', + editable: false, + + library: media.query( _.defaults({ + type: 'audio' + }, options.library ) ) + }), + + // Playlist states. + new media.controller.CollectionEdit({ + type: 'audio', + collectionType: 'playlist', + title: l10n.editPlaylistTitle, + SettingsView: media.view.Settings.Playlist, + library: options.selection, + editing: options.editing, + menu: 'playlist', + dragInfoText: l10n.playlistDragInfo, + dragInfo: false + }), + + new media.controller.CollectionAdd({ + type: 'audio', + collectionType: 'playlist', + title: l10n.addToPlaylistTitle + }), + + new media.controller.Library({ + id: 'video-playlist', + title: l10n.createVideoPlaylistTitle, + priority: 60, + toolbar: 'main-video-playlist', + filterable: 'uploaded', + multiple: 'add', + editable: false, + + library: media.query( _.defaults({ + type: 'video' + }, options.library ) ) + }), + + new media.controller.CollectionEdit({ + type: 'video', + collectionType: 'playlist', + title: l10n.editVideoPlaylistTitle, + SettingsView: media.view.Settings.Playlist, + library: options.selection, + editing: options.editing, + menu: 'video-playlist', + dragInfoText: l10n.playlistDragInfo, + dragInfo: false + }), + + new media.controller.CollectionAdd({ + type: 'video', + collectionType: 'playlist', + title: l10n.addToVideoPlaylistTitle }) ]); - counts = media.playlist.counts(); - - if ( counts.audio ) { - this.states.add( media.playlist.states(options) ); - } - - if ( counts.video ) { - this.states.add( media.playlist.videoStates(options) ); - } - if ( media.view.settings.post.featuredImageId ) { this.states.add( new media.controller.FeaturedImage() ); } @@ -2422,10 +2481,13 @@ click: function() { var controller = this.controller, - state = controller.state(); + state = controller.state(), + library = state.get('library'); + + library.type = 'video'; controller.close(); - state.trigger( 'update', state.get('library') ); + state.trigger( 'update', library ); // Restore and reset the default state. controller.setState( controller.options.state ); diff --git a/src/wp-includes/js/mediaelement/wp-mediaelement.js b/src/wp-includes/js/mediaelement/wp-mediaelement.js index 2e22dc07ce..72ea6bde31 100644 --- a/src/wp-includes/js/mediaelement/wp-mediaelement.js +++ b/src/wp-includes/js/mediaelement/wp-mediaelement.js @@ -7,6 +7,10 @@ $(function () { var settings = {}; + if ( $( document.body ).hasClass( 'mce-content-body' ) ) { + return; + } + if ( typeof _wpmejsSettings !== 'undefined' ) { settings.pluginPath = _wpmejsSettings.pluginPath; } diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php index 31913365ae..0516d06d57 100644 --- a/src/wp-includes/media-template.php +++ b/src/wp-includes/media-template.php @@ -517,53 +517,25 @@ function wp_print_media_templates() {