2015-02-22 01:56:27 -05:00
|
|
|
/*globals wp, _ */
|
|
|
|
|
2015-02-09 11:01:29 -05:00
|
|
|
var media = wp.media,
|
|
|
|
baseSettings = window._wpmejsSettings || {},
|
|
|
|
l10n = window._wpMediaViewsL10n || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin
|
|
|
|
*/
|
|
|
|
wp.media.mixin = {
|
|
|
|
mejsSettings: baseSettings,
|
|
|
|
|
|
|
|
removeAllPlayers: function() {
|
|
|
|
var p;
|
|
|
|
|
|
|
|
if ( window.mejs && window.mejs.players ) {
|
|
|
|
for ( p in window.mejs.players ) {
|
|
|
|
window.mejs.players[p].pause();
|
|
|
|
this.removePlayer( window.mejs.players[p] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-02-08 19:43:50 -05:00
|
|
|
|
|
|
|
/**
|
2015-02-09 11:01:29 -05:00
|
|
|
* Override the MediaElement method for removing a player.
|
|
|
|
* MediaElement tries to pull the audio/video tag out of
|
|
|
|
* its container and re-add it to the DOM.
|
2015-02-08 19:43:50 -05:00
|
|
|
*/
|
2015-02-09 11:01:29 -05:00
|
|
|
removePlayer: function(t) {
|
|
|
|
var featureIndex, feature;
|
2015-02-08 19:43:50 -05:00
|
|
|
|
2015-02-09 11:01:29 -05:00
|
|
|
if ( ! t.options ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-08 19:43:50 -05:00
|
|
|
|
2015-02-09 11:01:29 -05:00
|
|
|
// invoke features cleanup
|
|
|
|
for ( featureIndex in t.options.features ) {
|
|
|
|
feature = t.options.features[featureIndex];
|
|
|
|
if ( t['clean' + feature] ) {
|
|
|
|
try {
|
|
|
|
t['clean' + feature](t);
|
|
|
|
} catch (e) {}
|
2015-02-08 19:43:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-09 11:01:29 -05:00
|
|
|
if ( ! t.isDynamic ) {
|
|
|
|
t.$node.remove();
|
2015-02-08 19:43:50 -05:00
|
|
|
}
|
|
|
|
|
2015-02-09 11:01:29 -05:00
|
|
|
if ( 'native' !== t.media.pluginType ) {
|
2015-02-09 13:45:26 -05:00
|
|
|
t.$media.remove();
|
2015-02-08 19:43:50 -05:00
|
|
|
}
|
2015-02-09 11:01:29 -05:00
|
|
|
|
|
|
|
delete window.mejs.players[t.id];
|
|
|
|
|
|
|
|
t.container.remove();
|
|
|
|
t.globalUnbind();
|
|
|
|
delete t.node.player;
|
|
|
|
},
|
2015-02-08 19:43:50 -05:00
|
|
|
|
|
|
|
/**
|
2015-02-09 11:01:29 -05:00
|
|
|
* Allows any class that has set 'player' to a MediaElementPlayer
|
|
|
|
* instance to remove the player when listening to events.
|
2015-02-08 19:43:50 -05:00
|
|
|
*
|
2015-02-09 11:01:29 -05:00
|
|
|
* Examples: modal closes, shortcode properties are removed, etc.
|
2015-02-08 19:43:50 -05:00
|
|
|
*/
|
2015-02-09 11:01:29 -05:00
|
|
|
unsetPlayers : function() {
|
|
|
|
if ( this.players && this.players.length ) {
|
|
|
|
_.each( this.players, function (player) {
|
|
|
|
player.pause();
|
|
|
|
wp.media.mixin.removePlayer( player );
|
|
|
|
} );
|
|
|
|
this.players = [];
|
2015-02-08 19:43:50 -05:00
|
|
|
}
|
2015-02-09 11:01:29 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Autowire "collection"-type shortcodes
|
|
|
|
*/
|
|
|
|
wp.media.playlist = new wp.media.collection({
|
|
|
|
tag: 'playlist',
|
|
|
|
editTitle : l10n.editPlaylistTitle,
|
|
|
|
defaults : {
|
|
|
|
id: wp.media.view.settings.post.id,
|
|
|
|
style: 'light',
|
|
|
|
tracklist: true,
|
|
|
|
tracknumbers: true,
|
|
|
|
images: true,
|
|
|
|
artists: true,
|
|
|
|
type: 'audio'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcode modeling for audio
|
|
|
|
* `edit()` prepares the shortcode for the media modal
|
|
|
|
* `shortcode()` builds the new shortcode after update
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
wp.media.audio = {
|
|
|
|
coerce : wp.media.coerce,
|
|
|
|
|
|
|
|
defaults : {
|
|
|
|
id : wp.media.view.settings.post.id,
|
|
|
|
src : '',
|
|
|
|
loop : false,
|
|
|
|
autoplay : false,
|
|
|
|
preload : 'none',
|
|
|
|
width : 400
|
|
|
|
},
|
|
|
|
|
|
|
|
edit : function( data ) {
|
|
|
|
var frame, shortcode = wp.shortcode.next( 'audio', data ).shortcode;
|
|
|
|
|
|
|
|
frame = wp.media({
|
|
|
|
frame: 'audio',
|
|
|
|
state: 'audio-details',
|
|
|
|
metadata: _.defaults( shortcode.attrs.named, this.defaults )
|
|
|
|
});
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
},
|
|
|
|
|
|
|
|
shortcode : function( model ) {
|
|
|
|
var content;
|
|
|
|
|
|
|
|
_.each( this.defaults, function( value, key ) {
|
|
|
|
model[ key ] = this.coerce( model, key );
|
|
|
|
|
|
|
|
if ( value === model[ key ] ) {
|
|
|
|
delete model[ key ];
|
|
|
|
}
|
|
|
|
}, this );
|
|
|
|
|
|
|
|
content = model.content;
|
|
|
|
delete model.content;
|
|
|
|
|
|
|
|
return new wp.shortcode({
|
|
|
|
tag: 'audio',
|
|
|
|
attrs: model,
|
|
|
|
content: content
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcode modeling for video
|
|
|
|
* `edit()` prepares the shortcode for the media modal
|
|
|
|
* `shortcode()` builds the new shortcode after update
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
wp.media.video = {
|
|
|
|
coerce : wp.media.coerce,
|
|
|
|
|
|
|
|
defaults : {
|
|
|
|
id : wp.media.view.settings.post.id,
|
|
|
|
src : '',
|
|
|
|
poster : '',
|
|
|
|
loop : false,
|
|
|
|
autoplay : false,
|
|
|
|
preload : 'metadata',
|
|
|
|
content : '',
|
|
|
|
width : 640,
|
|
|
|
height : 360
|
|
|
|
},
|
|
|
|
|
|
|
|
edit : function( data ) {
|
|
|
|
var frame,
|
|
|
|
shortcode = wp.shortcode.next( 'video', data ).shortcode,
|
|
|
|
attrs;
|
|
|
|
|
|
|
|
attrs = shortcode.attrs.named;
|
|
|
|
attrs.content = shortcode.content;
|
|
|
|
|
|
|
|
frame = wp.media({
|
|
|
|
frame: 'video',
|
|
|
|
state: 'video-details',
|
|
|
|
metadata: _.defaults( attrs, this.defaults )
|
|
|
|
});
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
},
|
|
|
|
|
|
|
|
shortcode : function( model ) {
|
|
|
|
var content;
|
|
|
|
|
|
|
|
_.each( this.defaults, function( value, key ) {
|
|
|
|
model[ key ] = this.coerce( model, key );
|
|
|
|
|
|
|
|
if ( value === model[ key ] ) {
|
|
|
|
delete model[ key ];
|
|
|
|
}
|
|
|
|
}, this );
|
|
|
|
|
|
|
|
content = model.content;
|
|
|
|
delete model.content;
|
|
|
|
|
|
|
|
return new wp.shortcode({
|
|
|
|
tag: 'video',
|
|
|
|
attrs: model,
|
|
|
|
content: content
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
media.model.PostMedia = require( './models/post-media.js' );
|
|
|
|
media.controller.AudioDetails = require( './controllers/audio-details.js' );
|
|
|
|
media.controller.VideoDetails = require( './controllers/video-details.js' );
|
|
|
|
media.view.MediaFrame.MediaDetails = require( './views/frame/media-details.js' );
|
|
|
|
media.view.MediaFrame.AudioDetails = require( './views/frame/audio-details.js' );
|
|
|
|
media.view.MediaFrame.VideoDetails = require( './views/frame/video-details.js' );
|
|
|
|
media.view.MediaDetails = require( './views/media-details.js' );
|
|
|
|
media.view.AudioDetails = require( './views/audio-details.js' );
|
|
|
|
media.view.VideoDetails = require( './views/video-details.js' );
|