Improve inline doc descriptions in media-views.js.

Props ericlewis.
See #28459.


git-svn-id: https://develop.svn.wordpress.org/trunk@28688 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
wonderboymusic 2014-06-06 14:12:03 +00:00
parent 67639d7e91
commit 655d03da0a
2 changed files with 69 additions and 34 deletions

View File

@ -5,7 +5,7 @@ window.wp = window.wp || {};
var Attachment, Attachments, Query, PostImage, compare, l10n, media; var Attachment, Attachments, Query, PostImage, compare, l10n, media;
/** /**
* wp.media( attributes ) * Create and return a media frame.
* *
* Handles the default media experience. Automatically creates * Handles the default media experience. Automatically creates
* and opens a media frame, and returns the result. * and opens a media frame, and returns the result.
@ -31,7 +31,7 @@ window.wp = window.wp || {};
} else if ( 'post' === attributes.frame && MediaFrame.Post ) { } else if ( 'post' === attributes.frame && MediaFrame.Post ) {
frame = new MediaFrame.Post( attributes ); frame = new MediaFrame.Post( attributes );
} else if ( 'manage' === attributes.frame && MediaFrame.Manage ) { } else if ( 'manage' === attributes.frame && MediaFrame.Manage ) {
frame = new MediaFrame.Manage( attributes ); frame = new MediaFrame.Manage( attributes );
} else if ( 'image' === attributes.frame && MediaFrame.ImageDetails ) { } else if ( 'image' === attributes.frame && MediaFrame.ImageDetails ) {
frame = new MediaFrame.ImageDetails( attributes ); frame = new MediaFrame.ImageDetails( attributes );
} else if ( 'audio' === attributes.frame && MediaFrame.AudioDetails ) { } else if ( 'audio' === attributes.frame && MediaFrame.AudioDetails ) {

View File

@ -92,14 +92,16 @@
_.extend( media.controller.Region.prototype, { _.extend( media.controller.Region.prototype, {
/** /**
* Switch modes * Activate a mode.
* *
* @param {string} mode * @param {string} mode
* *
* @fires wp.media.controller.Region#{id}:activate:{mode} * @fires this.view#{this.id}:activate:{this._mode}
* @fires wp.media.controller.Region#{id}:deactivate:{mode} * @fires this.view#{this.id}:activate
* @fires this.view#{this.id}:deactivate:{this._mode}
* @fires this.view#{this.id}:deactivate
* *
* @returns {wp.media.controller.Region} Returns itself to allow chaining * @returns {wp.media.controller.Region} Returns itself to allow chaining.
*/ */
mode: function( mode ) { mode: function( mode ) {
if ( ! mode ) { if ( ! mode ) {
@ -110,27 +112,40 @@
return this; return this;
} }
/**
* Region mode deactivation event.
*
* @event this.view#{this.id}:deactivate:{this._mode}
* @event this.view#{this.id}:deactivate
*/
this.trigger('deactivate'); this.trigger('deactivate');
this._mode = mode; this._mode = mode;
this.render( mode ); this.render( mode );
/**
* Region mode activation event.
*
* @event this.view#{this.id}:activate:{this._mode}
* @event this.view#{this.id}:activate
*/
this.trigger('activate'); this.trigger('activate');
return this; return this;
}, },
/** /**
* Render a new mode, the view is set in the `create` callback method * Render a mode.
* of the extending class
*
* If no mode is provided, just re-render the current mode.
* If the provided mode isn't active, perform a full switch.
* *
* @param {string} mode * @param {string} mode
* *
* @fires wp.media.controller.Region#{id}:create:{mode} * @fires this.view#{this.id}:create:{this._mode}
* @fires wp.media.controller.Region#{id}:render:{mode} * @fires this.view#{this.id}:create
* @fires this.view#{this.id}:render:{this._mode}
* @fires this.view#{this.id}:render
* *
* @returns {wp.media.controller.Region} Returns itself to allow chaining * @returns {wp.media.controller.Region} Returns itself to allow chaining
*/ */
render: function( mode ) { render: function( mode ) {
// If the mode isn't active, activate it.
if ( mode && mode !== this._mode ) { if ( mode && mode !== this._mode ) {
return this.mode( mode ); return this.mode( mode );
} }
@ -138,8 +153,25 @@
var set = { view: null }, var set = { view: null },
view; view;
/**
* Create region view event.
*
* Region view creation takes place in an event callback on the frame.
*
* @event this.view#{this.id}:create:{this._mode}
* @event this.view#{this.id}:create
*/
this.trigger( 'create', set ); this.trigger( 'create', set );
view = set.view; view = set.view;
/**
* Render region view event.
*
* Region view creation takes place in an event callback on the frame.
*
* @event this.view#{this.id}:create:{this._mode}
* @event this.view#{this.id}:create
*/
this.trigger( 'render', view ); this.trigger( 'render', view );
if ( view ) { if ( view ) {
this.set( view ); this.set( view );
@ -148,13 +180,17 @@
}, },
/** /**
* @returns {wp.media.View} Returns the selector's first subview * Get the region's view.
*
* @returns {wp.media.View}
*/ */
get: function() { get: function() {
return this.view.views.first( this.selector ); return this.view.views.first( this.selector );
}, },
/** /**
* Set the region's view as a subview of the frame.
*
* @param {Array|Object} views * @param {Array|Object} views
* @param {Object} [options={}] * @param {Object} [options={}]
* @returns {wp.Backbone.Subviews} Subviews is returned to allow chaining * @returns {wp.Backbone.Subviews} Subviews is returned to allow chaining
@ -167,10 +203,10 @@
}, },
/** /**
* Helper function to trigger view events based on {id}:{event}:{mode} * Trigger regional view events on the frame.
* *
* @param {string} event * @param {string} event
* @returns {undefined|wp.media.controller.Region} Returns itself to allow chaining * @returns {undefined|wp.media.controller.Region} Returns itself to allow chaining.
*/ */
trigger: function( event ) { trigger: function( event ) {
var base, args; var base, args;
@ -182,11 +218,11 @@
args = _.toArray( arguments ); args = _.toArray( arguments );
base = this.id + ':' + event; base = this.id + ':' + event;
// Trigger `region:action:mode` event. // Trigger `{this.id}:{event}:{this._mode}` event on the frame.
args[0] = base + ':' + this._mode; args[0] = base + ':' + this._mode;
this.view.trigger.apply( this.view, args ); this.view.trigger.apply( this.view, args );
// Trigger `region:action` event. // Trigger `{this.id}:{event}` event on the frame.
args[0] = base; args[0] = base;
this.view.trigger.apply( this.view, args ); this.view.trigger.apply( this.view, args );
return this; return this;
@ -210,7 +246,6 @@
// Use Backbone's self-propagating `extend` inheritance method. // Use Backbone's self-propagating `extend` inheritance method.
media.controller.StateMachine.extend = Backbone.Model.extend; media.controller.StateMachine.extend = Backbone.Model.extend;
// Add events to the `StateMachine`.
_.extend( media.controller.StateMachine.prototype, Backbone.Events, { _.extend( media.controller.StateMachine.prototype, Backbone.Events, {
/** /**
* Fetch a state. * Fetch a state.
@ -286,10 +321,10 @@
} }
}); });
// Map methods from the `states` collection to the `StateMachine` itself. // Map all event binding and triggering on a StateMachine to its `states` collection.
_.each([ 'on', 'off', 'trigger' ], function( method ) { _.each([ 'on', 'off', 'trigger' ], function( method ) {
/** /**
* @returns {wp.media.controller.StateMachine} Returns itself to allow chaining * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining.
*/ */
media.controller.StateMachine.prototype[ method ] = function() { media.controller.StateMachine.prototype[ method ] = function() {
// Ensure that the `states` collection exists so the `StateMachine` // Ensure that the `states` collection exists so the `StateMachine`
@ -304,10 +339,9 @@
/** /**
* wp.media.controller.State * wp.media.controller.State
* *
* A state is a step in a workflow that when set will trigger * A state is a step in a workflow that when set will trigger the controllers
* the controllers for the regions to be updated as specified. This * for the regions to be updated as specified in the frame. This is the base
* class is the base class that the various states used in the media * class that the various states used in wp.media extend.
* modals extend.
* *
* @constructor * @constructor
* @augments Backbone.Model * @augments Backbone.Model
@ -538,7 +572,7 @@
}; };
/** /**
* wp.media.controller.Library * A state for choosing an attachment from the media library.
* *
* @constructor * @constructor
* @augments wp.media.controller.State * @augments wp.media.controller.State
@ -747,7 +781,7 @@
_.extend( media.controller.Library.prototype, media.selectionSync ); _.extend( media.controller.Library.prototype, media.selectionSync );
/** /**
* wp.media.controller.ImageDetails * A state for editing the settings of an image within a content editor.
* *
* @constructor * @constructor
* @augments wp.media.controller.State * @augments wp.media.controller.State
@ -778,7 +812,7 @@
}); });
/** /**
* wp.media.controller.GalleryEdit * A state for editing a gallery's images and settings.
* *
* @constructor * @constructor
* @augments wp.media.controller.Library * @augments wp.media.controller.Library
@ -877,7 +911,7 @@
}); });
/** /**
* wp.media.controller.GalleryAdd * A state for adding an image to a gallery.
* *
* @constructor * @constructor
* @augments wp.media.controller.Library * @augments wp.media.controller.Library
@ -1111,7 +1145,7 @@
}); });
/** /**
* wp.media.controller.FeaturedImage * A state for selecting a featured image for a post.
* *
* @constructor * @constructor
* @augments wp.media.controller.Library * @augments wp.media.controller.Library
@ -1194,9 +1228,7 @@
}); });
/** /**
* wp.media.controller.ReplaceImage * A state for replacing an image.
*
* Replace a selected single image
* *
* @constructor * @constructor
* @augments wp.media.controller.Library * @augments wp.media.controller.Library
@ -1266,7 +1298,7 @@
}); });
/** /**
* wp.media.controller.EditImage * A state for editing (cropping, etc.) an image.
* *
* @constructor * @constructor
* @augments wp.media.controller.State * @augments wp.media.controller.State
@ -4530,6 +4562,9 @@
* @augments Backbone.View * @augments Backbone.View
*/ */
media.view.RouterItem = media.view.MenuItem.extend({ media.view.RouterItem = media.view.MenuItem.extend({
/**
* On click handler to activate the content region's corresponding mode.
*/
click: function() { click: function() {
var contentMode = this.options.contentMode; var contentMode = this.options.contentMode;
if ( contentMode ) { if ( contentMode ) {