This repository has been archived by the owner. It is now read-only.

Gallery Widget #120

Merged
merged 43 commits into from Sep 19, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+15 −14
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Fix travis issues, prevent JS error.

  • Loading branch information...
timmyc committed May 3, 2017
commit 75a466cc914966a686636b2572a27834185e0a21
@@ -1,5 +1,5 @@
/* eslint consistent-this: [ "error", "control" ] */
(function( component ) {
(function( component, $ ) {
'use strict';
var GalleryWidgetModel, GalleryWidgetControl, GalleryDetailsMediaFrame;
@@ -64,8 +64,6 @@
* @constructor
*/
GalleryWidgetControl = component.MediaWidgetControl.extend( {
/**
* Render preview.
*
@@ -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() ) );
},
/**
@@ -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();
} )
} );
} );
@@ -163,4 +162,4 @@
component.controlConstructors.media_gallery = GalleryWidgetControl;
component.modelConstructors.media_gallery = GalleryWidgetModel;
})( wp.mediaWidgets );
})( wp.mediaWidgets, jQuery );
@@ -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' ) )
),
@@ -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 );
}
@@ -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 ) { #>

This comment has been minimized.

@timmyc

timmyc Aug 17, 2017

Collaborator

As mentioned in the #120 (comment) I posted, we will likely want to revisit this preview logic and maybe only show the first 2-3 images in a larger gallery.

<dl class="gallery-item">
ProTip! Use n and p to navigate between commits in a pull request.