- if ( 'video' === data.type ) {
- size.width = attachment.width;
- size.height = attachment.height;
- if ( media.view.settings.contentWidth ) {
- resize.width = media.view.settings.contentWidth - 22;
- resize.height = Math.ceil( ( size.height * resize.width ) / size.width );
- if ( ! options.width ) {
- options.width = resize.width;
- options.height = resize.height;
- }
- } else {
- if ( ! options.width ) {
- options.width = attachment.width;
- options.height = attachment.height;
+ /**
+ * Remove a given view node from the DOM.
+ *
+ * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
+ * @param {HTMLElement} node The view node to remove.
+ */
+ remove: function( editor, node ) {
+ this.unbindNode.call( this, editor, node, $( node ).find( '.wpview-content' ).get( 0 ) );
+ $( node ).trigger( 'wp-mce-view-unbind' );
+ editor.dom.remove( node );
+ editor.focus();
+ }
+ } );
+} )( window, window.wp, window.wp.shortcode, window.jQuery );
+
+/*
+ * The WordPress core TinyMCE views.
+ * Views for the gallery, audio, video, playlist and embed shortcodes,
+ * and a view for embeddable URLs.
+ */
+( function( window, views, media, $ ) {
+ var base, gallery, av, embed,
+ schema, parser, serializer;
+
+ function verifyHTML( string ) {
+ var settings = {};
+
+ if ( ! window.tinymce ) {
+ return string.replace( /<[^>]+>/g, '' );
+ }
+
+ if ( ! string || ( string.indexOf( '<' ) === -1 && string.indexOf( '>' ) === -1 ) ) {
+ return string;
+ }
+
+ schema = schema || new window.tinymce.html.Schema( settings );
+ parser = parser || new window.tinymce.html.DomParser( settings, schema );
+ serializer = serializer || new window.tinymce.html.Serializer( settings, schema );
+
+ return serializer.serialize( parser.parse( string, { forced_root_block: false } ) );
+ }
+
+ base = {
+ state: [],
+
+ edit: function( text, update ) {
+ var type = this.type,
+ frame = media[ type ].edit( text );
+
+ this.pausePlayers && this.pausePlayers();
+
+ _.each( this.state, function( state ) {
+ frame.state( state ).on( 'update', function( selection ) {
+ update( media[ type ].shortcode( selection ).string(), type === 'gallery' );
+ } );
+ } );
+
+ frame.on( 'close', function() {
+ frame.detach();
+ } );
+
+ frame.open();
+ }
+ };
+
+ 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;