]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/mce-view.js
WordPress 4.1-scripts
[autoinstalls/wordpress.git] / wp-includes / js / mce-view.js
index 85484ef42b9eb3307b17556a88be1b6691e497fd..da1ce6aed2c4c99f1bad6c59caca548a8eec9fd3 100644 (file)
@@ -14,6 +14,9 @@ window.wp = window.wp || {};
        var views = {},
                instances = {},
                media = wp.media,
+               mediaWindows = [],
+               windowIdx = 0,
+               waitInterval = 50,
                viewOptions = ['encodedText'];
 
        // Create the `wp.mce` object if necessary.
@@ -53,9 +56,9 @@ window.wp = window.wp || {};
                                this.setContent(
                                        '<p class="wpview-selection-before">\u00a0</p>' +
                                        '<div class="wpview-body" contenteditable="false">' +
-                                               '<div class="toolbar">' +
+                                               '<div class="toolbar mce-arrow-down">' +
                                                        ( _.isFunction( views[ this.type ].edit ) ? '<div class="dashicons dashicons-edit edit"></div>' : '' ) +
-                                                       '<div class="dashicons dashicons-no-alt remove"></div>' +
+                                                       '<div class="dashicons dashicons-no remove"></div>' +
                                                '</div>' +
                                                '<div class="wpview-content wpview-type-' + this.type + '">' +
                                                        ( this.getHtml() || this.loadingPlaceholder() ) +
@@ -228,7 +231,7 @@ window.wp = window.wp || {};
                                                                iframeDoc.body.className = editor.getBody().className;
                                                        });
                                                }
-                                       }, 50 );
+                                       }, waitInterval );
                                });
                        } else {
                                this.setContent( body );
@@ -437,8 +440,9 @@ window.wp = window.wp || {};
                 *
                 * @param view {object} being refreshed
                 * @param text {string} textual representation of the view
+                * @param force {Boolean} whether to force rendering
                 */
-               refreshView: function( view, text ) {
+               refreshView: function( view, text, force ) {
                        var encodedText = window.encodeURIComponent( text ),
                                viewOptions,
                                result, instance;
@@ -454,7 +458,7 @@ window.wp = window.wp || {};
                                instances[ encodedText ] = instance;
                        }
 
-                       instance.render();
+                       instance.render( force );
                },
 
                getInstance: function( encodedText ) {
@@ -525,7 +529,9 @@ window.wp = window.wp || {};
 
                                        _.each( attachments, function( attachment ) {
                                                if ( attachment.sizes ) {
-                                                       if ( attachment.sizes.thumbnail ) {
+                                                       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;
@@ -552,9 +558,10 @@ window.wp = window.wp || {};
                        frame = gallery.edit( data );
 
                        frame.state('gallery-edit').on( 'update', function( selection ) {
-                               var shortcode = gallery.shortcode( selection ).string();
+                               var shortcode = gallery.shortcode( selection ).string(), force;
                                $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) );
-                               wp.mce.views.refreshView( self, shortcode );
+                               force = ( data !== shortcode );
+                               wp.mce.views.refreshView( self, shortcode, force );
                        });
 
                        frame.on( 'close', function() {
@@ -587,13 +594,68 @@ window.wp = window.wp || {};
                                this.fetch();
 
                                this.getEditors( function( editor ) {
-                                       editor.on( 'hide', self.stopPlayers );
+                                       editor.on( 'hide', function () {
+                                               mediaWindows = [];
+                                               windowIdx = 0;
+                                               self.stopPlayers();
+                                       } );
                                });
                        },
 
+                       pauseOtherWindows: function ( win ) {
+                               _.each( mediaWindows, function ( mediaWindow ) {
+                                       if ( mediaWindow.sandboxId !== win.sandboxId ) {
+                                               _.each( mediaWindow.mejs.players, function ( player ) {
+                                                       player.pause();
+                                               } );
+                                       }
+                               } );
+                       },
+
+                       iframeLoaded: function (win) {
+                               return _.bind( function () {
+                                       var callback;
+                                       if ( ! win.mejs || _.isEmpty( win.mejs.players ) ) {
+                                               return;
+                                       }
+
+                                       win.sandboxId = windowIdx;
+                                       windowIdx++;
+                                       mediaWindows.push( win );
+
+                                       callback = _.bind( function () {
+                                               this.pauseOtherWindows( win );
+                                       }, this );
+
+                                       if ( ! _.isEmpty( win.mejs.MediaPluginBridge.pluginMediaElements ) ) {
+                                               _.each( win.mejs.MediaPluginBridge.pluginMediaElements, function ( mediaElement ) {
+                                                       mediaElement.addEventListener( 'play', callback );
+                                               } );
+                                       }
+
+                                       _.each( win.mejs.players, function ( player ) {
+                                               $( player.node ).on( 'play', callback );
+                                       }, this );
+                               }, this );
+                       },
+
+                       listenToSandboxes: function () {
+                               _.each( this.getNodes(), function ( node ) {
+                                       var win, iframe = $( '.wpview-sandbox', node ).get( 0 );
+                                       if ( iframe && ( win = iframe.contentWindow ) ) {
+                                               $( win ).load( _.bind( this.iframeLoaded( win ), this ) );
+                                       }
+                               }, this );
+                       },
+
+                       deferredListen: function () {
+                               window.setTimeout( _.bind( this.listenToSandboxes, this ), this.getNodes().length * waitInterval );
+                       },
+
                        setNodes: function () {
                                if ( this.parsed ) {
                                        this.setIframes( this.parsed.head, this.parsed.body );
+                                       this.deferredListen();
                                } else {
                                        this.fail();
                                }
@@ -613,6 +675,7 @@ window.wp = window.wp || {};
                                        if ( response ) {
                                                self.parsed = response;
                                                self.setIframes( response.head, response.body );
+                                               self.deferredListen();
                                        } else {
                                                self.fail( true );
                                        }