firefox = this.ua.is( 'ff' ),
className = '.wp-' + this.shortcode.tag + '-shortcode';
- if ( this.player ) {
- this.unsetPlayer();
- }
-
media = $( node ).find( className );
if ( ! this.isCompatible( media ) ) {
* @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 );
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();
},
*/
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 ) );
},
/**
* @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 );
},
/**
this.data = options;
return this.template( options );
+ },
+
+ unbind: function() {
+ this.unsetPlayers();
}
});
_.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin );