Last active
May 16, 2019 12:07
-
-
Save isotrope/4de6c27582c8e9ac384a5b1557974a5d to your computer and use it in GitHub Desktop.
Instantiating ACF Gutenberg block script instances.
This file contains hidden or 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
$( 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