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 / Animation.php

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

113 lines 2.3 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
5 use Averta\WordPress\Utility\JSON;
6 use Depicter\Document\CSS\Breakpoints;
7
8 class Animation
9 {
10 /**
11 * Animation in phase
12 *
13 * @var object
14 */
15 public $in;
16
17 /**
18 * Animation out phase
19 *
20 * @var object
21 */
22 public $out;
23
24 /**
25 * Animation loop phase
26 *
27 * @var object
28 */
29 public $loop;
30
31 /**
32 * @var bool|null
33 */
34 public $waitForAction;
35
36 /**
37 * Known phases
38 *
39 * @var array
40 */
41 protected $phases = ['in', 'out', 'loop'];
42
43
44 /**
45 * @param string $phase
46 * @param string $breakpoint
47 *
48 * @return false|string
49 */
50 public function getAnimation( $phase, $breakpoint ) {
51
52 if( empty( $this->{$phase}->data->{$breakpoint}->type ) || ! isset( $this->{$phase}->data->{$breakpoint}->params ) ){
53 return false;
54 }
55
56 $params = $this->{$phase}->data->{$breakpoint}->params;
57
58 if ( \Depicter::auth()->isPaid() ) {
59 $params->type = $this->{$phase}->data->{$breakpoint}->type ?? 'move';
60 } else {
61 $params->type = 'move';
62 }
63
64 return JSON::encode( $params );
65 }
66
67 private function getWaitForAnimationAttr( $phase, $breakpoint ) {
68
69 }
70
71 /**
72 * Get all animation attributes
73 *
74 * @return array
75 */
76 public function getAnimationAttrs() {
77 $attrs = [];
78
79 // Collect animation attributes
80 foreach ( Breakpoints::names() as $breakpoint ){
81 foreach ( $this->phases as $phase ){
82 $breakpoint_prefix = $breakpoint ? $breakpoint . '-' : $breakpoint;
83 $breakpoint_prefix = $breakpoint == 'default' ? '' : $breakpoint_prefix;
84 if( $animation_value = $this->getAnimation( $phase, $breakpoint ) ){
85 $attrs[ 'data-'. $breakpoint_prefix .'animation-' . $phase ] = $this->getAnimation( $phase, $breakpoint );
86 }
87
88 if ( $phase == 'loop' ) {
89 $attrs['data-between-in-out'] = !empty( $this->{$phase}->betweenInAndOut ) ? "true" : "false";
90 }
91 }
92 }
93
94 // Get animation interactive attributes
95 if( ! is_null( $this->waitForAction ) ){
96 $attrs[ "data-wait-for-action" ] = $this->waitForAction ? "true" : "false";
97 }
98
99 if( isset( $this->out->wait ) ){
100 $attrs[ "data-animation-out-wait" ] = $this->out->wait ? "true" : "false";
101 }
102
103 // Get animation interactive attributes
104 foreach ( $this->phases as $phase ){
105 if( isset( $this->{$phase}->interactive ) ){
106 $attrs[ "data-animation-{$phase}-interactive" ] = $this->{$phase}->interactive ? "true" : "false";
107 }
108 }
109
110 return $attrs;
111 }
112 }
113