2015-02-22 01:56:27 -05:00
|
|
|
/*globals wp, Backbone, _ */
|
|
|
|
|
2015-02-08 19:43:50 -05:00
|
|
|
/**
|
2015-02-22 01:56:27 -05:00
|
|
|
* wp.media.model.PostMedia
|
|
|
|
*
|
2015-02-08 19:43:50 -05:00
|
|
|
* Shared model class for audio and video. Updates the model after
|
|
|
|
* "Add Audio|Video Source" and "Replace Audio|Video" states return
|
|
|
|
*
|
2015-02-22 01:28:26 -05:00
|
|
|
* @class
|
2015-02-08 19:43:50 -05:00
|
|
|
* @augments Backbone.Model
|
|
|
|
*/
|
|
|
|
var PostMedia = Backbone.Model.extend({
|
|
|
|
initialize: function() {
|
|
|
|
this.attachment = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
setSource: function( attachment ) {
|
|
|
|
this.attachment = attachment;
|
|
|
|
this.extension = attachment.get( 'filename' ).split('.').pop();
|
|
|
|
|
|
|
|
if ( this.get( 'src' ) && this.extension === this.get( 'src' ).split('.').pop() ) {
|
|
|
|
this.unset( 'src' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( _.contains( wp.media.view.settings.embedExts, this.extension ) ) {
|
|
|
|
this.set( this.extension, this.attachment.get( 'url' ) );
|
|
|
|
} else {
|
|
|
|
this.unset( this.extension );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
changeAttachment: function( attachment ) {
|
|
|
|
this.setSource( attachment );
|
|
|
|
|
|
|
|
this.unset( 'src' );
|
|
|
|
_.each( _.without( wp.media.view.settings.embedExts, this.extension ), function( ext ) {
|
2015-02-08 23:45:28 -05:00
|
|
|
this.unset( ext );
|
|
|
|
}, this );
|
2015-02-08 19:43:50 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-09 11:01:29 -05:00
|
|
|
module.exports = PostMedia;
|