first commit

This commit is contained in:
CHIEFSOFT\ameye
2023-11-30 13:20:54 -05:00
commit e9e5c0546c
5833 changed files with 1801865 additions and 0 deletions
@@ -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);
}
}
@@ -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 );
File diff suppressed because one or more lines are too long
@@ -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>';
@@ -0,0 +1,203 @@
<?php
/**
* Justified Gallery Block.
*
* @package Canvas
*/
/**
* Initialize Posts block.
*/
class CNVS_Block_Justified_Gallery {
/**
* Initialize
*/
public function __construct() {
add_action( 'init', array( $this, 'block' ) );
add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) );
}
/**
* Enqueue the block's assets for the editor.
*/
public function block() {
// Scripts.
wp_register_script( 'justifiedgallery', plugin_dir_url( __FILE__ ) . 'block/jquery.justifiedGallery.min.js', array( 'jquery' ), cnvs_get_setting( 'version' ), true );
wp_register_script( 'canvas-justified-gallery', plugin_dir_url( __FILE__ ) . 'block/public-block-justified-gallery.js', array( 'jquery', 'justifiedgallery' ), cnvs_get_setting( 'version' ), true );
wp_localize_script(
'canvas-justified-gallery', 'canvasJG', array(
'rtl' => is_rtl(),
)
);
wp_register_script(
'canvas-justified-gallery-block-editor-script',
plugins_url( 'block/block.js', __FILE__ ),
array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor', 'lodash', 'jquery', 'justifiedgallery', 'canvas-justified-gallery' ),
filemtime( plugin_dir_path( __FILE__ ) . 'block/block.js' ),
true
);
// Styles.
wp_register_style(
'canvas-justified-gallery-block-style',
plugins_url( 'block/block-justified-gallery.css', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'block/block-justified-gallery.css' )
);
wp_style_add_data( 'canvas-justified-gallery-block-style', 'rtl', 'replace' );
}
/**
* Register block
*
* @param array $blocks all registered blocks.
* @return array
*/
public function register_block_type( $blocks ) {
$intermediate_image_sizes = get_intermediate_image_sizes();
$image_sizes = array();
foreach ( $intermediate_image_sizes as $size ) {
$image_sizes[ $size ] = $size;
}
$blocks[] = array(
'name' => 'canvas/justified-gallery',
'title' => esc_html__( 'Justified Gallery', 'canvas' ),
'category' => 'canvas',
'keywords' => array(),
'icon' => '
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 3H15V10H3V3ZM19 3H21V10H19V3ZM3 14H8V21H3L3 14ZM12 14H21V21H12V14Z" stroke="currentColor" fill="none" stroke-width="2"/>
</svg>
',
'supports' => array(
'className' => true,
'anchor' => true,
'html' => false,
'canvasSpacings' => true,
'canvasBorder' => true,
'canvasResponsive' => true,
),
'styles' => array(),
'location' => array(),
'sections' => array(
'general' => array(
'title' => esc_html__( 'Block Settings', 'canvas' ),
'priority' => 5,
'open' => true,
),
),
'layouts' => array(),
'fields' => array(
array(
'key' => 'images',
'label' => esc_html__( 'Images', 'canvas' ),
'section' => 'general',
'type' => 'gallery',
'items' => array(
'type' => 'integer',
),
),
array(
'key' => 'imageSize',
'label' => esc_html__( 'Images Size', 'canvas' ),
'section' => 'general',
'type' => 'select',
'default' => 'thumbnail',
'choices' => $image_sizes,
),
array(
'key' => 'linkTo',
'label' => esc_html__( 'Link To', 'canvas' ),
'section' => 'general',
'type' => 'select',
'default' => 'file',
'choices' => array(
'post' => esc_html__( 'Attachment Page', 'canvas' ),
'file' => esc_html__( 'Media File', 'canvas' ),
'none' => esc_html__( 'None', 'canvas' ),
),
),
array(
'key' => 'rowHeight',
'label' => esc_html__( 'Row Height', 'canvas' ),
'section' => 'general',
'type' => 'number',
'min' => 50,
'max' => 5000,
'default' => 275,
),
array(
'key' => 'maxRowHeight',
'label' => esc_html__( 'Max Row Height', 'canvas' ),
'help' => esc_html__( 'This option could be a false or negative value to keep it disabled. Could be a number (e.g 200) which specifies the maximum row height in pixel. Alternatively, a string which specifies a percentage (e.g. "200%" means that the row height can\'t exceed 2 * rowHeight).', 'canvas' ),
'section' => 'general',
'type' => 'text',
'default' => '-1',
),
array(
'key' => 'margins',
'label' => esc_html__( 'Margins', 'canvas' ),
'section' => 'general',
'type' => 'number',
'min' => 0,
'max' => 60,
'default' => 10,
),
array(
'key' => 'border',
'label' => esc_html__( 'Border', 'canvas' ),
'section' => 'general',
'type' => 'number',
'min' => -60,
'max' => 60,
'default' => -10,
),
array(
'key' => 'lastRow',
'label' => esc_html__( 'Last Row', 'canvas' ),
'section' => 'general',
'type' => 'select',
'choices' => array(
'nojustify' => esc_html__( 'No Justify', 'canvas' ),
'justify' => esc_html__( 'Justify', 'canvas' ),
'hide' => esc_html__( 'Hide', 'canvas' ),
),
'default' => 'nojustify',
),
array(
'key' => 'showCaptions',
'label' => esc_html__( 'Display Captions', 'canvas' ),
'section' => 'general',
'type' => 'toggle',
'default' => false,
),
array(
'key' => 'randomize',
'label' => esc_html__( 'Randomize', 'canvas' ),
'section' => 'general',
'type' => 'toggle',
'default' => false,
),
),
'template' => dirname( __FILE__ ) . '/block/render.php',
// enqueue registered scripts/styles.
'style' => 'canvas-justified-gallery-block-style',
'script' => is_admin() ? '' : 'canvas-justified-gallery',
'editor_style' => 'canvas-justified-gallery-block-style',
'editor_script' => 'canvas-justified-gallery-block-editor-script',
);
return $blocks;
}
}
new CNVS_Block_Justified_Gallery();