diff --git a/wp-admin/js/post-formats.js b/wp-admin/js/post-formats.js index f135dc1097..ed212ebb41 100644 --- a/wp-admin/js/post-formats.js +++ b/wp-admin/js/post-formats.js @@ -1,7 +1,7 @@ window.wp = window.wp || {}; (function($) { - var container, $container, mediaFrame, lastMimeType, mediaPreview, lastHeight = 360, content, + var container, $container, mediaFrame, lastMimeType, mediaPreview, lastHeight = 360, content, insertMediaButton, initialFormat = 'standard', shortClass = 'short-format', shortContentFormats = ['status', 'aside'], @@ -92,10 +92,19 @@ window.wp = window.wp || {}; } } - postFormats.currentPostFormat = format; - } + // If gallery, force it to open to gallery state + if ( 'gallery' === format ) + insertMediaButton.addClass( 'gallery' ); + else + insertMediaButton.removeClass( 'gallery' ); + + postFormats.currentPostFormat = format; + } + + $(function() { + insertMediaButton = $( '#insert-media-button' ); $container = $( '.post-formats-fields' ); initialFormat = $( '.post-format-options .active' ).data( 'wp-format' ); diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index 96a6f1cac1..3e2a651eb4 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -538,9 +538,6 @@ add: function( id, options ) { var workflow = this.get( id ); - if ( workflow ) - return workflow; - workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { frame: 'post', state: 'insert', @@ -692,9 +689,11 @@ } }, - open: function( id ) { + open: function( id, options ) { var workflow, editor; + options = options || {}; + id = this.id( id ); // Save a bookmark of the caret position in IE. @@ -709,9 +708,9 @@ workflow = this.get( id ); - // Initialize the editor's workflow if we haven't yet. - if ( ! workflow ) - workflow = this.add( id ); + // Redo workflow if state has changed + if ( ! workflow || ( workflow.options && options.state !== workflow.options.state ) ) + workflow = this.add( id, options ); return workflow.open(); }, @@ -719,7 +718,13 @@ init: function() { $(document.body).on( 'click', '.insert-media', function( event ) { var $this = $(this), - editor = $this.data('editor'); + editor = $this.data('editor'), + options = { + frame: 'post', + state: 'insert', + title: wp.media.view.l10n.addMedia, + multiple: true + }; event.preventDefault(); @@ -730,7 +735,12 @@ // See: http://core.trac.wordpress.org/ticket/22445 $this.blur(); - wp.media.editor.open( editor ); + if ( $this.hasClass( 'gallery' ) ) { + options.state = 'gallery'; + options.title = wp.media.view.l10n.createGalleryTitle; + } + + wp.media.editor.open( editor, options ); }); } };