2015-02-09 01:43:50 +01:00
|
|
|
/**
|
|
|
|
* wp.media.view.Embed
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @augments wp.media.View
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
*/
|
2015-03-31 04:03:29 +02:00
|
|
|
var Embed = wp.media.View.extend({
|
2015-02-09 01:43:50 +01:00
|
|
|
className: 'media-embed',
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
/**
|
|
|
|
* @member {wp.media.view.EmbedUrl}
|
|
|
|
*/
|
2015-03-31 04:03:29 +02:00
|
|
|
this.url = new wp.media.view.EmbedUrl({
|
2015-02-09 01:43:50 +01:00
|
|
|
controller: this.controller,
|
|
|
|
model: this.model.props
|
|
|
|
}).render();
|
|
|
|
|
|
|
|
this.views.set([ this.url ]);
|
|
|
|
this.refresh();
|
|
|
|
this.listenTo( this.model, 'change:type', this.refresh );
|
|
|
|
this.listenTo( this.model, 'change:loading', this.loading );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} view
|
|
|
|
*/
|
|
|
|
settings: function( view ) {
|
|
|
|
if ( this._settings ) {
|
|
|
|
this._settings.remove();
|
|
|
|
}
|
|
|
|
this._settings = view;
|
|
|
|
this.views.add( view );
|
|
|
|
},
|
|
|
|
|
|
|
|
refresh: function() {
|
|
|
|
var type = this.model.get('type'),
|
|
|
|
constructor;
|
|
|
|
|
|
|
|
if ( 'image' === type ) {
|
2015-03-31 04:03:29 +02:00
|
|
|
constructor = wp.media.view.EmbedImage;
|
2015-02-09 01:43:50 +01:00
|
|
|
} else if ( 'link' === type ) {
|
2015-03-31 04:03:29 +02:00
|
|
|
constructor = wp.media.view.EmbedLink;
|
2015-02-09 01:43:50 +01:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.settings( new constructor({
|
|
|
|
controller: this.controller,
|
|
|
|
model: this.model.props,
|
|
|
|
priority: 40
|
|
|
|
}) );
|
|
|
|
},
|
|
|
|
|
|
|
|
loading: function() {
|
|
|
|
this.$el.toggleClass( 'embed-loading', this.model.get('loading') );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-09 17:01:29 +01:00
|
|
|
module.exports = Embed;
|