| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Common; |
| 3 |
|
| 4 |
use Averta\Core\Utility\Data; |
| 5 |
use Averta\WordPress\Utility\JSON; |
| 6 |
use Depicter\Document\CSS\Breakpoints; |
| 7 |
|
| 8 |
class KenBurns extends States { |
| 9 |
|
| 10 |
/** |
| 11 |
* Get all kenburn attributes |
| 12 |
* |
| 13 |
* @return array |
| 14 |
*/ |
| 15 |
public function getKenBurnsAttrs(): array{ |
| 16 |
$attrs = []; |
| 17 |
// Collect animation attributes |
| 18 |
foreach ( Breakpoints::names() as $breakpoint ){ |
| 19 |
$breakpoint_prefix = $breakpoint ? $breakpoint . '-' : $breakpoint; |
| 20 |
$breakpoint_prefix = $breakpoint == 'default' ? '' : $breakpoint_prefix; |
| 21 |
|
| 22 |
if( isset( $this->{$breakpoint}->enable ) ){ |
| 23 |
$attrs[ 'data-'. $breakpoint_prefix .'ken-burns' ] = !empty($this->{$breakpoint}->enable) ? $this->getKenBurnsOption( $this->{$breakpoint} ) : 'false'; |
| 24 |
} else if ( isset( $this->default->enable ) ) { |
| 25 |
$attrs[ 'data-'. $breakpoint_prefix .'ken-burns' ] = "false"; |
| 26 |
} |
| 27 |
|
| 28 |
} |
| 29 |
return $attrs; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get kenburns option |
| 34 |
* |
| 35 |
* @param object $kenBurnsOptions |
| 36 |
* @return string |
| 37 |
*/ |
| 38 |
public function getKenBurnsOption( $kenBurnsOptions ): string{ |
| 39 |
$options = []; |
| 40 |
|
| 41 |
isset( $kenBurnsOptions->params->scale ) && $options['scale'] = $kenBurnsOptions->params->scale; |
| 42 |
isset( $kenBurnsOptions->params->duration ) && $options['duration'] = $kenBurnsOptions->params->duration; |
| 43 |
isset( $kenBurnsOptions->params->focalPoint ) && $options['focalPoint']['x'] = $kenBurnsOptions->params->focalPoint->x; |
| 44 |
isset( $kenBurnsOptions->params->focalPoint ) && $options['focalPoint']['y'] = $kenBurnsOptions->params->focalPoint->y; |
| 45 |
isset( $kenBurnsOptions->params->easing ) && $options['easing'] = $kenBurnsOptions->params->easing; |
| 46 |
|
| 47 |
return JSON::encode( $options ); |
| 48 |
} |
| 49 |
} |
| 50 |
|