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.
+23 −30
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Ensure all gallery settings get synced to widget

  • Loading branch information...
westonruter committed Sep 16, 2017
commit e1429f0d679f9abe4440135a28530046c5ec2862
@@ -221,13 +221,10 @@
var control = this, selection, mediaFrame, defaultSync, mediaFrameProps;
selection = new wp.media.model.Selection( control.selectedAttachments.models, {
multiple: true
} );
selection.gallery = new Backbone.Model({
_orderbyRandom: control.model.get( 'orderby_random' )
});
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
selection.gallery = new Backbone.Model( _.pick( mediaFrameProps, 'columns', 'link', 'size', '_orderbyRandom' ) );
if ( mediaFrameProps.size ) {
control.displaySettings.set( 'size', mediaFrameProps.size );

This comment has been minimized.

@westonruter

westonruter Sep 16, 2017

Contributor

This doesn't seem to be used?

@westonruter

westonruter Sep 16, 2017

Contributor

This doesn't seem to be used?

}
@@ -246,26 +243,25 @@
wp.media.frame = mediaFrame; // See wp.media().
// Handle selection of a media item.
mediaFrame.on( 'update', function onUpdate( selections ) {
var state = mediaFrame.state(), selectedImages;
selectedImages = selections || state.get( 'selection' );
mediaFrame.on( 'update', function onUpdate( newSelection ) {
var state = mediaFrame.state(), resultSelection;
if ( ! selectedImages ) {
resultSelection = newSelection || state.get( 'selection' );
if ( ! resultSelection ) {
return;
}
// Copy orderby_random from gallery state.
if ( selectedImages.gallery ) {
control.model.set( 'orderby_random', selectedImages.gallery.get( '_orderbyRandom' ) );
if ( resultSelection.gallery ) {
control.model.set( control.mapMediaToModelProps( resultSelection.gallery.toJSON() ) );
}
// Directly update selectedAttachments to prevent needing to do additional request.
control.selectedAttachments.reset( selectedImages.models );
control.selectedAttachments.reset( resultSelection.models );
// Update models in the widget instance.
control.model.set( {
ids: _.pluck( selectedImages.models, 'id' ).join( ',' )
ids: _.pluck( resultSelection.models, 'id' ).join( ',' ) // @todo Array.
} );
} );
@@ -301,11 +297,9 @@
*/
selectMedia: function selectMedia() {
var control = this, selection, mediaFrame, defaultSync, mediaFrameProps;
if ( control.isSelected() && 0 !== control.model.get( 'selection' ) ) {
selection = new wp.media.model.Selection( [ control.selectedAttachment ] );
} else {
selection = null;
}
selection = new wp.media.model.Selection( control.selectedAttachments.models, {
multiple: true
});
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
if ( mediaFrameProps.size ) {
@@ -324,26 +318,25 @@
wp.media.frame = mediaFrame; // See wp.media().
// Handle selection of a media item.
mediaFrame.on( 'update', function onUpdate( selections ) {
var state = mediaFrame.state(), selectedImages;
selectedImages = selections || state.get( 'selection' );
mediaFrame.on( 'update', function onUpdate( newSelection ) {
var state = mediaFrame.state(), resultSelection;
if ( ! selectedImages ) {
resultSelection = newSelection || state.get( 'selection' );
if ( ! resultSelection ) {
return;
}
// Copy orderby_random from gallery state.
if ( selectedImages.gallery ) {
control.model.set( 'orderby_random', selectedImages.gallery.get( '_orderbyRandom' ) );
if ( resultSelection.gallery ) {
control.model.set( control.mapMediaToModelProps( resultSelection.gallery.toJSON() ) );
}
// Directly update selectedAttachments to prevent needing to do additional request.
control.selectedAttachments.reset( selectedImages.models );
control.selectedAttachments.reset( resultSelection.models );
// Update widget instance.
control.model.set( {
ids: _.pluck( selectedImages.models, 'id' ).join( ',' ) // @todo Allow array.
ids: _.pluck( resultSelection.models, 'id' ).join( ',' ) // @todo Allow array.
} );
} );
@@ -4,13 +4,13 @@
*
* @package WordPress
* @subpackage Widgets
* @since 4.8.0
* @since 4.9.0
*/
/**
* Core class that implements a gallery widget.
*
* @since 4.8.0
* @since 4.9.0
*
* @see WP_Widget
*/
@@ -19,7 +19,7 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
/**
* Constructor.
*
* @since 4.8.0
* @since 4.9.0
* @access public
*/
public function __construct() {
ProTip! Use n and p to navigate between commits in a pull request.