Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

Commit

Permalink
Fix travis issues, prevent JS error.
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyc committed May 3, 2017
1 parent f8e7949 commit 905edbc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 11 additions & 12 deletions wp-admin/js/widgets/media-gallery-widget.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint consistent-this: [ "error", "control" ] */
(function( component ) {
(function( component, $ ) {
'use strict';

var GalleryWidgetModel, GalleryWidgetControl, GalleryDetailsMediaFrame;
Expand Down Expand Up @@ -64,8 +64,6 @@
* @constructor
*/
GalleryWidgetControl = component.MediaWidgetControl.extend( {


/**
* Render preview.
*
Expand All @@ -75,7 +73,7 @@
var control = this, previewContainer, previewTemplate;
previewContainer = control.$el.find( '.media-widget-preview' );
previewTemplate = wp.template( 'wp-media-widget-gallery-preview' );
previewContainer.html( previewTemplate( _.extend( control.previewTemplateProps.toJSON() ) ) );
previewContainer.html( previewTemplate( control.previewTemplateProps.toJSON() ) );
},

/**
Expand Down Expand Up @@ -109,21 +107,22 @@
});
wp.media.frame = mediaFrame; // See wp.media().


// Handle selection of a media item.
mediaFrame.on( 'update', function onUpdate( selection ) {
var state = mediaFrame.state();
mediaFrame.on( 'update', function onUpdate( selections ) {
var state = mediaFrame.state(), selectedImages;

selection = selection || state.get( 'selection' );
selectedImages = selections || state.get( 'selection' );

if ( ! selection ) {
if ( ! selectedImages ) {
return;
}

// Update widget instance.
control.model.set( {
ids: _.pluck( selection.models, 'id' ).join( ',' ),
attachments: selection.models.map( function( model ) { return model.toJSON(); } )
ids: _.pluck( selectedImages.models, 'id' ).join( ',' ),
attachments: selectedImages.models.map( function( model ) {
return model.toJSON();
} )
} );
} );

Expand Down Expand Up @@ -163,4 +162,4 @@
component.controlConstructors.media_gallery = GalleryWidgetControl;
component.modelConstructors.media_gallery = GalleryWidgetModel;

})( wp.mediaWidgets );
})( wp.mediaWidgets, jQuery );
6 changes: 4 additions & 2 deletions wp-includes/widgets/class-wp-widget-media-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct() {
'change_media' => _x( 'Add Image', 'label for button in the gallery widget; should not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Gallery', 'label for button in the gallery widget; should not be longer than ~13 characters long' ),
'missing_attachment' => sprintf(
/* translators: placeholder is URL to media library */
/* translators: placeholder is URL to media library */
__( 'We can&#8217;t find that gallery. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
Expand Down Expand Up @@ -107,9 +107,11 @@ public function render_media( $instance ) {
'ids' => $instance['ids'],
);

// @codingStandardsIgnoreStart
if ( $instance['orderby_random'] ) {
$shortcode_atts['orderby'] = 'rand';
}
// @codingStandardsIgnoreEnd

echo gallery_shortcode( $shortcode_atts );
}
Expand Down Expand Up @@ -170,7 +172,7 @@ public function render_control_template_scripts() {
<div class="notice notice-error notice-alt notice-missing-attachment">
<p><?php echo $this->l10n['missing_attachment']; ?></p>
</div>
<# } else if ( data.attachments.length ) { #>
<# } else if ( Array.isArray( data.attachments ) && data.attachments.length ) { #>
<div class="gallery gallery-columns-{{ data.columns }}">
<# _.each( data.attachments, function( attachment, index ) { #>
<dl class="gallery-item">
Expand Down

0 comments on commit 905edbc

Please sign in to comment.