2015-02-22 07:56:27 +01:00
|
|
|
/*globals wp, Backbone, _ */
|
|
|
|
|
2015-02-09 01:43:50 +01:00
|
|
|
/**
|
2015-02-22 07:56:27 +01:00
|
|
|
* wp.media.model.PostMedia
|
|
|
|
*
|
2015-02-09 01:43:50 +01: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 07:28:26 +01:00
|
|
|
* @class
|
2015-02-09 01:43:50 +01: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-09 05:45:28 +01:00
|
|
|
this.unset( ext );
|
|
|
|
}, this );
|
2015-02-09 01:43:50 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-09 17:01:29 +01:00
|
|
|
module.exports = PostMedia;
|