Skip to content

Commit

Permalink
refactored implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
prconcepcion committed Dec 28, 2023
1 parent b0abaa3 commit 6be733a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function __construct() {

// Adds a special class to the body tag, to indicate we can now run animations.
add_action( 'wp_footer', array( $this, 'init_animation' ) );
add_action( 'wp_footer', array( $this, 'init_stackable_vars' ) );

// Add the fallback values for the default block width and wide block width.
// These are used for the inside "Content width" option of Columns.
Expand Down Expand Up @@ -101,9 +102,6 @@ public function register_frontend_assets() {
wp_register_script( 'ugb-block-frontend-js', null, [], STACKABLE_VERSION );
}

$args = apply_filters( 'stackable_localize_frontend_script', array() );
wp_localize_script( 'ugb-block-frontend-js', 'stackable', $args );

// Register inline frontend styles, these are always loaded.
// Register via a dummy style.
wp_register_style( 'ugb-style-css-nodep', false );
Expand Down Expand Up @@ -452,6 +450,13 @@ public function load_plugin_textdomain() {
public function init_animation() {
echo '<script>requestAnimationFrame(() => document.body.classList.add( "stk--anim-init" ))</script>';
}

public function init_stackable_vars() {
$args = apply_filters( 'stackable_localize_frontend_script', array() );
if ( array_key_exists( 'restUrl', $args ) ) {
echo '<script> stackable = {"restUrl": "' . $args["restUrl"] .'"} </script>';
}
}
}

new Stackable_init();
Expand Down

0 comments on commit 6be733a

Please sign in to comment.