+ gallery = _.extend( {}, base, {
+ state: [ 'gallery-edit' ],
+ template: media.template( 'editor-gallery' ),
+
+ initialize: function() {
+ var attachments = media.gallery.attachments( this.shortcode, media.view.settings.post.id ),
+ attrs = this.shortcode.attrs.named,
+ self = this;
+
+ attachments.more()
+ .done( function() {
+ attachments = attachments.toJSON();
+
+ _.each( attachments, function( attachment ) {
+ if ( attachment.sizes ) {
+ if ( attrs.size && attachment.sizes[ attrs.size ] ) {
+ attachment.thumbnail = attachment.sizes[ attrs.size ];
+ } else if ( attachment.sizes.thumbnail ) {
+ attachment.thumbnail = attachment.sizes.thumbnail;
+ } else if ( attachment.sizes.full ) {
+ attachment.thumbnail = attachment.sizes.full;
+ }
+ }
+ } );
+
+ self.render( self.template( {
+ verifyHTML: verifyHTML,
+ attachments: attachments,
+ columns: attrs.columns ? parseInt( attrs.columns, 10 ) : media.galleryDefaults.columns
+ } ) );
+ } )
+ .fail( function( jqXHR, textStatus ) {
+ self.setError( textStatus );
+ } );
+ }
+ } );
+
+ av = _.extend( {}, base, {
+ action: 'parse-media-shortcode',
+
+ initialize: function() {
+ var self = this;
+
+ if ( this.url ) {
+ this.loader = false;
+ this.shortcode = media.embed.shortcode( {
+ url: this.text
+ } );
+ }
+
+ wp.ajax.post( this.action, {
+ post_ID: media.view.settings.post.id,
+ type: this.shortcode.tag,
+ shortcode: this.shortcode.string()
+ } )
+ .done( function( response ) {
+ self.render( response );
+ } )
+ .fail( function( response ) {
+ if ( self.url ) {
+ self.ignore = true;
+ self.removeMarkers();
+ } else {
+ self.setError( response.message || response.statusText, 'admin-media' );
+ }
+ } );
+
+ this.getEditors( function( editor ) {
+ editor.on( 'wpview-selected', function() {
+ self.pausePlayers();
+ } );
+ } );
+ },
+
+ pausePlayers: function() {
+ this.getNodes( function( editor, node, content ) {
+ var win = $( 'iframe.wpview-sandbox', content ).get( 0 );
+
+ if ( win && ( win = win.contentWindow ) && win.mejs ) {
+ _.each( win.mejs.players, function( player ) {
+ try {
+ player.pause();
+ } catch ( e ) {}
+ } );
+ }
+ } );
+ }
+ } );
+
+ embed = _.extend( {}, av, {
+ action: 'parse-embed',
+
+ edit: function( text, update ) {
+ var frame = media.embed.edit( text, this.url ),
+ self = this;
+
+ this.pausePlayers();
+
+ frame.state( 'embed' ).props.on( 'change:url', function( model, url ) {
+ if ( url && model.get( 'url' ) ) {
+ frame.state( 'embed' ).metadata = model.toJSON();
+ }
+ } );
+
+ frame.state( 'embed' ).on( 'select', function() {
+ var data = frame.state( 'embed' ).metadata;
+
+ if ( self.url ) {
+ update( data.url );
+ } else {
+ update( media.embed.shortcode( data ).string() );
+ }
+ } );
+
+ frame.on( 'close', function() {
+ frame.detach();
+ } );
+
+ frame.open();
+ }
+ } );
+
+ views.register( 'gallery', _.extend( {}, gallery ) );
+
+ views.register( 'audio', _.extend( {}, av, {
+ state: [ 'audio-details' ]
+ } ) );
+
+ views.register( 'video', _.extend( {}, av, {
+ state: [ 'video-details' ]
+ } ) );
+
+ views.register( 'playlist', _.extend( {}, av, {
+ state: [ 'playlist-edit', 'video-playlist-edit' ]
+ } ) );
+
+ views.register( 'embed', _.extend( {}, embed ) );
+
+ views.register( 'embedURL', _.extend( {}, embed, {
+ match: function( content ) {
+ var re = /(^|<p>)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,
+ match = re.exec( content );
+
+ if ( match ) {
+ return {
+ index: match.index + match[1].length,
+ content: match[2],
+ options: {
+ url: true
+ }
+ };
+ }
+ }
+ } ) );
+} )( window, window.wp.mce.views, window.wp.media, window.jQuery );