This repository has been archived by the owner on Aug 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Gallery Widget #120
Merged
Merged
Gallery Widget #120
Changes from 18 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
634f3cd
[WIP] Gallery Widget
obenland f8e7949
Add preview for galleries
obenland 905edbc
Fix travis issues, prevent JS error.
timmyc 77463cd
[WIP] Gallery Widget
obenland 46fe3b4
Add preview for galleries
obenland 75a466c
Fix travis issues, prevent JS error.
timmyc 88a5d0b
Rebase and get things somewhat operational again.
timmyc 984e68f
Fix preview for gallery
9aae63b
Fix linting errors.
timmyc 053147f
Fix edit gallery button.
a063060
Not sure how to fix travis failing, trying this.
timmyc 69e7a8f
try that again
timmyc ac13f7c
Remove another rule to try and get CI to pass.
timmyc 41b6ea9
Fix edit gallery button
0203390
Merge branch 'add/gallery-widget' of https://github.com/xwp/wp-core-m…
9469601
Fix unit tests for WP 4.8
westonruter aebe864
Skip phpcs on PHP 5.2
westonruter 19c44bd
Update dev-lib
westonruter 18896da
Updates and qunit tests.
timmyc bfde3ee
Fix backwards compat issue, add phpunit test
timmyc f072ef3
Remove attachment data from gallery widget schema.
joemcgill 4363f80
Update dev-lib and use precise distro so PHP 5.2 is available
westonruter 1f490cd
Fix jscs and jshint issues
westonruter bcad6c1
Remove attachments from expected schema in unit test
joemcgill c1d7c4f
Merge pull request #187 from xwp/add/gallery-widget-without-attachmen…
westonruter cfe62b4
Update the widget preview design.
joemcgill 2e8c03a
Register gallery widget CSS via wp_default_styles() and enqueue in wi…
westonruter fdf4f14
Show number of additional images if more than 5
joemcgill d61f3e9
Update preview to use an image as final placeholder
joemcgill ff52e6c
Merge pull request #188 from xwp/update/gallery-widget-preview-design
westonruter a4dacce
Allow gallery preview clicking to be shortcut for edit gallery button
westonruter fd47023
Persist random order setting from gallery; refactor method for fetchi…
westonruter ece64e9
Fix rendering on change and reset
westonruter be35f36
Add missing replace_media label
westonruter e1429f0
Ensure all gallery settings get synced to widget
westonruter 94d6ab2
Update button label to 'Replace Gallery' instead of 'Replace Images' …
westonruter f2c6a49
Remove obsolete qunit test
westonruter 4e343ef
Add handleAttachmentDestroy to factor out former removeAttachmentId l…
westonruter 70480f5
Ensure r41248 from core is applied to defaultSync logic
westonruter daa0039
Remove obsolete access phpDoc tags
westonruter e82a420
Use all gallery shortcode properties when rendering shortcode.
joemcgill 775f498
Whitespace fix
joemcgill e5ee972
Remove disabling of syncing attachment changes to server so captions …
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule dev-lib
updated
8 files
+3 −2 | .travis.yml | |
+21 −0 | LICENSE.txt | |
+41 −15 | check-diff.sh | |
+3 −3 | class-wordpress-readme-parser.php | |
+5 −4 | generate-markdown-readme | |
+8 −10 | package.json | |
+8 −0 | phpcs.xml | |
+5 −4 | readme.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
/* eslint consistent-this: [ "error", "control" ] */ | ||
(function( component, $ ) { | ||
'use strict'; | ||
|
||
var GalleryWidgetModel, GalleryWidgetControl, GalleryDetailsMediaFrame; | ||
|
||
/** | ||
* Custom gallery details frame. | ||
* | ||
* @class GalleryDetailsMediaFrame | ||
* @constructor | ||
*/ | ||
GalleryDetailsMediaFrame = wp.media.view.MediaFrame.Post.extend( { | ||
|
||
/** | ||
* Create the default states. | ||
* | ||
* @returns {void} | ||
*/ | ||
createStates: function createStates() { | ||
this.states.add([ | ||
new wp.media.controller.Library({ | ||
id: 'gallery', | ||
title: wp.media.view.l10n.createGalleryTitle, | ||
priority: 40, | ||
toolbar: 'main-gallery', | ||
filterable: 'uploaded', | ||
multiple: 'add', | ||
editable: true, | ||
|
||
library: wp.media.query( _.defaults({ | ||
type: 'image' | ||
}, this.options.library ) ) | ||
}), | ||
|
||
// Gallery states. | ||
new wp.media.controller.GalleryEdit({ | ||
library: this.options.selection, | ||
editing: this.options.editing, | ||
menu: 'gallery' | ||
}), | ||
|
||
new wp.media.controller.GalleryAdd() | ||
]); | ||
} | ||
} ); | ||
|
||
/** | ||
* Gallery widget model. | ||
* | ||
* See WP_Widget_Gallery::enqueue_admin_scripts() for amending prototype from PHP exports. | ||
* | ||
* @class GalleryWidgetModel | ||
* @constructor | ||
*/ | ||
GalleryWidgetModel = component.MediaWidgetModel.extend( {} ); | ||
|
||
/** | ||
* Gallery widget control. | ||
* | ||
* See WP_Widget_Gallery::enqueue_admin_scripts() for amending prototype from PHP exports. | ||
* | ||
* @class GalleryWidgetControl | ||
* @constructor | ||
*/ | ||
GalleryWidgetControl = component.MediaWidgetControl.extend( { | ||
/** | ||
* Render preview. | ||
* | ||
* @returns {void} | ||
*/ | ||
renderPreview: function renderPreview() { | ||
var control = this, previewContainer, previewTemplate; | ||
previewContainer = control.$el.find( '.media-widget-preview' ); | ||
previewTemplate = wp.template( 'wp-media-widget-gallery-preview' ); | ||
previewContainer.html( previewTemplate( control.previewTemplateProps.toJSON() ) ); | ||
}, | ||
isSelected: function isSelected() { | ||
var control = this; | ||
|
||
if ( control.model.get( 'error' ) ) { | ||
return false; | ||
} | ||
|
||
return Boolean( control.model.get( 'ids' ) || control.model.get( 'attachments' ) ); | ||
}, | ||
/** | ||
* Open the media select frame to edit images. | ||
* | ||
* @returns {void} | ||
*/ | ||
editMedia: function editMedia() { | ||
var control = this, selection, mediaFrame, defaultSync, mediaFrameProps; | ||
if ( control.isSelected() && 0 !== control.model.get( 'selection' ) ) { | ||
selection = new wp.media.model.Selection( JSON.parse( control.model.get( 'attachments' ) ), { | ||
multiple: true | ||
}); | ||
} else { | ||
selection = null; | ||
} | ||
|
||
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() ); | ||
if ( mediaFrameProps.size ) { | ||
control.displaySettings.set( 'size', mediaFrameProps.size ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be used? |
||
} | ||
mediaFrame = new GalleryDetailsMediaFrame({ | ||
frame: 'manage', | ||
text: control.l10n.add_to_widget, | ||
selection: selection, | ||
mimeType: control.mime_type, | ||
selectedDisplaySettings: control.displaySettings, | ||
showDisplaySettings: control.showDisplaySettings, | ||
metadata: mediaFrameProps, | ||
editing: true, | ||
multiple: true, | ||
state: 'gallery-edit' | ||
}); | ||
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' ); | ||
|
||
if ( ! selectedImages ) { | ||
return; | ||
} | ||
|
||
// Update widget instance. | ||
control.model.set( { | ||
ids: _.pluck( selectedImages.models, 'id' ).join( ',' ), | ||
attachments: JSON.stringify( | ||
selectedImages.models.map( function( model ) { | ||
return model.toJSON(); | ||
} ) | ||
), | ||
selection: selectedImages | ||
} ); | ||
} ); | ||
|
||
// Disable syncing of attachment changes back to server. See <https://core.trac.wordpress.org/ticket/40403>. | ||
defaultSync = wp.media.model.Attachment.prototype.sync; | ||
wp.media.model.Attachment.prototype.sync = function rejectedSync() { | ||
return $.Deferred().rejectWith( this ).promise(); | ||
}; | ||
mediaFrame.on( 'close', function onClose() { | ||
wp.media.model.Attachment.prototype.sync = defaultSync; | ||
}); | ||
|
||
mediaFrame.$el.addClass( 'media-widget' ); | ||
mediaFrame.open(); | ||
|
||
// Clear the selected attachment when it is deleted in the media select frame. | ||
if ( selection ) { | ||
selection.on( 'destroy', function onDestroy( attachment ) { | ||
if ( control.model.get( 'attachment_id' ) === attachment.get( 'id' ) ) { | ||
control.model.set({ | ||
attachment_id: 0, | ||
url: '' | ||
}); | ||
} | ||
}); | ||
} | ||
}, | ||
/** | ||
* Open the media select frame to chose an item. | ||
* | ||
* @returns {void} | ||
*/ | ||
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; | ||
} | ||
|
||
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() ); | ||
if ( mediaFrameProps.size ) { | ||
control.displaySettings.set( 'size', mediaFrameProps.size ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be used? |
||
} | ||
mediaFrame = new GalleryDetailsMediaFrame({ | ||
frame: 'select', | ||
text: control.l10n.add_to_widget, | ||
selection: selection, | ||
mimeType: control.mime_type, | ||
selectedDisplaySettings: control.displaySettings, | ||
showDisplaySettings: control.showDisplaySettings, | ||
metadata: mediaFrameProps, | ||
state: 'gallery' | ||
}); | ||
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' ); | ||
|
||
if ( ! selectedImages ) { | ||
return; | ||
} | ||
|
||
// Update widget instance. | ||
control.model.set( { | ||
ids: _.pluck( selectedImages.models, 'id' ).join( ',' ), | ||
attachments: JSON.stringify( | ||
selectedImages.models.map( function( model ) { | ||
return model.toJSON(); | ||
} ) | ||
), | ||
selection: selectedImages | ||
} ); | ||
} ); | ||
|
||
// Disable syncing of attachment changes back to server. See <https://core.trac.wordpress.org/ticket/40403>. | ||
defaultSync = wp.media.model.Attachment.prototype.sync; | ||
wp.media.model.Attachment.prototype.sync = function rejectedSync() { | ||
return $.Deferred().rejectWith( this ).promise(); | ||
}; | ||
mediaFrame.on( 'close', function onClose() { | ||
wp.media.model.Attachment.prototype.sync = defaultSync; | ||
}); | ||
|
||
mediaFrame.$el.addClass( 'media-widget' ); | ||
mediaFrame.open(); | ||
|
||
// Clear the selected attachment when it is deleted in the media select frame. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we need this logic here... but will test to confirm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was needed. I confirmed. |
||
if ( selection ) { | ||
selection.on( 'destroy', function onDestroy( attachment ) { | ||
if ( control.model.get( 'attachment_id' ) === attachment.get( 'id' ) ) { | ||
control.model.set({ | ||
attachment_id: 0, | ||
url: '' | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
/* | ||
* Make sure focus is set inside of modal so that hitting Esc will close | ||
* the modal and not inadvertently cause the widget to collapse in the customizer. | ||
*/ | ||
mediaFrame.$el.find( ':focusable:first' ).focus(); | ||
} | ||
|
||
} ); | ||
|
||
// Exports. | ||
component.controlConstructors.media_gallery = GalleryWidgetControl; | ||
component.modelConstructors.media_gallery = GalleryWidgetModel; | ||
|
||
})( wp.mediaWidgets, jQuery ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to remove these two lines now that @westonruter has fixed up the CI problems.