WordPress/wp-includes/js/media/views/embed.js
Scott Taylor b191013198 Media JS files:
* In media manifests, ditch IIFEs and global injection, these get dynamically scoped via Browserify
* Remove the `debug` option from `browserify:media`
* Add `jshint:media` to `jshint:corejs`
* Add a trailing newline to all new module files

Props iseulde.
See #28510.

Built from https://develop.svn.wordpress.org/trunk@31385


git-svn-id: http://core.svn.wordpress.org/trunk@31366 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-09 16:01:29 +00:00

69 lines
1.3 KiB
JavaScript

/**
* wp.media.view.Embed
*
* @class
* @augments wp.media.View
* @augments wp.Backbone.View
* @augments Backbone.View
*/
var View = require( './view.js' ),
EmbedImage = require( './embed/image.js' ),
EmbedLink = require( './embed/link.js' ),
EmbedUrl = require( './embed/url.js' ),
Embed;
Embed = View.extend({
className: 'media-embed',
initialize: function() {
/**
* @member {wp.media.view.EmbedUrl}
*/
this.url = new EmbedUrl({
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 ) {
constructor = EmbedImage;
} else if ( 'link' === type ) {
constructor = EmbedLink;
} 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') );
}
});
module.exports = Embed;