Widgets: Further refine WP JS coding style in media widgets code.

Props afercia.
See #32417.

Built from https://develop.svn.wordpress.org/trunk@40821


git-svn-id: http://core.svn.wordpress.org/trunk@40678 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-05-22 22:05:42 +00:00
parent e083a1aff7
commit 6e935e7f20
5 changed files with 32 additions and 32 deletions

View File

@ -19,18 +19,18 @@
*/ */
createStates: function createStates() { createStates: function createStates() {
this.states.add([ this.states.add([
new wp.media.controller.AudioDetails( { new wp.media.controller.AudioDetails({
media: this.media media: this.media
} ), }),
new wp.media.controller.MediaLibrary( { new wp.media.controller.MediaLibrary({
type: 'audio', type: 'audio',
id: 'add-audio-source', id: 'add-audio-source',
title: wp.media.view.l10n.audioAddSourceTitle, title: wp.media.view.l10n.audioAddSourceTitle,
toolbar: 'add-audio-source', toolbar: 'add-audio-source',
media: this.media, media: this.media,
menu: false menu: false
} ) })
]); ]);
} }
}); });
@ -43,7 +43,7 @@
* @class AudioWidgetModel * @class AudioWidgetModel
* @constructor * @constructor
*/ */
AudioWidgetModel = component.MediaWidgetModel.extend( {} ); AudioWidgetModel = component.MediaWidgetModel.extend({});
/** /**
* Audio widget control. * Audio widget control.
@ -53,7 +53,7 @@
* @class AudioWidgetModel * @class AudioWidgetModel
* @constructor * @constructor
*/ */
AudioWidgetControl = component.MediaWidgetControl.extend( { AudioWidgetControl = component.MediaWidgetControl.extend({
/** /**
* Show display settings. * Show display settings.
@ -92,13 +92,13 @@
previewContainer = control.$el.find( '.media-widget-preview' ); previewContainer = control.$el.find( '.media-widget-preview' );
previewTemplate = wp.template( 'wp-media-widget-audio-preview' ); previewTemplate = wp.template( 'wp-media-widget-audio-preview' );
previewContainer.html( previewTemplate( { previewContainer.html( previewTemplate({
model: { model: {
attachment_id: control.model.get( 'attachment_id' ), attachment_id: control.model.get( 'attachment_id' ),
src: attachmentUrl src: attachmentUrl
}, },
error: control.model.get( 'error' ) error: control.model.get( 'error' )
} ) ); }));
wp.mediaelement.initialize(); wp.mediaelement.initialize();
}, },
@ -117,7 +117,7 @@
frame: 'audio', frame: 'audio',
state: 'audio-details', state: 'audio-details',
metadata: metadata metadata: metadata
} ); });
wp.media.frame = mediaFrame; wp.media.frame = mediaFrame;
mediaFrame.$el.addClass( 'media-widget' ); mediaFrame.$el.addClass( 'media-widget' );
@ -141,7 +141,7 @@
mediaFrame.open(); mediaFrame.open();
} }
} ); });
// Exports. // Exports.
component.controlConstructors.media_audio = AudioWidgetControl; component.controlConstructors.media_audio = AudioWidgetControl;

View File

@ -23,23 +23,23 @@
media: this.media media: this.media
}), }),
new wp.media.controller.MediaLibrary( { new wp.media.controller.MediaLibrary({
type: 'video', type: 'video',
id: 'add-video-source', id: 'add-video-source',
title: wp.media.view.l10n.videoAddSourceTitle, title: wp.media.view.l10n.videoAddSourceTitle,
toolbar: 'add-video-source', toolbar: 'add-video-source',
media: this.media, media: this.media,
menu: false menu: false
} ), }),
new wp.media.controller.MediaLibrary( { new wp.media.controller.MediaLibrary({
type: 'text', type: 'text',
id: 'add-track', id: 'add-track',
title: wp.media.view.l10n.videoAddTrackTitle, title: wp.media.view.l10n.videoAddTrackTitle,
toolbar: 'add-track', toolbar: 'add-track',
media: this.media, media: this.media,
menu: 'video-details' menu: 'video-details'
} ) })
]); ]);
} }
}); });
@ -52,7 +52,7 @@
* @class VideoWidgetModel * @class VideoWidgetModel
* @constructor * @constructor
*/ */
VideoWidgetModel = component.MediaWidgetModel.extend( {} ); VideoWidgetModel = component.MediaWidgetModel.extend({});
/** /**
* Video widget control. * Video widget control.
@ -62,7 +62,7 @@
* @class VideoWidgetControl * @class VideoWidgetControl
* @constructor * @constructor
*/ */
VideoWidgetControl = component.MediaWidgetControl.extend( { VideoWidgetControl = component.MediaWidgetControl.extend({
/** /**
* Show display settings. * Show display settings.
@ -181,7 +181,7 @@
previewContainer = control.$el.find( '.media-widget-preview' ); previewContainer = control.$el.find( '.media-widget-preview' );
previewTemplate = wp.template( 'wp-media-widget-video-preview' ); previewTemplate = wp.template( 'wp-media-widget-video-preview' );
previewContainer.html( previewTemplate( { previewContainer.html( previewTemplate({
model: { model: {
attachment_id: control.model.get( 'attachment_id' ), attachment_id: control.model.get( 'attachment_id' ),
src: attachmentUrl, src: attachmentUrl,
@ -189,7 +189,7 @@
}, },
is_hosted_embed: isHostedEmbed, is_hosted_embed: isHostedEmbed,
error: error error: error
} ) ); }));
wp.mediaelement.initialize(); wp.mediaelement.initialize();
}, },
@ -232,7 +232,7 @@
mediaFrame.open(); mediaFrame.open();
} }
} ); });
// Exports. // Exports.
component.controlConstructors.media_video = VideoWidgetControl; component.controlConstructors.media_video = VideoWidgetControl;

View File

@ -134,7 +134,7 @@ wp.mediaWidgets = ( function( $ ) {
noticeContainer.empty(); noticeContainer.empty();
noticeContainer.append( $( '<p>', { noticeContainer.append( $( '<p>', {
html: notice html: notice
} ) ); }));
noticeContainer.slideDown( 'fast' ); noticeContainer.slideDown( 'fast' );
} }
}, },
@ -217,7 +217,7 @@ wp.mediaWidgets = ( function( $ ) {
* *
* @returns {void} * @returns {void}
*/ */
renderFail: function renderFail( ) { renderFail: function renderFail() {
var embedLinkView = this; // eslint-disable-line consistent-this var embedLinkView = this; // eslint-disable-line consistent-this
$( '#embed-url-field' ).addClass( 'invalid' ); $( '#embed-url-field' ).addClass( 'invalid' );
embedLinkView.setErrorNotice( embedLinkView.controller.options.invalidEmbedTypeError || 'ERROR' ); embedLinkView.setErrorNotice( embedLinkView.controller.options.invalidEmbedTypeError || 'ERROR' );
@ -230,7 +230,7 @@ wp.mediaWidgets = ( function( $ ) {
controller: this.controller, controller: this.controller,
model: this.model.props, model: this.model.props,
priority: 40 priority: 40
}) ); }));
} }
}); });
@ -258,7 +258,7 @@ wp.mediaWidgets = ( function( $ ) {
mime = specificMimes.join( ',' ); mime = specificMimes.join( ',' );
} }
this.states.add( [ this.states.add([
// Main states. // Main states.
new component.PersistentDisplaySettingsLibrary({ new component.PersistentDisplaySettingsLibrary({
@ -287,7 +287,7 @@ wp.mediaWidgets = ( function( $ ) {
type: 'image' === this.options.mimeType ? 'image' : 'link', type: 'image' === this.options.mimeType ? 'image' : 'link',
invalidEmbedTypeError: this.options.invalidEmbedTypeError invalidEmbedTypeError: this.options.invalidEmbedTypeError
}) })
] ); ]);
}, },
/** /**
@ -643,7 +643,7 @@ wp.mediaWidgets = ( function( $ ) {
var control = this, selection, mediaFrame, defaultSync, mediaFrameProps; var control = this, selection, mediaFrame, defaultSync, mediaFrameProps;
if ( control.isSelected() && 0 !== control.model.get( 'attachment_id' ) ) { if ( control.isSelected() && 0 !== control.model.get( 'attachment_id' ) ) {
selection = new wp.media.model.Selection( [ control.selectedAttachment ] ); selection = new wp.media.model.Selection([ control.selectedAttachment ]);
} else { } else {
selection = null; selection = null;
} }
@ -745,7 +745,7 @@ wp.mediaWidgets = ( function( $ ) {
{ attachment_id: 0 }, // Because some media frames use `attachment_id` not `id`. { attachment_id: 0 }, // Because some media frames use `attachment_id` not `id`.
control.model.getEmbedResetProps() control.model.getEmbedResetProps()
); );
} else { } else {
throw new Error( 'Unexpected state: ' + state.get( 'id' ) ); throw new Error( 'Unexpected state: ' + state.get( 'id' ) );
} }
@ -760,7 +760,7 @@ wp.mediaWidgets = ( function( $ ) {
if ( ext in control.model.schema && modelProps.url !== modelProps[ ext ] ) { if ( ext in control.model.schema && modelProps.url !== modelProps[ ext ] ) {
modelProps[ ext ] = ''; modelProps[ ext ] = '';
} }
} ); });
return modelProps; return modelProps;
}, },

View File

@ -125,7 +125,7 @@ wp.textWidgets = ( function( $ ) {
} }
// Destroy any existing editor so that it can be re-initialized after a widget-updated event. // Destroy any existing editor so that it can be re-initialized after a widget-updated event.
if ( tinymce.get( id ) ) { if ( tinymce.get( id ) ) {
restoreTextMode = tinymce.get( id ).isHidden(); restoreTextMode = tinymce.get( id ).isHidden();
wp.editor.remove( id ); wp.editor.remove( id );
} }
@ -135,7 +135,7 @@ wp.textWidgets = ( function( $ ) {
wpautop: true wpautop: true
}, },
quicktags: true quicktags: true
} ); });
editor = window.tinymce.get( id ); editor = window.tinymce.get( id );
if ( ! editor ) { if ( ! editor ) {
@ -190,12 +190,12 @@ wp.textWidgets = ( function( $ ) {
}; };
editor.on( 'focus', function() { editor.on( 'focus', function() {
control.editorFocused = true; control.editorFocused = true;
} ); });
editor.on( 'NodeChange', _.debounce( triggerChangeIfDirty, changeDebounceDelay ) ); editor.on( 'NodeChange', _.debounce( triggerChangeIfDirty, changeDebounceDelay ) );
editor.on( 'blur', function() { editor.on( 'blur', function() {
control.editorFocused = false; control.editorFocused = false;
triggerChangeIfDirty(); triggerChangeIfDirty();
} ); });
control.editor = editor; control.editor = editor;
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.8-beta2-40820'; $wp_version = '4.8-beta2-40821';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.