CoreFiles by mySites.guru
post-media.js42 lines, 1,046 bytes, from wordpress-4.2-beta3.zip
Raw History Compare with 4.2-beta2
md5
fae12bb3b183d78ca648e412931355b8
sha1
e8d0c68ecee288f3c9a46dcc1ca438c9a424ab5e
sha256
4296bda1bc1c83bc2fa6abce74c787a6a074c2b558d1f5d71db494e0c5b91659
/*globals wp, Backbone, _ */

/**
 * wp.media.model.PostMedia
 *
 * Shared model class for audio and video. Updates the model after
 *   "Add Audio|Video Source" and "Replace Audio|Video" states return
 *
 * @class
 * @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 ) {
			this.unset( ext );
		}, this );
	}
});

module.exports = PostMedia;

The same content is in 4 releases, WordPress 4.2-beta1 to 4.2-beta4. See them all, or every version of this file.