From 63dd1ca5189d52a64b00be093a31e9a54ebbe449 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Fri, 9 Nov 2012 09:59:36 +0000 Subject: [PATCH] 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: https://develop.svn.wordpress.org/trunk@22495 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/js/media-upload.js | 1 + wp-includes/js/mce-view.js | 1 + wp-includes/js/media-models.js | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wp-admin/js/media-upload.js b/wp-admin/js/media-upload.js index 60dc0cb87b..2d9972a4ae 100644 --- a/wp-admin/js/media-upload.js +++ b/wp-admin/js/media-upload.js @@ -103,6 +103,7 @@ var tb_position; return workflow; workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { + frame: 'post', title: wp.media.view.l10n.insertMedia, multiple: true } ) ); diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index c34c8d4547..345b517a2a 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -694,6 +694,7 @@ window.wp = window.wp || {}; return; this.frame = wp.media({ + frame: 'post', state: 'gallery-edit', title: mceview.l10n.editGallery, editing: true, diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index dd42f5ab21..5005ff724e 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -7,15 +7,30 @@ window.wp = window.wp || {}; * wp.media( attributes ) * * 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. * * @param {object} attributes The properties passed to the main media controller. * @return {object} A media workflow. */ media = wp.media = function( attributes ) { - if ( media.view.MediaFrame.Post ) - return new media.view.MediaFrame.Post( attributes ).render().attach().open(); + var MediaFrame = media.view.MediaFrame, + 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: {} });