| 1 |
<?php |
| 2 |
class BBlocksLottiePlayer extends BBlocks{ |
| 3 |
public function __construct(){ |
| 4 |
add_action( 'init', [$this, 'register'] ); |
| 5 |
} |
| 6 |
|
| 7 |
function register(){ |
| 8 |
$this::registerScripts( 'lottie-player', array( |
| 9 |
'attributes' => $this->attributes(), |
| 10 |
'render_callback' => [$this, 'render'] |
| 11 |
) ); |
| 12 |
} |
| 13 |
|
| 14 |
function attributes(){ |
| 15 |
return array( |
| 16 |
'align' => array( 'type' => 'string', 'default' => '' ), |
| 17 |
'cId' => array( 'type' => 'string', 'default' => '' ), |
| 18 |
|
| 19 |
'playerAlign' => array( 'type' => 'string', 'default' => 'center' ), |
| 20 |
|
| 21 |
'file' => array( 'type' => 'string', 'default' => 'https://assets4.lottiefiles.com/datafiles/zc3XRzudyWE36ZBJr7PIkkqq0PFIrIBgp4ojqShI/newAnimation.json' ), |
| 22 |
'isControls' => array( 'type' => 'boolean', 'default' => true ), |
| 23 |
'isAutoplay' => array( 'type' => 'boolean', 'default' => true ), |
| 24 |
'isLoop' => array( 'type' => 'boolean', 'default' => true ), |
| 25 |
'isHover' => array( 'type' => 'boolean', 'default' => false ), |
| 26 |
'mode' => array( 'type' => 'string', 'default' => 'normal' ), |
| 27 |
'count' => array( 'type' => 'number', 'default' => 0 ), |
| 28 |
'speed' => array( 'type' => 'number', 'default' => 1 ), |
| 29 |
'intermission' => array( 'type' => 'number', 'default' => 0 ), |
| 30 |
|
| 31 |
'width' => array( 'type' => 'string', 'default' => '450px' ), |
| 32 |
'background' => array( 'type' => 'string', 'default' => '#0000' ), |
| 33 |
|
| 34 |
'controlsHeight' => array( 'type' => 'string', 'default' => '35px' ), |
| 35 |
'controlsBG' => array( 'type' => 'string', 'default' => '#0000' ), |
| 36 |
'controlsIconColor' => array( 'type' => 'string', 'default' => '#4527a4' ), |
| 37 |
'controlsIconHoverColor' => array( 'type' => 'string', 'default' => '#8344c5' ), |
| 38 |
'controlsIconActiveColor' => array( 'type' => 'string', 'default' => '#8344c5' ), |
| 39 |
'controlsTrackColor' => array( 'type' => 'string', 'default' => '#8344c5' ), |
| 40 |
'controlsThumbColor' => array( 'type' => 'string', 'default' => '#4527a4' ) |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
function render( $attributes ){ |
| 45 |
extract( $attributes ); |
| 46 |
|
| 47 |
// Generate Styles |
| 48 |
$lottiePlayerStyle = new BBlocksStyleGenerator(); |
| 49 |
$lottiePlayerStyle::addStyle( "#bBlocksLottiePlayer-$cId .bBlocksLottiePlayer", array( |
| 50 |
'text-align' => $playerAlign |
| 51 |
) ); |
| 52 |
$lottiePlayerStyle::addStyle( "#bBlocksLottiePlayer-$cId .bBlocksLottiePlayer lottie-player", array( |
| 53 |
'width' => $width, |
| 54 |
'--lottie-player-toolbar-height' => $controlsHeight, |
| 55 |
'--lottie-player-toolbar-background-color' => $controlsBG, |
| 56 |
'--lottie-player-toolbar-icon-color' => $controlsIconColor, |
| 57 |
'--lottie-player-toolbar-icon-hover-color' => $controlsIconHoverColor, |
| 58 |
'--lottie-player-toolbar-icon-active-color' => $controlsIconActiveColor, |
| 59 |
'--lottie-player-seeker-track-color' => $controlsTrackColor, |
| 60 |
'--lottie-player-seeker-thumb-color' => $controlsThumbColor |
| 61 |
) ); |
| 62 |
|
| 63 |
$jsonData = json_encode( array( 'isControls' => $isControls, 'isAutoplay' => $isAutoplay, 'isLoop' => $isLoop, 'isHover' => $isHover ) ); |
| 64 |
|
| 65 |
ob_start(); ?> |
| 66 |
<div class='wp-block-b-blocks-lottie-player <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksLottiePlayer-<?php echo esc_attr( $cId ); ?>' data-controls='<?php echo esc_attr( $jsonData ); ?>'> |
| 67 |
<style><?php echo wp_kses( $lottiePlayerStyle::renderStyle(), array() ); ?></style> |
| 68 |
|
| 69 |
<div class='bBlocksLottiePlayer'> |
| 70 |
<lottie-player |
| 71 |
controls |
| 72 |
autoplay |
| 73 |
loop |
| 74 |
mode='<?php echo esc_attr( $mode ); ?>' |
| 75 |
background='<?php echo esc_attr( $background ); ?>' |
| 76 |
count='<?php echo esc_attr( $count ); ?>' |
| 77 |
speed='<?php echo esc_attr( $speed ); ?>' |
| 78 |
direction='1' |
| 79 |
intermission='<?php echo esc_attr( $intermission * 1000 ); ?>' |
| 80 |
src='<?php echo esc_attr( $file ); ?>' |
| 81 |
> |
| 82 |
</lottie-player> |
| 83 |
</div> |
| 84 |
</div> |
| 85 |
<?php $lottiePlayerStyle::$styles = array(); // Empty styles |
| 86 |
return ob_get_clean(); |
| 87 |
} |
| 88 |
} |
| 89 |
new BBlocksLottiePlayer(); |