first commit
This commit is contained in:
+113
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* All of the CSS for your public-facing functionality should be
|
||||
* included in this file.
|
||||
*/
|
||||
/**
|
||||
* Environment for all styles (variables, additions, etc).
|
||||
*/
|
||||
/*--------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------*/
|
||||
.cnvs-gallery-type-justified {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 1.5rem;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item {
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
/* background: #888888; To have gray placeholders while the gallery is loading with waitThumbnailsLoad = false */
|
||||
opacity: 0.1;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item > img, .cnvs-gallery-type-justified .gallery-item > a > img {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: none;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item > .caption {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
padding: 0.5rem;
|
||||
opacity: 0;
|
||||
color: white;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
font-size: 0.75rem;
|
||||
-webkit-transition: 0.2s ease opacity;
|
||||
transition: 0.2s ease opacity;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item > .caption.caption-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified > .entry-visible {
|
||||
opacity: 1;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified > .entry-visible > img, .cnvs-gallery-type-justified > .entry-visible > a > img {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified > .jg-filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified.justified-loaded:before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified:before {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
border: 2px solid rgba(119, 119, 119, 0.25);
|
||||
border-top-color: #777;
|
||||
border-radius: 50%;
|
||||
position: relative;
|
||||
-webkit-animation: loader-rotate 1s linear infinite;
|
||||
animation: loader-rotate 1s linear infinite;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
content: "";
|
||||
}
|
||||
|
||||
@-webkit-keyframes loader-rotate {
|
||||
0% {
|
||||
-webkit-transform: rotate(0);
|
||||
transform: rotate(0);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes loader-rotate {
|
||||
0% {
|
||||
-webkit-transform: rotate(0);
|
||||
transform: rotate(0);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* All of the CSS for your public-facing functionality should be
|
||||
* included in this file.
|
||||
*/
|
||||
/**
|
||||
* Environment for all styles (variables, additions, etc).
|
||||
*/
|
||||
/*--------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------*/
|
||||
.cnvs-gallery-type-justified {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 1.5rem;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item {
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
/* background: #888888; To have gray placeholders while the gallery is loading with waitThumbnailsLoad = false */
|
||||
opacity: 0.1;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item > img, .cnvs-gallery-type-justified .gallery-item > a > img {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: none;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item > .caption {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
padding: 0.5rem;
|
||||
opacity: 0;
|
||||
color: white;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
font-size: 0.75rem;
|
||||
-webkit-transition: 0.2s ease opacity;
|
||||
transition: 0.2s ease opacity;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified .gallery-item > .caption.caption-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified > .entry-visible {
|
||||
opacity: 1;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified > .entry-visible > img, .cnvs-gallery-type-justified > .entry-visible > a > img {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified > .jg-filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified.justified-loaded:before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cnvs-gallery-type-justified:before {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
border: 2px solid rgba(119, 119, 119, 0.25);
|
||||
border-top-color: #777;
|
||||
border-radius: 50%;
|
||||
position: relative;
|
||||
-webkit-animation: loader-rotate 1s linear infinite;
|
||||
animation: loader-rotate 1s linear infinite;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
content: "";
|
||||
}
|
||||
|
||||
@-webkit-keyframes loader-rotate {
|
||||
0% {
|
||||
-webkit-transform: rotate(0);
|
||||
transform: rotate(0);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes loader-rotate {
|
||||
0% {
|
||||
-webkit-transform: rotate(0);
|
||||
transform: rotate(0);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
.cnvs-block-jg-add-media-button button.components-button {
|
||||
-webkit-box-pack: center;
|
||||
-ms-flex-pack: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
margin-top: 20px;
|
||||
padding: 20px;
|
||||
-webkit-box-shadow: none !important;
|
||||
box-shadow: none !important;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
.cnvs-block-jg-add-media-button button.components-button {
|
||||
-webkit-box-pack: center;
|
||||
-ms-flex-pack: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
margin-top: 20px;
|
||||
padding: 20px;
|
||||
-webkit-box-shadow: none !important;
|
||||
box-shadow: none !important;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import "./block.scss";
|
||||
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
const {
|
||||
__,
|
||||
} = wp.i18n;
|
||||
|
||||
const {
|
||||
addFilter,
|
||||
} = wp.hooks;
|
||||
|
||||
const {
|
||||
Button,
|
||||
DropZone,
|
||||
} = wp.components;
|
||||
|
||||
const {
|
||||
MediaPlaceholder,
|
||||
MediaUpload,
|
||||
mediaUpload,
|
||||
} = wp.blockEditor;
|
||||
|
||||
const {
|
||||
createBlock,
|
||||
} = wp.blocks;
|
||||
|
||||
/**
|
||||
* Custom block Edit output for Justified Gallery block.
|
||||
*
|
||||
* @param {JSX} edit Original block edit.
|
||||
* @param {Object} blockProps Block data.
|
||||
*
|
||||
* @return {JSX} Block edit.
|
||||
*/
|
||||
function editRender( edit, blockProps ) {
|
||||
if ( 'canvas/justified-gallery' !== blockProps.name ) {
|
||||
return edit;
|
||||
}
|
||||
|
||||
const {
|
||||
attributes,
|
||||
setAttributes,
|
||||
isSelected,
|
||||
} = blockProps;
|
||||
|
||||
const {
|
||||
images,
|
||||
} = attributes;
|
||||
|
||||
const ALLOWED_MEDIA_TYPES = [ 'image' ];
|
||||
|
||||
const hasImages = images && images.length;
|
||||
|
||||
// show gallery with images.
|
||||
if ( hasImages ) {
|
||||
return (
|
||||
<div>
|
||||
{ edit }
|
||||
<DropZone
|
||||
onFilesDrop={ ( files ) => {
|
||||
const currentImages = images || [];
|
||||
mediaUpload( {
|
||||
allowedTypes: ALLOWED_MEDIA_TYPES,
|
||||
filesList: files,
|
||||
onFileChange: ( images ) => {
|
||||
const result = images.map( ( image ) => {
|
||||
return image.id;
|
||||
} );
|
||||
|
||||
setAttributes( {
|
||||
images: currentImages.concat( result ),
|
||||
} );
|
||||
},
|
||||
onError( e ) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log( e );
|
||||
},
|
||||
} );
|
||||
} }
|
||||
/>
|
||||
{ isSelected ? (
|
||||
<div className="cnvs-block-jg-add-media-button">
|
||||
<MediaUpload
|
||||
onSelect={ ( images ) => {
|
||||
const result = images.map( ( image ) => {
|
||||
return image.id;
|
||||
} );
|
||||
|
||||
setAttributes( {
|
||||
images: result,
|
||||
} );
|
||||
} }
|
||||
allowedTypes={ ALLOWED_MEDIA_TYPES }
|
||||
multiple
|
||||
gallery
|
||||
value={ images }
|
||||
render={ ( { open } ) => (
|
||||
<Button isDefault={ true } onClick={ open }>{ __( 'Edit Gallery' ) }</Button>
|
||||
) }
|
||||
/>
|
||||
</div>
|
||||
) : '' }
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// add media upload if no images selected.
|
||||
return (
|
||||
<div>
|
||||
<MediaPlaceholder
|
||||
icon="format-gallery"
|
||||
labels={ {
|
||||
title: __( 'Gallery' ),
|
||||
instructions: __( 'Drag images, upload new ones or select files from your library.' ),
|
||||
} }
|
||||
onSelect={ ( images ) => {
|
||||
const result = images.map( ( image ) => {
|
||||
return image.id;
|
||||
} );
|
||||
|
||||
setAttributes( {
|
||||
images: result,
|
||||
} );
|
||||
} }
|
||||
accept="image/*"
|
||||
allowedTypes={ ALLOWED_MEDIA_TYPES }
|
||||
multiple
|
||||
value={ undefined }
|
||||
onError={ ( e ) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log( e );
|
||||
} }
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Block transformations.
|
||||
*
|
||||
* @param {Object} blockData Block data.
|
||||
*
|
||||
* @return {Object} Block data.
|
||||
*/
|
||||
function registerData( blockData ) {
|
||||
if ( 'canvas/justified-gallery' === blockData.name ) {
|
||||
blockData.transforms = {
|
||||
from: [
|
||||
{
|
||||
type: 'block',
|
||||
blocks: [ 'canvas/slider-gallery' ],
|
||||
transform: function( attrs ) {
|
||||
return createBlock(
|
||||
'canvas/justified-gallery',
|
||||
{
|
||||
images: attrs.images,
|
||||
imageSize: attrs.imageSize,
|
||||
linkTo: attrs.linkTo,
|
||||
}
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
return blockData;
|
||||
}
|
||||
|
||||
addFilter( 'canvas.customBlock.editRender', 'canvas/justified-gallery/editRender', editRender );
|
||||
addFilter( 'canvas.customBlock.registerData', 'canvas/justified-gallery/registerData', registerData );
|
||||
Vendored
+8
File diff suppressed because one or more lines are too long
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Justified Gallery
|
||||
*/
|
||||
( function( $ ) {
|
||||
|
||||
function canvasInitJustifiedGallery() {
|
||||
|
||||
$( '.cnvs-gallery-type-justified:not(.cnvs-gallery-type-justified-ready)' ).imagesLoaded( function( instance ) {
|
||||
|
||||
$( instance.elements ).each( function( index, el ) {
|
||||
var $el = $( el );
|
||||
var data = $el.data();
|
||||
|
||||
$el.filter(':not(.cnvs-gallery-type-justified-ready)')
|
||||
.addClass( 'cnvs-gallery-type-justified-ready' )
|
||||
.justifiedGallery( {
|
||||
rtl: !!canvasJG.rtl,
|
||||
margins: data.jgMargins,
|
||||
rowHeight: data.jgRowHeight,
|
||||
maxRowHeight: data.jgMaxRowHeight,
|
||||
lastRow: data.jgLastRow,
|
||||
border: 0,
|
||||
border: typeof data.jgBorder !== 'undefined' ? data.jgBorder : 0,
|
||||
selector: 'figure',
|
||||
captions: typeof data.jgCaptions !== 'undefined' ? data.jgCaptions : true,
|
||||
randomize: typeof data.jgRandomize !== 'undefined' ? data.jgRandomize : false,
|
||||
cssAnimation: true,
|
||||
captionSettings: {
|
||||
animationDuration: 100,
|
||||
visibleOpacity: 1.0,
|
||||
nonVisibleOpacity: 0.0
|
||||
}
|
||||
} ).on( 'jg.complete', function( e ) {
|
||||
|
||||
$el.addClass( 'justified-loaded' );
|
||||
|
||||
$( document.body ).trigger( 'image-load' );
|
||||
} );
|
||||
} );
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
$( document ).ready( function() {
|
||||
canvasInitJustifiedGallery();
|
||||
$( document.body ).on( 'post-load', function() {
|
||||
canvasInitJustifiedGallery();
|
||||
} );
|
||||
|
||||
if ( 'undefined' !== typeof wp && 'undefined' !== typeof wp.hooks ) {
|
||||
wp.hooks.addAction( 'canvas.components.serverSideRender.onChange', 'canvas/justified-gallery.init', function( props ) {
|
||||
if ( 'canvas/justified-gallery' === props.block ) {
|
||||
canvasInitJustifiedGallery();
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
} )( jQuery );
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Justified Gallery block template
|
||||
*
|
||||
* @package Canvas
|
||||
*/
|
||||
|
||||
$images = (array) ( isset( $attributes['images'] ) ? $attributes['images'] : array() );
|
||||
|
||||
if ( empty( $images ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="' . esc_attr( $attributes['className'] ) . '" ' . ( isset( $attributes['anchor'] ) ? ' id="' . esc_attr( $attributes['anchor'] ) . '"' : '' ) . '>';
|
||||
|
||||
?>
|
||||
|
||||
<div
|
||||
class='gallery cnvs-gallery-type-justified'
|
||||
data-jg-margins="<?php echo esc_attr( $attributes['margins'] ); ?>"
|
||||
data-jg-border="<?php echo esc_attr( $attributes['border'] ); ?>"
|
||||
data-jg-row-height="<?php echo esc_attr( $attributes['rowHeight'] ); ?>"
|
||||
data-jg-max-row-height="<?php echo esc_attr( $attributes['maxRowHeight'] ); ?>"
|
||||
data-jg-last-row="<?php echo esc_attr( $attributes['lastRow'] ); ?>"
|
||||
data-jg-captions="<?php echo esc_attr( $attributes['showCaptions'] ? 'true' : 'false' ); ?>"
|
||||
data-jg-randomize="<?php echo esc_attr( $attributes['randomize'] ? 'true' : 'false' ); ?>"
|
||||
>
|
||||
<?php
|
||||
foreach ( $images as $img ) {
|
||||
$link = false;
|
||||
|
||||
switch ( $attributes['linkTo'] ) {
|
||||
case 'post':
|
||||
$link = get_the_permalink( $img );
|
||||
break;
|
||||
case 'file':
|
||||
$link = wp_get_attachment_image_src( $img, 'full' )[0];
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
<figure class="gallery-item">
|
||||
<?php if ( $link ) : ?>
|
||||
<a href="<?php echo esc_url( $link ); ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php echo wp_get_attachment_image( $img, $attributes['imageSize'] ); ?>
|
||||
|
||||
<?php if ( $link ) : ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if ( $attributes['showCaptions'] ) {
|
||||
$caption = wp_get_attachment_caption( $img );
|
||||
|
||||
if ( $caption ) {
|
||||
echo '<div class="caption wp-caption-text gallery-caption">' . wp_kses( $caption, 'post' ) . '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</figure>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
echo '</div>';
|
||||
Reference in New Issue
Block a user