| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Interactions; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
class Presets { |
| 10 |
const DEFAULT_DURATION = 300; |
| 11 |
const DEFAULT_DELAY = 0; |
| 12 |
const DEFAULT_SLIDE_DISTANCE = 100; |
| 13 |
const DEFAULT_SCALE_START = 0; |
| 14 |
const DEFAULT_EASING = 'linear'; |
| 15 |
|
| 16 |
const TRIGGERS = [ 'load', 'scrollIn', 'scrollOn' ]; // 'scrollOut' is not supported yet. |
| 17 |
const EFFECTS = [ 'fade', 'slide', 'scale' ]; |
| 18 |
const TYPES = [ 'in', 'out' ]; |
| 19 |
const DIRECTIONS = [ 'left', 'right', 'top', 'bottom' ]; |
| 20 |
const DURATIONS = [ 0, 100, 200, 300, 400, 500, 750, 1000, 1250, 1500 ]; |
| 21 |
const DELAYS = [ 0, 100, 200, 300, 400, 500, 750, 1000, 1250, 1500 ]; |
| 22 |
|
| 23 |
public function list() { |
| 24 |
return $this->generate_animation_options(); |
| 25 |
} |
| 26 |
|
| 27 |
public function defaults() { |
| 28 |
return [ |
| 29 |
'defaultDuration' => self::DEFAULT_DURATION, |
| 30 |
'defaultDelay' => self::DEFAULT_DELAY, |
| 31 |
'slideDistance' => self::DEFAULT_SLIDE_DISTANCE, |
| 32 |
'scaleStart' => self::DEFAULT_SCALE_START, |
| 33 |
'easing' => self::DEFAULT_EASING, |
| 34 |
]; |
| 35 |
} |
| 36 |
|
| 37 |
private function get_label( $key, $value ) { |
| 38 |
$special_labels = [ |
| 39 |
'trigger' => [ |
| 40 |
'load' => __( 'On page load', 'elementor' ), |
| 41 |
'scrollIn' => __( 'Scroll into view', 'elementor' ), |
| 42 |
'scrollOut' => __( 'Scroll out of view', 'elementor' ), |
| 43 |
], |
| 44 |
]; |
| 45 |
|
| 46 |
if ( isset( $special_labels[ $key ][ $value ] ) ) { |
| 47 |
return $special_labels[ $key ][ $value ]; |
| 48 |
} |
| 49 |
|
| 50 |
$label = ucwords( str_replace( '-', ' ', $value ) ); |
| 51 |
|
| 52 |
return esc_html( $label ); |
| 53 |
} |
| 54 |
|
| 55 |
private function generate_animation_options() { |
| 56 |
$options = []; |
| 57 |
|
| 58 |
foreach ( self::TRIGGERS as $trigger ) { |
| 59 |
foreach ( self::EFFECTS as $effect ) { |
| 60 |
foreach ( self::TYPES as $type ) { |
| 61 |
foreach ( self::DIRECTIONS as $direction ) { |
| 62 |
foreach ( self::DURATIONS as $duration ) { |
| 63 |
foreach ( self::DELAYS as $delay ) { |
| 64 |
$value = "{$trigger}-{$effect}-{$type}-{$direction}-{$duration}-{$delay}"; |
| 65 |
$label = sprintf( |
| 66 |
'%s: %s %s', |
| 67 |
$this->get_label( 'trigger', $trigger ), |
| 68 |
$this->get_label( 'effect', $effect ), |
| 69 |
$this->get_label( 'type', $type ), |
| 70 |
); |
| 71 |
$options[] = [ |
| 72 |
'value' => $value, |
| 73 |
'label' => $label, |
| 74 |
]; |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
foreach ( self::DURATIONS as $duration ) { |
| 80 |
foreach ( self::DELAYS as $delay ) { |
| 81 |
$value = "{$trigger}-{$effect}-{$type}--{$duration}-{$delay}"; |
| 82 |
$label = sprintf( |
| 83 |
'%s: %s %s', |
| 84 |
$this->get_label( 'trigger', $trigger ), |
| 85 |
$this->get_label( 'effect', $effect ), |
| 86 |
$this->get_label( 'type', $type ), |
| 87 |
); |
| 88 |
$options[] = [ |
| 89 |
'value' => $value, |
| 90 |
'label' => $label, |
| 91 |
]; |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
return $options; |
| 99 |
} |
| 100 |
} |
| 101 |
|