2018-06-28 04:30:15 +02:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/widgets/media-audio-widget.js
|
|
|
|
*/
|
|
|
|
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
/* eslint consistent-this: [ "error", "control" ] */
|
|
|
|
(function( component ) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var AudioWidgetModel, AudioWidgetControl, AudioDetailsMediaFrame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom audio details frame that removes the replace-audio state.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.mediaWidgets.controlConstructors~AudioDetailsMediaFrame
|
|
|
|
* @augments wp.media.view.MediaFrame.AudioDetails
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
AudioDetailsMediaFrame = wp.media.view.MediaFrame.AudioDetails.extend(/** @lends wp.mediaWidgets.controlConstructors~AudioDetailsMediaFrame.prototype */{
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the default states.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
createStates: function createStates() {
|
|
|
|
this.states.add([
|
2017-05-23 00:05:42 +02:00
|
|
|
new wp.media.controller.AudioDetails({
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
media: this.media
|
2017-05-23 00:05:42 +02:00
|
|
|
}),
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
2017-05-23 00:05:42 +02:00
|
|
|
new wp.media.controller.MediaLibrary({
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
type: 'audio',
|
|
|
|
id: 'add-audio-source',
|
|
|
|
title: wp.media.view.l10n.audioAddSourceTitle,
|
|
|
|
toolbar: 'add-audio-source',
|
|
|
|
media: this.media,
|
|
|
|
menu: false
|
2017-05-23 00:05:42 +02:00
|
|
|
})
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio widget model.
|
|
|
|
*
|
|
|
|
* See WP_Widget_Audio::enqueue_admin_scripts() for amending prototype from PHP exports.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.mediaWidgets.modelConstructors.media_audio
|
|
|
|
* @augments wp.mediaWidgets.MediaWidgetModel
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
2017-05-23 00:05:42 +02:00
|
|
|
AudioWidgetModel = component.MediaWidgetModel.extend({});
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio widget control.
|
|
|
|
*
|
|
|
|
* See WP_Widget_Audio::enqueue_admin_scripts() for amending prototype from PHP exports.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.mediaWidgets.controlConstructors.media_audio
|
|
|
|
* @augments wp.mediaWidgets.MediaWidgetControl
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
AudioWidgetControl = component.MediaWidgetControl.extend(/** @lends wp.mediaWidgets.controlConstructors.media_audio.prototype */{
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show display settings.
|
|
|
|
*
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
showDisplaySettings: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map model props to media frame props.
|
|
|
|
*
|
|
|
|
* @param {Object} modelProps - Model props.
|
|
|
|
* @returns {Object} Media frame props.
|
|
|
|
*/
|
|
|
|
mapModelToMediaFrameProps: function mapModelToMediaFrameProps( modelProps ) {
|
|
|
|
var control = this, mediaFrameProps;
|
|
|
|
mediaFrameProps = component.MediaWidgetControl.prototype.mapModelToMediaFrameProps.call( control, modelProps );
|
|
|
|
mediaFrameProps.link = 'embed';
|
|
|
|
return mediaFrameProps;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render preview.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
renderPreview: function renderPreview() {
|
|
|
|
var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl;
|
|
|
|
attachmentId = control.model.get( 'attachment_id' );
|
|
|
|
attachmentUrl = control.model.get( 'url' );
|
|
|
|
|
|
|
|
if ( ! attachmentId && ! attachmentUrl ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
previewContainer = control.$el.find( '.media-widget-preview' );
|
|
|
|
previewTemplate = wp.template( 'wp-media-widget-audio-preview' );
|
|
|
|
|
2017-05-23 00:05:42 +02:00
|
|
|
previewContainer.html( previewTemplate({
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
model: {
|
|
|
|
attachment_id: control.model.get( 'attachment_id' ),
|
|
|
|
src: attachmentUrl
|
|
|
|
},
|
|
|
|
error: control.model.get( 'error' )
|
2017-05-23 00:05:42 +02:00
|
|
|
}));
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
wp.mediaelement.initialize();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the media audio-edit frame to modify the selected item.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
editMedia: function editMedia() {
|
|
|
|
var control = this, mediaFrame, metadata, updateCallback;
|
|
|
|
|
|
|
|
metadata = control.mapModelToMediaFrameProps( control.model.toJSON() );
|
|
|
|
|
|
|
|
// Set up the media frame.
|
|
|
|
mediaFrame = new AudioDetailsMediaFrame({
|
|
|
|
frame: 'audio',
|
|
|
|
state: 'audio-details',
|
|
|
|
metadata: metadata
|
2017-05-23 00:05:42 +02:00
|
|
|
});
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
wp.media.frame = mediaFrame;
|
|
|
|
mediaFrame.$el.addClass( 'media-widget' );
|
|
|
|
|
|
|
|
updateCallback = function( mediaFrameProps ) {
|
|
|
|
|
|
|
|
// Update cached attachment object to avoid having to re-fetch. This also triggers re-rendering of preview.
|
|
|
|
control.selectedAttachment.set( mediaFrameProps );
|
|
|
|
|
|
|
|
control.model.set( _.extend(
|
|
|
|
control.model.defaults(),
|
|
|
|
control.mapMediaToModelProps( mediaFrameProps ),
|
|
|
|
{ error: false }
|
|
|
|
) );
|
|
|
|
};
|
|
|
|
|
|
|
|
mediaFrame.state( 'audio-details' ).on( 'update', updateCallback );
|
|
|
|
mediaFrame.state( 'replace-audio' ).on( 'replace', updateCallback );
|
|
|
|
mediaFrame.on( 'close', function() {
|
|
|
|
mediaFrame.detach();
|
|
|
|
});
|
|
|
|
|
|
|
|
mediaFrame.open();
|
|
|
|
}
|
2017-05-23 00:05:42 +02:00
|
|
|
});
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
|
|
|
|
// Exports.
|
|
|
|
component.controlConstructors.media_audio = AudioWidgetControl;
|
|
|
|
component.modelConstructors.media_audio = AudioWidgetModel;
|
|
|
|
|
|
|
|
})( wp.mediaWidgets );
|