PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Models / Common / KenBurns.php

KenBurns.php in Depicter — Popup & Slider Builder trunk, at app/src/Document/Models/Common/KenBurns.php

75 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 use Depicter\Document\Helper\Helper;
8
9 class KenBurns extends States {
10
11 /**
12 * Get all kenburn attributes
13 *
14 * @return array
15 */
16 public function getKenBurnsAttrs(): array{
17 $attrs = [];
18 // Collect animation attributes
19 foreach ( Breakpoints::names() as $breakpoint ){
20 $breakpoint_prefix = $breakpoint ? $breakpoint . '-' : $breakpoint;
21 $breakpoint_prefix = $breakpoint == 'default' ? '' : $breakpoint_prefix;
22
23 if( Helper::isStyleEnabled( $this, $breakpoint ) ){
24 $attrs[ 'data-'. $breakpoint_prefix .'ken-burns' ] = $this->getKenBurnsOption( $breakpoint );
25 } else if ( isset( $this->default->enable ) ) {
26 $attrs[ 'data-'. $breakpoint_prefix .'ken-burns' ] = "false";
27 }
28
29 }
30 return $attrs;
31 }
32
33 /**
34 * Get kenburns option
35 *
36 * @param string $breakpoint
37 * @return string
38 */
39 public function getKenBurnsOption( $breakpoint ): string{
40 $options = [];
41
42 $options['scale'] = $this->{$breakpoint}->params->scale ?? $this->getParentValue( 'scale', $breakpoint, '');
43 $options['duration'] = $this->{$breakpoint}->params->duration ?? $this->getParentValue( 'duration', $breakpoint, '5000');
44 $options['focalPoint']['x'] = $this->{$breakpoint}->params->focalPoint->x ?? $this->getParentValue( 'focalX', $breakpoint, '');
45 $options['focalPoint']['y'] = $this->{$breakpoint}->params->focalPoint->y ?? $this->getParentValue( 'focalY', $breakpoint, '');
46 $options['easing'] = $this->{$breakpoint}->params->easing ?? $this->getParentValue( 'easing', $breakpoint, 'linear');
47
48 return JSON::encode( $options );
49 }
50
51 /**
52 * Get parent device value for a css variable
53 *
54 * @param $variable
55 * @param $device
56 * @param $default
57 *
58 * @return mixed
59 */
60 public function getParentValue( $variable, $device, $default ) {
61 $parentDevice = Breakpoints::getParentDevice( $device );
62 if ( !empty( $parentDevice ) ) {
63 if ( strpos( $variable, 'focal' ) === false ) {
64 return $this->{$parentDevice}->params->{$variable} ?? $this->getParentValue( $variable, $parentDevice, $default );
65 } else {
66 $focalAxis = str_replace( 'focal', '', strtolower( $variable ) );
67 return $this->{$parentDevice}->params->focalPoint->{$focalAxis} ?? $this->getParentValue( $variable, $parentDevice, $default );
68 }
69
70 }
71
72 return $default;
73 }
74 }
75