Media JS: Use basic upload/library by default.

`wp.media` now recognizes the `frame` attribute (currently a string; either'select' or 'post') and defaults to using a basic select frame. It also checks for the existence of classes in a safer fashion, as it does not assume the `MediaFrame` property exists.

see #21390.


git-svn-id: http://core.svn.wordpress.org/trunk@22495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2012-11-09 09:59:36 +00:00
parent 9c7acdfe7c
commit 4a008574d2
3 changed files with 20 additions and 3 deletions

View File

@ -103,6 +103,7 @@ var tb_position;
return workflow; return workflow;
workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
frame: 'post',
title: wp.media.view.l10n.insertMedia, title: wp.media.view.l10n.insertMedia,
multiple: true multiple: true
} ) ); } ) );

View File

@ -694,6 +694,7 @@ window.wp = window.wp || {};
return; return;
this.frame = wp.media({ this.frame = wp.media({
frame: 'post',
state: 'gallery-edit', state: 'gallery-edit',
title: mceview.l10n.editGallery, title: mceview.l10n.editGallery,
editing: true, editing: true,

View File

@ -7,15 +7,30 @@ window.wp = window.wp || {};
* wp.media( attributes ) * wp.media( attributes )
* *
* Handles the default media experience. Automatically creates * Handles the default media experience. Automatically creates
* and opens a media workflow, and returns the result. * and opens a media frame, and returns the result.
* Does nothing if the controllers do not exist. * Does nothing if the controllers do not exist.
* *
* @param {object} attributes The properties passed to the main media controller. * @param {object} attributes The properties passed to the main media controller.
* @return {object} A media workflow. * @return {object} A media workflow.
*/ */
media = wp.media = function( attributes ) { media = wp.media = function( attributes ) {
if ( media.view.MediaFrame.Post ) var MediaFrame = media.view.MediaFrame,
return new media.view.MediaFrame.Post( attributes ).render().attach().open(); frame;
if ( ! MediaFrame )
return;
attributes = _.defaults( attributes || {}, {
frame: 'select'
});
if ( 'select' === attributes.frame && MediaFrame.Select )
frame = new MediaFrame.Select( attributes );
else if ( 'post' === attributes.frame && MediaFrame.Post )
frame = new MediaFrame.Post( attributes );
delete attributes.frame;
return frame.render().attach().open();
}; };
_.extend( media, { model: {}, view: {}, controller: {} }); _.extend( media, { model: {}, view: {}, controller: {} });