| 1 |
<?php |
| 2 |
// Exit if accessed directly. |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Returns the content of the block. |
| 9 |
* |
| 10 |
* @param array $attributes Block attributes. |
| 11 |
* |
| 12 |
* @param string $content Block save content. |
| 13 |
*/ |
| 14 |
function ab_render_animated_block( $attributes, $content ) { |
| 15 |
// Frontend JS |
| 16 |
if ( ! is_admin() ) { |
| 17 |
wp_enqueue_script( |
| 18 |
'scroll-class', |
| 19 |
plugins_url( 'dist/assets/js/scrollClass.min.js', __DIR__ ), |
| 20 |
[ 'jquery' ], |
| 21 |
filemtime( AB_PLUGIN_DIR . '/dist/assets/js/scrollClass.min.js' ), |
| 22 |
true |
| 23 |
); |
| 24 |
|
| 25 |
wp_enqueue_script( |
| 26 |
'ab-animated-block', |
| 27 |
plugins_url( 'block/view.js', __DIR__ ), |
| 28 |
[ 'jquery', 'scroll-class' ], |
| 29 |
filemtime( AB_PLUGIN_DIR . '/block/view.js' ), |
| 30 |
true |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
return $content; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Register the block. |
| 39 |
*/ |
| 40 |
function ab_register_animated_block() { |
| 41 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
// Editor JS |
| 46 |
wp_register_script( |
| 47 |
'ab-animated-block-editor', |
| 48 |
plugins_url( 'block/editor.js', __DIR__ ), |
| 49 |
[ 'jquery' ], |
| 50 |
filemtime( AB_PLUGIN_DIR . '/block/editor.js' ), |
| 51 |
true |
| 52 |
); |
| 53 |
|
| 54 |
register_block_type( __DIR__, |
| 55 |
array( |
| 56 |
'render_callback' => 'ab_render_animated_block', |
| 57 |
'editor_script' => 'ab-animated-block-editor' |
| 58 |
) |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
add_action( 'init', 'ab_register_animated_block' ); |
| 63 |
|