Skip to content

Instantly share code, notes, and snippets.

@isotrope
Last active May 16, 2019 12:07
Show Gist options
  • Save isotrope/4de6c27582c8e9ac384a5b1557974a5d to your computer and use it in GitHub Desktop.
Save isotrope/4de6c27582c8e9ac384a5b1557974a5d to your computer and use it in GitHub Desktop.
Instantiating ACF Gutenberg block script instances.
$( function () {
// back-end instantiating
if ( window.acf ) {
// https://www.advancedcustomfields.com/resources/javascript-api/#functions-addaction
window.acf.addAction( 'render_block_preview/type=full-width-slider', function ( field ) {
const $sliderContainers = $( field ).find( '.block.full-width-slider' );
if ( $sliderContainers.length > 0 ) {
$sliderContainers.each( ( i, el ) => {
const blockFullWidthSlider = new BlockFullWidthSlider( $( el ) );
} );
}
} );
} else {
// Normal front-end version
const $sliderContainers = $( '.block.full-width-slider' );
if ( $sliderContainers.length > 0 ) {
$sliderContainers.each( ( i, el ) => {
const blockFullWidthSlider = new BlockFullWidthSlider( $( el ) );
} );
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment