Skip to content

Commit

Permalink
Fix advanced gallery component frontend scripts enqueuing
Browse files Browse the repository at this point in the history
  • Loading branch information
razwan committed Oct 6, 2020
1 parent cb39607 commit 2beba68
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 66 deletions.
8 changes: 8 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ function novablocks_register_block_types() {
$dependencies[] = 'google-maps';
}

$advanced_gallery_dependent_scripts = array(
'novablocks/media-frontend'
);

if ( in_array( $handle, $advanced_gallery_dependent_scripts ) ) {
$dependencies[] = 'novablocks/advanced-gallery-frontend';
}

// actually register the script
wp_register_script(
$handle,
Expand Down
65 changes: 65 additions & 0 deletions packages/block-library/src/blocks/advanced-gallery/frontend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { AdvancedGallery } from "@novablocks/components";

const { GridItemCollection } = AdvancedGallery;
const { getGalleryStyle, getGridStyle, safariHeightFix } = AdvancedGallery.utils;

(function($, window, undefined) {

$( '.novablocks-advanced-gallery' ).each( ( i, gallery ) => {

let $gallery = $( gallery ),
$grid = $gallery.find( '.novablocks-advanced-gallery__grid' ),
images = $gallery.find( '.novablocks-advanced-gallery__image' ).toArray();

const attributes = {
imageResizing: $gallery.data( 'imageresizing' ),
containerHeight: $gallery.data( 'containerheight' ),
positionShift: $gallery.data( 'positionshift' ),
sizeContrast: $gallery.data( 'sizecontrast' ),
imageRotation: $gallery.data( 'imagerotation' ),
placementVariation: $gallery.data( 'placementvariation' ),
elementsDistance: $gallery.data( 'elementsdistance' ),
verticalSpacing: $gallery.data( 'verticalspacing' ),
objectPosition: $gallery.data( 'objectposition' ),
};

const gridItemsCollection = new GridItemCollection( images, attributes );

gridItemsCollection.gridItems.map( ( gridItem, index ) => {
let $image = $( gridItem.image ),
$item = $image.closest( '.novablocks-advanced-gallery__grid-item' );

$item.css( gridItem.getStyle() );
$image.css( gridItem.getImageStyle() );
} );

const galleryStyle = getGalleryStyle( attributes );

for ( let propertyName in galleryStyle ) {
$gallery.css( galleryStyle );

if ( propertyName.indexOf( '--' ) === 0 ) {
gallery.style.setProperty( propertyName, galleryStyle[ propertyName ] );
}
}

if ( $grid.length ) {

const gridStyle = getGridStyle( attributes );

$grid.css( gridStyle );

for ( let propertyName in gridStyle ) {
if ( propertyName.indexOf( '--' ) === 0 ) {
$grid.get( 0 ).style.setProperty( propertyName, gridStyle[propertyName] );
}
}
}

} );

$( '.novablocks-advanced-gallery__grid' ).each( function( i, obj ) {
safariHeightFix( obj );
} );

})(jQuery, window);
57 changes: 0 additions & 57 deletions packages/block-library/src/blocks/media/frontend.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,3 @@
import { AdvancedGallery } from "@novablocks/components";

const { GridItemCollection } = AdvancedGallery;
const { getGalleryStyle, getGridStyle } = AdvancedGallery.utils;

(function($, window, undefined) {

$( '.novablocks-advanced-gallery' ).each( ( i, gallery ) => {

let $gallery = $( gallery ),
$grid = $gallery.find( '.novablocks-advanced-gallery__grid' ),
images = $gallery.find( '.novablocks-advanced-gallery__image' ).toArray();

const attributes = {
imageResizing: $gallery.data( 'imageresizing' ),
containerHeight: $gallery.data( 'containerheight' ),
positionShift: $gallery.data( 'positionshift' ),
sizeContrast: $gallery.data( 'sizecontrast' ),
imageRotation: $gallery.data( 'imagerotation' ),
placementVariation: $gallery.data( 'placementvariation' ),
elementsDistance: $gallery.data( 'elementsdistance' ),
verticalSpacing: $gallery.data( 'verticalspacing' ),
objectPosition: $gallery.data( 'objectposition' ),
};

const gridItemsCollection = new GridItemCollection( images, attributes );

gridItemsCollection.gridItems.map( ( gridItem, index ) => {
let $image = $( gridItem.image ),
$item = $image.closest( '.novablocks-advanced-gallery__grid-item' );

$item.css( gridItem.getStyle() );
$image.css( gridItem.getImageStyle() );
} );

const galleryStyle = getGalleryStyle( attributes );

for ( let propertyName in galleryStyle ) {
$gallery.css( galleryStyle );

if ( propertyName.indexOf( '--' ) === 0 ) {
gallery.style.setProperty( propertyName, galleryStyle[ propertyName ] );
}
}

if ( $grid.length ) {

const gridStyle = getGridStyle( attributes );

$grid.css( gridStyle );

for ( let propertyName in gridStyle ) {
if ( propertyName.indexOf( '--' ) === 0 ) {
$grid.get( 0 ).style.setProperty( propertyName, gridStyle[propertyName] );
}
}
}
} );

})(jQuery, window);
9 changes: 0 additions & 9 deletions packages/components/src/advanced-gallery/frontend.js

This file was deleted.

0 comments on commit 2beba68

Please sign in to comment.