| 1 |
<?php |
| 2 |
|
| 3 |
namespace Getwid\Blocks; |
| 4 |
|
| 5 |
class Section extends AbstractBlock { |
| 6 |
|
| 7 |
public function __construct() { |
| 8 |
|
| 9 |
parent::__construct( 'getwid/section' ); |
| 10 |
|
| 11 |
register_block_type( |
| 12 |
getwid_get_plugin_path( 'assets/blocks/section' ), |
| 13 |
array( |
| 14 |
'render_callback' => array( $this, 'render_callback' ), |
| 15 |
) |
| 16 |
); |
| 17 |
} |
| 18 |
|
| 19 |
public function get_label() { |
| 20 |
return __( 'Section', 'getwid' ); |
| 21 |
} |
| 22 |
|
| 23 |
public function block_frontend_assets( $attributes = array(), $content = '' ) { |
| 24 |
|
| 25 |
if ( is_admin() ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
$has_background_slider = false !== strpos( $content, 'wp-block-getwid-section__background-slider-item' ); |
| 30 |
|
| 31 |
if ( ! empty( $attributes['entranceAnimation'] ) ) { |
| 32 |
wp_enqueue_script( 'wow' ); |
| 33 |
wp_enqueue_style( 'animate' ); |
| 34 |
} |
| 35 |
|
| 36 |
if ( $has_background_slider ) { |
| 37 |
wp_enqueue_script( 'slick' ); |
| 38 |
wp_enqueue_style( 'slick' ); |
| 39 |
wp_enqueue_style( 'slick-theme' ); |
| 40 |
wp_enqueue_script( 'imagesloaded' ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
public function render_callback( $attributes, $content ) { |
| 45 |
|
| 46 |
$this->block_frontend_assets( $attributes, $content ); |
| 47 |
|
| 48 |
return $content; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
getwid()->blocksManager()->addBlock( |
| 53 |
new Section() |
| 54 |
); |
| 55 |
|