]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/mce-view.js
WordPress 3.9.1
[autoinstalls/wordpress.git] / wp-includes / js / mce-view.js
index afd60fab37da0819c9ff66745d4809c8689af506..ec167ca47c586226a96af37a57cd66d904fd1312 100644 (file)
@@ -451,10 +451,6 @@ window.wp = window.wp || {};
                                firefox = this.ua.is( 'ff' ),
                                className = '.wp-' +  this.shortcode.tag + '-shortcode';
 
-                       if ( this.player ) {
-                               this.unsetPlayer();
-                       }
-
                        media = $( node ).find( className );
 
                        if ( ! this.isCompatible( media ) ) {
@@ -487,20 +483,17 @@ window.wp = window.wp || {};
                 * @returns {string}
                 */
                getHtml: function() {
-                       var attrs = _.defaults(
-                               this.shortcode.attrs.named,
-                               wp.media[ this.shortcode.tag ].defaults
-                       );
-                       return this.template({ model: attrs });
+                       var attrs = this.shortcode.attrs.named;
+                       attrs.content = this.shortcode.content;
+
+                       return this.template({ model: _.defaults(
+                               attrs,
+                               wp.media[ this.shortcode.tag ].defaults )
+                       });
                },
 
                unbind: function() {
-                       var self = this;
-                       this.pauseAllPlayers();
-                       _.each( this.players, function (player) {
-                               self.removePlayer( player );
-                       } );
-                       this.players = [];
+                       this.unsetPlayers();
                }
        });
        _.extend( wp.mce.media.View.prototype, wp.media.mixin );
@@ -547,22 +540,10 @@ window.wp = window.wp || {};
                template:  media.template('editor-playlist'),
 
                initialize: function( options ) {
+                       this.players = [];
                        this.data = {};
                        this.attachments = [];
                        this.shortcode = options.shortcode;
-                       _.bindAll( this, 'setPlayer' );
-                       $(this).on('ready', this.setNode);
-               },
-
-               /**
-                * Set the element context for the view, and then fetch the playlist's
-                *   associated attachments.
-                *
-                * @param {Event} e
-                * @param {HTMLElement} node
-                */
-               setNode: function(e, node) {
-                       this.node = node;
                        this.fetch();
                },
 
@@ -571,7 +552,7 @@ window.wp = window.wp || {};
                 */
                fetch: function() {
                        this.attachments = wp.media.playlist.attachments( this.shortcode );
-                       this.attachments.more().done( this.setPlayer );
+                       this.dfd = this.attachments.more().done( _.bind( this.render, this ) );
                },
 
                /**
@@ -582,36 +563,31 @@ window.wp = window.wp || {};
                 * @global WPPlaylistView
                 * @global tinymce.editors
                 */
-               setPlayer: function() {
-                       var p,
-                               html = this.getHtml(),
-                               t = this.encodedText,
-                               self = this;
-
-                       this.unsetPlayer();
+               render: function() {
+                       var html = this.getHtml(), self = this;
 
                        _.each( tinymce.editors, function( editor ) {
                                var doc;
                                if ( editor.plugins.wpview ) {
                                        doc = editor.getDoc();
-                                       $( doc ).find( '[data-wpview-text="' + t + '"]' ).each(function(i, elem) {
+                                       $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) {
                                                var node = $( elem );
-                                               node.html( html );
-                                               self.node = elem;
-                                       });
-                               }
-                       }, this );
 
-                       if ( ! this.data.tracks ) {
-                               return;
-                       }
+                                               // The <ins> is used to mark the end of the wrapper div. Needed when comparing
+                                               // the content as string for preventing extra undo levels.
+                                               node.html( html ).append( '<ins data-wpview-end="1"></ins>' );
 
-                       p = new WPPlaylistView({
-                               el: $( self.node ).find( '.wp-playlist' ).get(0),
-                               metadata: this.data
-                       });
+                                               if ( ! self.data.tracks ) {
+                                                       return;
+                                               }
 
-                       this.player = p._player;
+                                               self.players.push( new WPPlaylistView({
+                                                       el: $( elem ).find( '.wp-playlist' ).get(0),
+                                                       metadata: self.data
+                                               }).player );
+                                       });
+                               }
+                       }, this );
                },
 
                /**
@@ -695,6 +671,10 @@ window.wp = window.wp || {};
                        this.data = options;
 
                        return this.template( options );
+               },
+
+               unbind: function() {
+                       this.unsetPlayers();
                }
        });
        _.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin );