2014-03-26 17:41:15 -04:00
|
|
|
/* global _wpMediaViewsL10n, _wpmejsSettings, MediaElementPlayer */
|
2014-03-19 01:31:15 -04:00
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
(function($, _, Backbone) {
|
|
|
|
var media = wp.media,
|
|
|
|
baseSettings = {},
|
|
|
|
l10n = typeof _wpMediaViewsL10n === 'undefined' ? {} : _wpMediaViewsL10n;
|
|
|
|
|
|
|
|
if ( ! _.isUndefined( window._wpmejsSettings ) ) {
|
2014-05-11 02:25:15 -04:00
|
|
|
baseSettings = _wpmejsSettings;
|
2014-03-22 19:26:17 -04:00
|
|
|
}
|
2014-03-19 01:31:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin
|
|
|
|
*/
|
|
|
|
wp.media.mixin = {
|
2014-03-26 08:11:14 -04:00
|
|
|
mejsSettings: baseSettings,
|
2014-03-19 01:31:15 -04:00
|
|
|
/**
|
|
|
|
* Pauses every instance of MediaElementPlayer
|
|
|
|
*/
|
2014-03-22 19:26:17 -04:00
|
|
|
pauseAllPlayers: function() {
|
2014-03-19 01:31:15 -04:00
|
|
|
var p;
|
|
|
|
if ( window.mejs && window.mejs.players ) {
|
|
|
|
for ( p in window.mejs.players ) {
|
|
|
|
window.mejs.players[p].pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-03 23:39:15 -04:00
|
|
|
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] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-10 22:07:14 -04:00
|
|
|
/**
|
|
|
|
* Pauses the current object's instances of MediaElementPlayer
|
|
|
|
*/
|
|
|
|
pausePlayers: function() {
|
|
|
|
_.each( this.players, function (player) {
|
|
|
|
player.pause();
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2014-03-19 01:31:15 -04:00
|
|
|
/**
|
|
|
|
* Utility to identify the user's browser
|
|
|
|
*/
|
|
|
|
ua: {
|
2014-03-22 19:26:17 -04:00
|
|
|
is : function( browser ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
var passes = false, ua = window.navigator.userAgent;
|
|
|
|
|
|
|
|
switch ( browser ) {
|
|
|
|
case 'oldie':
|
|
|
|
passes = ua.match(/MSIE [6-8]/gi) !== null;
|
|
|
|
break;
|
|
|
|
case 'ie':
|
2014-07-03 21:10:15 -04:00
|
|
|
passes = /MSIE /.test( ua ) || ( /Trident\//.test( ua ) && /rv:\d/.test( ua ) ); // IE11
|
2014-03-19 01:31:15 -04:00
|
|
|
break;
|
|
|
|
case 'ff':
|
|
|
|
passes = ua.match(/firefox/gi) !== null;
|
|
|
|
break;
|
|
|
|
case 'opera':
|
|
|
|
passes = ua.match(/OPR/) !== null;
|
|
|
|
break;
|
|
|
|
case 'safari':
|
|
|
|
passes = ua.match(/safari/gi) !== null && ua.match(/chrome/gi) === null;
|
|
|
|
break;
|
|
|
|
case 'chrome':
|
2014-03-22 19:26:17 -04:00
|
|
|
passes = ua.match(/safari/gi) !== null && ua.match(/chrome/gi) !== null;
|
2014-03-19 01:31:15 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return passes;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify compatibility for native playback by browser
|
|
|
|
*/
|
|
|
|
compat :{
|
|
|
|
'opera' : {
|
|
|
|
audio: ['ogg', 'wav'],
|
|
|
|
video: ['ogg', 'webm']
|
|
|
|
},
|
|
|
|
'chrome' : {
|
2014-03-19 03:02:15 -04:00
|
|
|
audio: ['ogg', 'mpeg'],
|
2014-03-19 01:31:15 -04:00
|
|
|
video: ['ogg', 'webm', 'mp4', 'm4v', 'mpeg']
|
|
|
|
},
|
|
|
|
'ff' : {
|
|
|
|
audio: ['ogg', 'mpeg'],
|
|
|
|
video: ['ogg', 'webm']
|
|
|
|
},
|
|
|
|
'safari' : {
|
|
|
|
audio: ['mpeg', 'wav'],
|
|
|
|
video: ['mp4', 'm4v', 'mpeg', 'x-ms-wmv', 'quicktime']
|
|
|
|
},
|
|
|
|
'ie' : {
|
|
|
|
audio: ['mpeg'],
|
|
|
|
video: ['mp4', 'm4v', 'mpeg']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the passed media contains a <source> that provides
|
|
|
|
* native playback in the user's browser
|
|
|
|
*
|
|
|
|
* @param {jQuery} media
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2014-03-22 19:26:17 -04:00
|
|
|
isCompatible: function( media ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
if ( ! media.find( 'source' ).length ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ua = this.ua, test = false, found = false, sources;
|
|
|
|
|
|
|
|
if ( ua.is( 'oldIE' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sources = media.find( 'source' );
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
_.find( this.compat, function( supports, browser ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
if ( ua.is( browser ) ) {
|
|
|
|
found = true;
|
2014-03-22 19:26:17 -04:00
|
|
|
_.each( sources, function( elem ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
var audio = new RegExp( 'audio\/(' + supports.audio.join('|') + ')', 'gi' ),
|
|
|
|
video = new RegExp( 'video\/(' + supports.video.join('|') + ')', 'gi' );
|
|
|
|
|
|
|
|
if ( elem.type.match( video ) !== null || elem.type.match( audio ) !== null ) {
|
|
|
|
test = true;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return test || found;
|
|
|
|
} );
|
|
|
|
|
|
|
|
return test;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-04-11 20:46:14 -04:00
|
|
|
removePlayer: function(t) {
|
|
|
|
var featureIndex, feature;
|
2014-03-19 01:31:15 -04:00
|
|
|
|
2014-05-10 19:36:18 -04:00
|
|
|
if ( ! t.options ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-19 01:31:15 -04: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) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! t.isDynamic ) {
|
|
|
|
t.$node.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'native' !== t.media.pluginType ) {
|
|
|
|
t.media.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete window.mejs.players[t.id];
|
|
|
|
|
|
|
|
t.container.remove();
|
|
|
|
t.globalUnbind();
|
|
|
|
delete t.node.player;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows any class that has set 'player' to a MediaElementPlayer
|
|
|
|
* instance to remove the player when listening to events.
|
|
|
|
*
|
|
|
|
* Examples: modal closes, shortcode properties are removed, etc.
|
|
|
|
*/
|
2014-04-22 13:53:16 -04:00
|
|
|
unsetPlayers : function() {
|
|
|
|
if ( this.players && this.players.length ) {
|
|
|
|
_.each( this.players, function (player) {
|
2014-05-10 22:07:14 -04:00
|
|
|
player.pause();
|
2014-04-22 13:53:16 -04:00
|
|
|
wp.media.mixin.removePlayer( player );
|
|
|
|
} );
|
|
|
|
this.players = [];
|
2014-03-19 01:31:15 -04: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,
|
2014-03-27 13:58:15 -04:00
|
|
|
artists: true,
|
|
|
|
type: 'audio'
|
2014-03-19 01:31:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2014-03-20 09:33:14 -04:00
|
|
|
src : '',
|
|
|
|
loop : false,
|
2014-03-19 01:31:15 -04:00
|
|
|
autoplay : false,
|
2014-03-20 09:33:14 -04:00
|
|
|
preload : 'none',
|
2014-03-26 08:11:14 -04:00
|
|
|
width : 400
|
2014-03-19 01:31:15 -04:00
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
edit : function( data ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
var frame, shortcode = wp.shortcode.next( 'audio', data ).shortcode;
|
|
|
|
frame = wp.media({
|
|
|
|
frame: 'audio',
|
|
|
|
state: 'audio-details',
|
2014-03-22 19:26:17 -04:00
|
|
|
metadata: _.defaults( shortcode.attrs.named, this.defaults )
|
2014-03-19 01:31:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
shortcode : function( model ) {
|
2014-03-19 03:02:15 -04:00
|
|
|
var self = this, content;
|
2014-03-19 01:31:15 -04:00
|
|
|
|
2014-03-19 03:02:15 -04:00
|
|
|
_.each( this.defaults, function( value, key ) {
|
|
|
|
model[ key ] = self.coerce( model, key );
|
2014-03-19 01:31:15 -04:00
|
|
|
|
2014-03-19 03:02:15 -04:00
|
|
|
if ( value === model[ key ] ) {
|
|
|
|
delete model[ key ];
|
2014-03-19 01:31:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-19 03:02:15 -04:00
|
|
|
content = model.content;
|
|
|
|
delete model.content;
|
|
|
|
|
|
|
|
return new wp.shortcode({
|
|
|
|
tag: 'audio',
|
|
|
|
attrs: model,
|
|
|
|
content: content
|
2014-03-19 01:31:15 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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',
|
2014-03-20 09:33:14 -04:00
|
|
|
content : '',
|
2014-03-22 19:26:17 -04:00
|
|
|
width : 640,
|
|
|
|
height : 360
|
2014-03-19 01:31:15 -04:00
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
edit : function( data ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
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',
|
2014-03-22 19:26:17 -04:00
|
|
|
metadata: _.defaults( attrs, this.defaults )
|
2014-03-19 01:31:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
shortcode : function( model ) {
|
2014-03-19 03:02:15 -04:00
|
|
|
var self = this, content;
|
2014-03-19 01:31:15 -04:00
|
|
|
|
|
|
|
_.each( this.defaults, function( value, key ) {
|
2014-03-19 03:02:15 -04:00
|
|
|
model[ key ] = self.coerce( model, key );
|
2014-03-19 01:31:15 -04:00
|
|
|
|
2014-03-19 03:02:15 -04:00
|
|
|
if ( value === model[ key ] ) {
|
|
|
|
delete model[ key ];
|
2014-03-19 01:31:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-19 03:02:15 -04:00
|
|
|
content = model.content;
|
|
|
|
delete model.content;
|
|
|
|
|
|
|
|
return new wp.shortcode({
|
|
|
|
tag: 'video',
|
|
|
|
attrs: model,
|
2014-03-19 01:31:15 -04:00
|
|
|
content: content
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-03-22 19:26:17 -04:00
|
|
|
* Shared model class for audio and video. Updates the model after
|
|
|
|
* "Add Audio|Video Source" and "Replace Audio|Video" states return
|
2014-03-19 01:31:15 -04:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments Backbone.Model
|
2014-03-22 19:26:17 -04:00
|
|
|
*/
|
2014-03-19 01:31:15 -04:00
|
|
|
media.model.PostMedia = Backbone.Model.extend({
|
|
|
|
initialize: function() {
|
|
|
|
this.attachment = false;
|
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
setSource: function( attachment ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
this.attachment = attachment;
|
2014-03-22 19:26:17 -04:00
|
|
|
this.extension = attachment.get( 'filename' ).split('.').pop();
|
2014-03-19 01:31:15 -04:00
|
|
|
|
|
|
|
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 ) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.setSource( attachment );
|
|
|
|
|
|
|
|
this.unset( 'src' );
|
2014-03-22 19:26:17 -04:00
|
|
|
_.each( _.without( wp.media.view.settings.embedExts, this.extension ), function( ext ) {
|
2014-03-19 01:31:15 -04:00
|
|
|
self.unset( ext );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2014-03-22 19:26:17 -04:00
|
|
|
* The controller for the Audio Details state
|
2014-03-19 01:31:15 -04:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments wp.media.controller.State
|
|
|
|
* @augments Backbone.Model
|
|
|
|
*/
|
|
|
|
media.controller.AudioDetails = media.controller.State.extend({
|
2014-03-22 19:26:17 -04:00
|
|
|
defaults: {
|
2014-03-19 01:31:15 -04:00
|
|
|
id: 'audio-details',
|
|
|
|
toolbar: 'audio-details',
|
|
|
|
title: l10n.audioDetailsTitle,
|
|
|
|
content: 'audio-details',
|
|
|
|
menu: 'audio-details',
|
|
|
|
router: false,
|
2014-03-22 19:26:17 -04:00
|
|
|
priority: 60
|
|
|
|
},
|
2014-03-19 01:31:15 -04:00
|
|
|
|
|
|
|
initialize: function( options ) {
|
|
|
|
this.media = options.media;
|
|
|
|
media.controller.State.prototype.initialize.apply( this, arguments );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2014-03-22 19:26:17 -04:00
|
|
|
* The controller for the Video Details state
|
2014-03-19 01:31:15 -04:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments wp.media.controller.State
|
|
|
|
* @augments Backbone.Model
|
|
|
|
*/
|
|
|
|
media.controller.VideoDetails = media.controller.State.extend({
|
2014-03-22 19:26:17 -04:00
|
|
|
defaults: {
|
2014-03-19 01:31:15 -04:00
|
|
|
id: 'video-details',
|
|
|
|
toolbar: 'video-details',
|
|
|
|
title: l10n.videoDetailsTitle,
|
|
|
|
content: 'video-details',
|
|
|
|
menu: 'video-details',
|
|
|
|
router: false,
|
2014-03-22 19:26:17 -04:00
|
|
|
priority: 60
|
|
|
|
},
|
2014-03-19 01:31:15 -04:00
|
|
|
|
|
|
|
initialize: function( options ) {
|
|
|
|
this.media = options.media;
|
|
|
|
media.controller.State.prototype.initialize.apply( this, arguments );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.media.view.MediaFrame.MediaDetails
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments wp.media.view.MediaFrame.Select
|
|
|
|
* @augments wp.media.view.MediaFrame
|
|
|
|
* @augments wp.media.view.Frame
|
|
|
|
* @augments wp.media.View
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
* @mixes wp.media.controller.StateMachine
|
|
|
|
*/
|
|
|
|
media.view.MediaFrame.MediaDetails = media.view.MediaFrame.Select.extend({
|
|
|
|
defaults: {
|
|
|
|
id: 'media',
|
|
|
|
url: '',
|
|
|
|
menu: 'media-details',
|
|
|
|
content: 'media-details',
|
|
|
|
toolbar: 'media-details',
|
|
|
|
type: 'link',
|
|
|
|
priority: 120
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function( options ) {
|
|
|
|
this.DetailsView = options.DetailsView;
|
|
|
|
this.cancelText = options.cancelText;
|
|
|
|
this.addText = options.addText;
|
|
|
|
|
|
|
|
this.media = new media.model.PostMedia( options.metadata );
|
|
|
|
this.options.selection = new media.model.Selection( this.media.attachment, { multiple: false } );
|
|
|
|
media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
|
|
|
|
},
|
|
|
|
|
|
|
|
bindHandlers: function() {
|
|
|
|
var menu = this.defaults.menu;
|
|
|
|
|
|
|
|
media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
|
|
|
|
|
|
|
|
this.on( 'menu:create:' + menu, this.createMenu, this );
|
|
|
|
this.on( 'content:render:' + menu, this.renderDetailsContent, this );
|
|
|
|
this.on( 'menu:render:' + menu, this.renderMenu, this );
|
|
|
|
this.on( 'toolbar:render:' + menu, this.renderDetailsToolbar, this );
|
|
|
|
},
|
|
|
|
|
|
|
|
renderDetailsContent: function() {
|
|
|
|
var view = new this.DetailsView({
|
|
|
|
controller: this,
|
|
|
|
model: this.state().media,
|
|
|
|
attachment: this.state().media.attachment
|
|
|
|
}).render();
|
|
|
|
|
|
|
|
this.content.set( view );
|
|
|
|
},
|
|
|
|
|
|
|
|
renderMenu: function( view ) {
|
|
|
|
var lastState = this.lastState(),
|
|
|
|
previous = lastState && lastState.id,
|
|
|
|
frame = this;
|
|
|
|
|
|
|
|
view.set({
|
|
|
|
cancel: {
|
|
|
|
text: this.cancelText,
|
|
|
|
priority: 20,
|
|
|
|
click: function() {
|
|
|
|
if ( previous ) {
|
|
|
|
frame.setState( previous );
|
|
|
|
} else {
|
|
|
|
frame.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
separateCancel: new media.View({
|
|
|
|
className: 'separator',
|
|
|
|
priority: 40
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
setPrimaryButton: function(text, handler) {
|
2014-03-19 01:31:15 -04:00
|
|
|
this.toolbar.set( new media.view.Toolbar({
|
|
|
|
controller: this,
|
|
|
|
items: {
|
2014-03-22 19:26:17 -04:00
|
|
|
button: {
|
2014-03-19 01:31:15 -04:00
|
|
|
style: 'primary',
|
2014-03-22 19:26:17 -04:00
|
|
|
text: text,
|
2014-03-19 01:31:15 -04:00
|
|
|
priority: 80,
|
2014-03-22 19:26:17 -04:00
|
|
|
click: function() {
|
|
|
|
var controller = this.controller;
|
|
|
|
handler.call( this, controller, controller.state() );
|
2014-03-19 01:31:15 -04:00
|
|
|
// Restore and reset the default state.
|
|
|
|
controller.setState( controller.options.state );
|
|
|
|
controller.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}) );
|
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
renderDetailsToolbar: function() {
|
|
|
|
this.setPrimaryButton( l10n.update, function( controller, state ) {
|
|
|
|
controller.close();
|
|
|
|
state.trigger( 'update', controller.media.toJSON() );
|
|
|
|
} );
|
|
|
|
},
|
2014-03-19 01:31:15 -04:00
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
renderReplaceToolbar: function() {
|
|
|
|
this.setPrimaryButton( l10n.replace, function( controller, state ) {
|
|
|
|
var attachment = state.get( 'selection' ).single();
|
|
|
|
controller.media.changeAttachment( attachment );
|
|
|
|
state.trigger( 'replace', controller.media.toJSON() );
|
|
|
|
} );
|
2014-03-19 01:31:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
renderAddSourceToolbar: function() {
|
2014-03-22 19:26:17 -04:00
|
|
|
this.setPrimaryButton( this.addText, function( controller, state ) {
|
|
|
|
var attachment = state.get( 'selection' ).single();
|
|
|
|
controller.media.setSource( attachment );
|
|
|
|
state.trigger( 'add-source', controller.media.toJSON() );
|
|
|
|
} );
|
2014-03-19 01:31:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.media.view.MediaFrame.AudioDetails
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments wp.media.view.MediaFrame.MediaDetails
|
|
|
|
* @augments wp.media.view.MediaFrame.Select
|
|
|
|
* @augments wp.media.view.MediaFrame
|
|
|
|
* @augments wp.media.view.Frame
|
|
|
|
* @augments wp.media.View
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
* @mixes wp.media.controller.StateMachine
|
|
|
|
*/
|
|
|
|
media.view.MediaFrame.AudioDetails = media.view.MediaFrame.MediaDetails.extend({
|
|
|
|
defaults: {
|
|
|
|
id: 'audio',
|
|
|
|
url: '',
|
|
|
|
menu: 'audio-details',
|
|
|
|
content: 'audio-details',
|
|
|
|
toolbar: 'audio-details',
|
|
|
|
type: 'link',
|
|
|
|
title: l10n.audioDetailsTitle,
|
|
|
|
priority: 120
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function( options ) {
|
|
|
|
options.DetailsView = media.view.AudioDetails;
|
|
|
|
options.cancelText = l10n.audioDetailsCancel;
|
|
|
|
options.addText = l10n.audioAddSourceTitle;
|
|
|
|
|
|
|
|
media.view.MediaFrame.MediaDetails.prototype.initialize.call( this, options );
|
|
|
|
},
|
|
|
|
|
|
|
|
bindHandlers: function() {
|
|
|
|
media.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply( this, arguments );
|
|
|
|
|
|
|
|
this.on( 'toolbar:render:replace-audio', this.renderReplaceToolbar, this );
|
|
|
|
this.on( 'toolbar:render:add-audio-source', this.renderAddSourceToolbar, this );
|
|
|
|
},
|
|
|
|
|
|
|
|
createStates: function() {
|
|
|
|
this.states.add([
|
|
|
|
new media.controller.AudioDetails( {
|
2014-03-22 19:26:17 -04:00
|
|
|
media: this.media
|
2014-03-19 01:31:15 -04:00
|
|
|
} ),
|
|
|
|
|
|
|
|
new media.controller.MediaLibrary( {
|
|
|
|
type: 'audio',
|
|
|
|
id: 'replace-audio',
|
|
|
|
title: l10n.audioReplaceTitle,
|
|
|
|
toolbar: 'replace-audio',
|
|
|
|
media: this.media,
|
|
|
|
menu: 'audio-details'
|
|
|
|
} ),
|
|
|
|
|
|
|
|
new media.controller.MediaLibrary( {
|
|
|
|
type: 'audio',
|
|
|
|
id: 'add-audio-source',
|
|
|
|
title: l10n.audioAddSourceTitle,
|
|
|
|
toolbar: 'add-audio-source',
|
|
|
|
media: this.media,
|
|
|
|
menu: false
|
|
|
|
} )
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.media.view.MediaFrame.VideoDetails
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments wp.media.view.MediaFrame.MediaDetails
|
|
|
|
* @augments wp.media.view.MediaFrame.Select
|
|
|
|
* @augments wp.media.view.MediaFrame
|
|
|
|
* @augments wp.media.view.Frame
|
|
|
|
* @augments wp.media.View
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
* @mixes wp.media.controller.StateMachine
|
|
|
|
*/
|
|
|
|
media.view.MediaFrame.VideoDetails = media.view.MediaFrame.MediaDetails.extend({
|
|
|
|
defaults: {
|
|
|
|
id: 'video',
|
|
|
|
url: '',
|
|
|
|
menu: 'video-details',
|
|
|
|
content: 'video-details',
|
|
|
|
toolbar: 'video-details',
|
|
|
|
type: 'link',
|
|
|
|
title: l10n.videoDetailsTitle,
|
|
|
|
priority: 120
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function( options ) {
|
|
|
|
options.DetailsView = media.view.VideoDetails;
|
|
|
|
options.cancelText = l10n.videoDetailsCancel;
|
|
|
|
options.addText = l10n.videoAddSourceTitle;
|
|
|
|
|
|
|
|
media.view.MediaFrame.MediaDetails.prototype.initialize.call( this, options );
|
|
|
|
},
|
|
|
|
|
|
|
|
bindHandlers: function() {
|
|
|
|
media.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply( this, arguments );
|
|
|
|
|
|
|
|
this.on( 'toolbar:render:replace-video', this.renderReplaceToolbar, this );
|
|
|
|
this.on( 'toolbar:render:add-video-source', this.renderAddSourceToolbar, this );
|
|
|
|
this.on( 'toolbar:render:select-poster-image', this.renderSelectPosterImageToolbar, this );
|
|
|
|
this.on( 'toolbar:render:add-track', this.renderAddTrackToolbar, this );
|
|
|
|
},
|
|
|
|
|
|
|
|
createStates: function() {
|
|
|
|
this.states.add([
|
|
|
|
new media.controller.VideoDetails({
|
2014-03-22 19:26:17 -04:00
|
|
|
media: this.media
|
2014-03-19 01:31:15 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
new media.controller.MediaLibrary( {
|
|
|
|
type: 'video',
|
|
|
|
id: 'replace-video',
|
|
|
|
title: l10n.videoReplaceTitle,
|
|
|
|
toolbar: 'replace-video',
|
|
|
|
media: this.media,
|
|
|
|
menu: 'video-details'
|
|
|
|
} ),
|
|
|
|
|
|
|
|
new media.controller.MediaLibrary( {
|
|
|
|
type: 'video',
|
|
|
|
id: 'add-video-source',
|
|
|
|
title: l10n.videoAddSourceTitle,
|
|
|
|
toolbar: 'add-video-source',
|
|
|
|
media: this.media,
|
|
|
|
menu: false
|
|
|
|
} ),
|
|
|
|
|
|
|
|
new media.controller.MediaLibrary( {
|
|
|
|
type: 'image',
|
|
|
|
id: 'select-poster-image',
|
|
|
|
title: l10n.videoSelectPosterImageTitle,
|
|
|
|
toolbar: 'select-poster-image',
|
|
|
|
media: this.media,
|
|
|
|
menu: 'video-details'
|
|
|
|
} ),
|
|
|
|
|
|
|
|
new media.controller.MediaLibrary( {
|
|
|
|
type: 'text',
|
|
|
|
id: 'add-track',
|
|
|
|
title: l10n.videoAddTrackTitle,
|
|
|
|
toolbar: 'add-track',
|
|
|
|
media: this.media,
|
|
|
|
menu: 'video-details'
|
|
|
|
} )
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
renderSelectPosterImageToolbar: function() {
|
2014-03-22 19:26:17 -04:00
|
|
|
this.setPrimaryButton( l10n.videoSelectPosterImageTitle, function( controller, state ) {
|
2014-07-08 13:48:17 -04:00
|
|
|
var urls = [], attachment = state.get( 'selection' ).single();
|
2014-03-19 01:31:15 -04:00
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
controller.media.set( 'poster', attachment.get( 'url' ) );
|
|
|
|
state.trigger( 'set-poster-image', controller.media.toJSON() );
|
2014-07-08 13:48:17 -04:00
|
|
|
|
|
|
|
_.each( wp.media.view.settings.embedExts, function (ext) {
|
|
|
|
if ( controller.media.get( ext ) ) {
|
|
|
|
urls.push( controller.media.get( ext ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.ajax.send( 'set-attachment-thumbnail', {
|
|
|
|
data : {
|
|
|
|
urls: urls,
|
|
|
|
thumbnail_id: attachment.get( 'id' )
|
|
|
|
}
|
|
|
|
} );
|
2014-03-22 19:26:17 -04:00
|
|
|
} );
|
2014-03-19 01:31:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
renderAddTrackToolbar: function() {
|
2014-03-22 19:26:17 -04:00
|
|
|
this.setPrimaryButton( l10n.videoAddTrackTitle, function( controller, state ) {
|
|
|
|
var attachment = state.get( 'selection' ).single(),
|
|
|
|
content = controller.media.get( 'content' );
|
|
|
|
|
|
|
|
if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) {
|
|
|
|
content += [
|
|
|
|
'<track srclang="en" label="English"kind="subtitles" src="',
|
|
|
|
attachment.get( 'url' ),
|
|
|
|
'" />'
|
|
|
|
].join('');
|
|
|
|
|
|
|
|
controller.media.set( 'content', content );
|
2014-03-19 01:31:15 -04:00
|
|
|
}
|
2014-03-22 19:26:17 -04:00
|
|
|
state.trigger( 'add-track', controller.media.toJSON() );
|
|
|
|
} );
|
2014-03-19 01:31:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-19 22:45:15 -04:00
|
|
|
/**
|
|
|
|
* wp.media.view.MediaDetails
|
|
|
|
*
|
|
|
|
* @contructor
|
|
|
|
* @augments wp.media.view.Settings.AttachmentDisplay
|
|
|
|
* @augments wp.media.view.Settings
|
|
|
|
* @augments wp.media.View
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
*/
|
|
|
|
media.view.MediaDetails = media.view.Settings.AttachmentDisplay.extend({
|
|
|
|
initialize: function() {
|
|
|
|
_.bindAll(this, 'success');
|
2014-04-22 13:53:16 -04:00
|
|
|
this.players = [];
|
|
|
|
this.listenTo( this.controller, 'close', media.mixin.unsetPlayers );
|
2014-03-19 22:45:15 -04:00
|
|
|
this.on( 'ready', this.setPlayer );
|
2014-04-22 13:53:16 -04:00
|
|
|
this.on( 'media:setting:remove', media.mixin.unsetPlayers, this );
|
2014-03-19 22:45:15 -04:00
|
|
|
this.on( 'media:setting:remove', this.render );
|
|
|
|
this.on( 'media:setting:remove', this.setPlayer );
|
|
|
|
this.events = _.extend( this.events, {
|
|
|
|
'click .remove-setting' : 'removeSetting',
|
|
|
|
'change .content-track' : 'setTracks',
|
|
|
|
'click .remove-track' : 'setTracks'
|
|
|
|
} );
|
|
|
|
|
|
|
|
media.view.Settings.AttachmentDisplay.prototype.initialize.apply( this, arguments );
|
|
|
|
},
|
|
|
|
|
|
|
|
prepare: function() {
|
|
|
|
return _.defaults({
|
|
|
|
model: this.model.toJSON()
|
|
|
|
}, this.options );
|
|
|
|
},
|
|
|
|
|
2014-03-20 18:23:15 -04:00
|
|
|
/**
|
|
|
|
* Remove a setting's UI when the model unsets it
|
|
|
|
*
|
|
|
|
* @fires wp.media.view.MediaDetails#media:setting:remove
|
|
|
|
*
|
|
|
|
* @param {Event} e
|
|
|
|
*/
|
2014-03-22 19:26:17 -04:00
|
|
|
removeSetting : function(e) {
|
2014-03-19 22:45:15 -04:00
|
|
|
var wrap = $( e.currentTarget ).parent(), setting;
|
|
|
|
setting = wrap.find( 'input' ).data( 'setting' );
|
|
|
|
|
|
|
|
if ( setting ) {
|
|
|
|
this.model.unset( setting );
|
|
|
|
this.trigger( 'media:setting:remove', this );
|
|
|
|
}
|
|
|
|
|
|
|
|
wrap.remove();
|
|
|
|
},
|
|
|
|
|
2014-03-20 18:23:15 -04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @fires wp.media.view.MediaDetails#media:setting:remove
|
|
|
|
*/
|
2014-03-22 19:26:17 -04:00
|
|
|
setTracks : function() {
|
2014-03-19 22:45:15 -04:00
|
|
|
var tracks = '';
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
_.each( this.$('.content-track'), function(track) {
|
2014-03-19 22:45:15 -04:00
|
|
|
tracks += $( track ).val();
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.model.set( 'content', tracks );
|
|
|
|
this.trigger( 'media:setting:remove', this );
|
|
|
|
},
|
|
|
|
|
2014-03-20 18:23:15 -04:00
|
|
|
/**
|
|
|
|
* @global MediaElementPlayer
|
|
|
|
*/
|
2014-03-22 19:26:17 -04:00
|
|
|
setPlayer : function() {
|
2014-04-22 13:53:16 -04:00
|
|
|
if ( ! this.players.length && this.media ) {
|
|
|
|
this.players.push( new MediaElementPlayer( this.media, this.settings ) );
|
2014-03-19 22:45:15 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @abstract
|
|
|
|
*/
|
2014-03-22 19:26:17 -04:00
|
|
|
setMedia : function() {
|
2014-03-19 22:45:15 -04:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
success : function(mejs) {
|
2014-03-19 22:45:15 -04:00
|
|
|
var autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
|
|
|
|
|
|
|
|
if ( 'flash' === mejs.pluginType && autoplay ) {
|
2014-03-22 19:26:17 -04:00
|
|
|
mejs.addEventListener( 'canplay', function() {
|
2014-03-19 22:45:15 -04:00
|
|
|
mejs.play();
|
|
|
|
}, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mejs = mejs;
|
|
|
|
},
|
|
|
|
|
2014-03-20 18:23:15 -04:00
|
|
|
/**
|
|
|
|
* @returns {media.view.MediaDetails} Returns itself to allow chaining
|
|
|
|
*/
|
2014-03-19 22:45:15 -04:00
|
|
|
render: function() {
|
2014-03-22 19:26:17 -04:00
|
|
|
var self = this;
|
2014-03-19 22:45:15 -04:00
|
|
|
|
|
|
|
media.view.Settings.AttachmentDisplay.prototype.render.apply( this, arguments );
|
|
|
|
setTimeout( function() { self.resetFocus(); }, 10 );
|
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
this.settings = _.defaults( {
|
|
|
|
success : this.success
|
|
|
|
}, baseSettings );
|
2014-03-19 22:45:15 -04:00
|
|
|
|
|
|
|
return this.setMedia();
|
|
|
|
},
|
|
|
|
|
|
|
|
resetFocus: function() {
|
|
|
|
this.$( '.embed-media-settings' ).scrollTop( 0 );
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
instances : 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When multiple players in the DOM contain the same src, things get weird.
|
|
|
|
*
|
2014-03-22 19:26:17 -04:00
|
|
|
* @param {HTMLElement} elem
|
2014-03-19 22:45:15 -04:00
|
|
|
* @returns {HTMLElement}
|
|
|
|
*/
|
2014-03-22 19:26:17 -04:00
|
|
|
prepareSrc : function( elem ) {
|
|
|
|
var i = media.view.MediaDetails.instances++;
|
|
|
|
_.each( $( elem ).find( 'source' ), function( source ) {
|
2014-03-19 22:45:15 -04:00
|
|
|
source.src = [
|
|
|
|
source.src,
|
|
|
|
source.src.indexOf('?') > -1 ? '&' : '?',
|
|
|
|
'_=',
|
|
|
|
i
|
|
|
|
].join('');
|
2014-03-22 19:26:17 -04:00
|
|
|
} );
|
2014-03-19 22:45:15 -04:00
|
|
|
|
2014-03-22 19:26:17 -04:00
|
|
|
return elem;
|
2014-03-19 22:45:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-19 01:31:15 -04:00
|
|
|
/**
|
|
|
|
* wp.media.view.AudioDetails
|
|
|
|
*
|
|
|
|
* @contructor
|
|
|
|
* @augments wp.media.view.MediaDetails
|
|
|
|
* @augments wp.media.view.Settings.AttachmentDisplay
|
|
|
|
* @augments wp.media.view.Settings
|
|
|
|
* @augments wp.media.View
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
*/
|
|
|
|
media.view.AudioDetails = media.view.MediaDetails.extend({
|
|
|
|
className: 'audio-details',
|
|
|
|
template: media.template('audio-details'),
|
|
|
|
|
|
|
|
setMedia: function() {
|
|
|
|
var audio = this.$('.wp-audio-shortcode');
|
|
|
|
|
|
|
|
if ( audio.find( 'source' ).length ) {
|
|
|
|
if ( audio.is(':hidden') ) {
|
|
|
|
audio.show();
|
|
|
|
}
|
|
|
|
this.media = media.view.MediaDetails.prepareSrc( audio.get(0) );
|
|
|
|
} else {
|
|
|
|
audio.hide();
|
|
|
|
this.media = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.media.view.VideoDetails
|
|
|
|
*
|
|
|
|
* @contructor
|
|
|
|
* @augments wp.media.view.MediaDetails
|
|
|
|
* @augments wp.media.view.Settings.AttachmentDisplay
|
|
|
|
* @augments wp.media.view.Settings
|
|
|
|
* @augments wp.media.View
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
*/
|
|
|
|
media.view.VideoDetails = media.view.MediaDetails.extend({
|
|
|
|
className: 'video-details',
|
|
|
|
template: media.template('video-details'),
|
|
|
|
|
|
|
|
setMedia: function() {
|
|
|
|
var video = this.$('.wp-video-shortcode');
|
|
|
|
|
|
|
|
if ( video.find( 'source' ).length ) {
|
|
|
|
if ( video.is(':hidden') ) {
|
|
|
|
video.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! video.hasClass('youtube-video') ) {
|
|
|
|
this.media = media.view.MediaDetails.prepareSrc( video.get(0) );
|
|
|
|
} else {
|
|
|
|
this.media = video.get(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
video.hide();
|
|
|
|
this.media = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-20 18:23:15 -04:00
|
|
|
/**
|
|
|
|
* Event binding
|
|
|
|
*/
|
2014-03-19 01:31:15 -04:00
|
|
|
function init() {
|
|
|
|
$(document.body)
|
2014-03-22 23:16:14 -04:00
|
|
|
.on( 'click', '.add-media-source', function( e ) {
|
|
|
|
media.frame.lastMime = $( e.currentTarget ).data( 'mime' );
|
|
|
|
media.frame.setState( 'add-' + media.frame.defaults.id + '-source' );
|
2014-03-19 01:31:15 -04:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
$( init );
|
|
|
|
|
2014-04-11 20:46:14 -04:00
|
|
|
}(jQuery, _, Backbone));
|