Edit File by line
/home/barbar84/www/wp-admin/js/widgets
File: media-audio-widget.js
/**
[0] Fix | Delete
* @output wp-admin/js/widgets/media-audio-widget.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* eslint consistent-this: [ "error", "control" ] */
[4] Fix | Delete
(function( component ) {
[5] Fix | Delete
'use strict';
[6] Fix | Delete
[7] Fix | Delete
var AudioWidgetModel, AudioWidgetControl, AudioDetailsMediaFrame;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Custom audio details frame that removes the replace-audio state.
[11] Fix | Delete
*
[12] Fix | Delete
* @class wp.mediaWidgets.controlConstructors~AudioDetailsMediaFrame
[13] Fix | Delete
* @augments wp.media.view.MediaFrame.AudioDetails
[14] Fix | Delete
*/
[15] Fix | Delete
AudioDetailsMediaFrame = wp.media.view.MediaFrame.AudioDetails.extend(/** @lends wp.mediaWidgets.controlConstructors~AudioDetailsMediaFrame.prototype */{
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Create the default states.
[19] Fix | Delete
*
[20] Fix | Delete
* @return {void}
[21] Fix | Delete
*/
[22] Fix | Delete
createStates: function createStates() {
[23] Fix | Delete
this.states.add([
[24] Fix | Delete
new wp.media.controller.AudioDetails({
[25] Fix | Delete
media: this.media
[26] Fix | Delete
}),
[27] Fix | Delete
[28] Fix | Delete
new wp.media.controller.MediaLibrary({
[29] Fix | Delete
type: 'audio',
[30] Fix | Delete
id: 'add-audio-source',
[31] Fix | Delete
title: wp.media.view.l10n.audioAddSourceTitle,
[32] Fix | Delete
toolbar: 'add-audio-source',
[33] Fix | Delete
media: this.media,
[34] Fix | Delete
menu: false
[35] Fix | Delete
})
[36] Fix | Delete
]);
[37] Fix | Delete
}
[38] Fix | Delete
});
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Audio widget model.
[42] Fix | Delete
*
[43] Fix | Delete
* See WP_Widget_Audio::enqueue_admin_scripts() for amending prototype from PHP exports.
[44] Fix | Delete
*
[45] Fix | Delete
* @class wp.mediaWidgets.modelConstructors.media_audio
[46] Fix | Delete
* @augments wp.mediaWidgets.MediaWidgetModel
[47] Fix | Delete
*/
[48] Fix | Delete
AudioWidgetModel = component.MediaWidgetModel.extend({});
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Audio widget control.
[52] Fix | Delete
*
[53] Fix | Delete
* See WP_Widget_Audio::enqueue_admin_scripts() for amending prototype from PHP exports.
[54] Fix | Delete
*
[55] Fix | Delete
* @class wp.mediaWidgets.controlConstructors.media_audio
[56] Fix | Delete
* @augments wp.mediaWidgets.MediaWidgetControl
[57] Fix | Delete
*/
[58] Fix | Delete
AudioWidgetControl = component.MediaWidgetControl.extend(/** @lends wp.mediaWidgets.controlConstructors.media_audio.prototype */{
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Show display settings.
[62] Fix | Delete
*
[63] Fix | Delete
* @type {boolean}
[64] Fix | Delete
*/
[65] Fix | Delete
showDisplaySettings: false,
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Map model props to media frame props.
[69] Fix | Delete
*
[70] Fix | Delete
* @param {Object} modelProps - Model props.
[71] Fix | Delete
* @return {Object} Media frame props.
[72] Fix | Delete
*/
[73] Fix | Delete
mapModelToMediaFrameProps: function mapModelToMediaFrameProps( modelProps ) {
[74] Fix | Delete
var control = this, mediaFrameProps;
[75] Fix | Delete
mediaFrameProps = component.MediaWidgetControl.prototype.mapModelToMediaFrameProps.call( control, modelProps );
[76] Fix | Delete
mediaFrameProps.link = 'embed';
[77] Fix | Delete
return mediaFrameProps;
[78] Fix | Delete
},
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Render preview.
[82] Fix | Delete
*
[83] Fix | Delete
* @return {void}
[84] Fix | Delete
*/
[85] Fix | Delete
renderPreview: function renderPreview() {
[86] Fix | Delete
var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl;
[87] Fix | Delete
attachmentId = control.model.get( 'attachment_id' );
[88] Fix | Delete
attachmentUrl = control.model.get( 'url' );
[89] Fix | Delete
[90] Fix | Delete
if ( ! attachmentId && ! attachmentUrl ) {
[91] Fix | Delete
return;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
previewContainer = control.$el.find( '.media-widget-preview' );
[95] Fix | Delete
previewTemplate = wp.template( 'wp-media-widget-audio-preview' );
[96] Fix | Delete
[97] Fix | Delete
previewContainer.html( previewTemplate({
[98] Fix | Delete
model: {
[99] Fix | Delete
attachment_id: control.model.get( 'attachment_id' ),
[100] Fix | Delete
src: attachmentUrl
[101] Fix | Delete
},
[102] Fix | Delete
error: control.model.get( 'error' )
[103] Fix | Delete
}));
[104] Fix | Delete
wp.mediaelement.initialize();
[105] Fix | Delete
},
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Open the media audio-edit frame to modify the selected item.
[109] Fix | Delete
*
[110] Fix | Delete
* @return {void}
[111] Fix | Delete
*/
[112] Fix | Delete
editMedia: function editMedia() {
[113] Fix | Delete
var control = this, mediaFrame, metadata, updateCallback;
[114] Fix | Delete
[115] Fix | Delete
metadata = control.mapModelToMediaFrameProps( control.model.toJSON() );
[116] Fix | Delete
[117] Fix | Delete
// Set up the media frame.
[118] Fix | Delete
mediaFrame = new AudioDetailsMediaFrame({
[119] Fix | Delete
frame: 'audio',
[120] Fix | Delete
state: 'audio-details',
[121] Fix | Delete
metadata: metadata
[122] Fix | Delete
});
[123] Fix | Delete
wp.media.frame = mediaFrame;
[124] Fix | Delete
mediaFrame.$el.addClass( 'media-widget' );
[125] Fix | Delete
[126] Fix | Delete
updateCallback = function( mediaFrameProps ) {
[127] Fix | Delete
[128] Fix | Delete
// Update cached attachment object to avoid having to re-fetch. This also triggers re-rendering of preview.
[129] Fix | Delete
control.selectedAttachment.set( mediaFrameProps );
[130] Fix | Delete
[131] Fix | Delete
control.model.set( _.extend(
[132] Fix | Delete
control.model.defaults(),
[133] Fix | Delete
control.mapMediaToModelProps( mediaFrameProps ),
[134] Fix | Delete
{ error: false }
[135] Fix | Delete
) );
[136] Fix | Delete
};
[137] Fix | Delete
[138] Fix | Delete
mediaFrame.state( 'audio-details' ).on( 'update', updateCallback );
[139] Fix | Delete
mediaFrame.state( 'replace-audio' ).on( 'replace', updateCallback );
[140] Fix | Delete
mediaFrame.on( 'close', function() {
[141] Fix | Delete
mediaFrame.detach();
[142] Fix | Delete
});
[143] Fix | Delete
[144] Fix | Delete
mediaFrame.open();
[145] Fix | Delete
}
[146] Fix | Delete
});
[147] Fix | Delete
[148] Fix | Delete
// Exports.
[149] Fix | Delete
component.controlConstructors.media_audio = AudioWidgetControl;
[150] Fix | Delete
component.modelConstructors.media_audio = AudioWidgetModel;
[151] Fix | Delete
[152] Fix | Delete
})( wp.mediaWidgets );
[153] Fix | Delete
[154] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function