From 30440dbb6685b4565532e32f2cd890e7d8e90547 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Thu, 6 Dec 2012 05:06:49 +0000 Subject: [PATCH] Add a canonical location for media frames, an alias to fetch attachments, and frame caching to custom header. fixes #22775. git-svn-id: http://core.svn.wordpress.org/trunk@23092 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/custom-background.js | 2 +- wp-admin/js/custom-header.js | 8 +++++++- wp-includes/js/media-models.js | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/wp-admin/js/custom-background.js b/wp-admin/js/custom-background.js index fd22cc56a7..c41ca6b00b 100644 --- a/wp-admin/js/custom-background.js +++ b/wp-admin/js/custom-background.js @@ -32,7 +32,7 @@ } // Create the media frame. - frame = wp.media({ + frame = wp.media.frames.customBackground = wp.media({ // Set the title of the modal. title: $el.data('choose'), diff --git a/wp-admin/js/custom-header.js b/wp-admin/js/custom-header.js index d858359238..d93ac3895c 100644 --- a/wp-admin/js/custom-header.js +++ b/wp-admin/js/custom-header.js @@ -18,8 +18,14 @@ var $el = $(this); event.preventDefault(); + // If the media frame already exists, reopen it. + if ( frame ) { + frame.open(); + return; + } + // Create the media frame. - frame = wp.media({ + frame = wp.media.frames.customHeader = wp.media({ // Set the title of the modal. title: $el.data('choose'), diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index afc9e7d518..34cce0b7ad 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -34,7 +34,7 @@ window.wp = window.wp || {}; return frame; }; - _.extend( media, { model: {}, view: {}, controller: {} }); + _.extend( media, { model: {}, view: {}, controller: {}, frames: {} }); // Link any localized strings. l10n = media.model.l10n = typeof _wpMediaModelsL10n === 'undefined' ? {} : _wpMediaModelsL10n; @@ -216,6 +216,13 @@ window.wp = window.wp || {}; * ======================================================================== */ + /** + * wp.media.attachment + */ + media.attachment = function( id ) { + return Attachment.get( id ); + }; + /** * wp.media.model.Attachment */