| @@ -6,44 +6,25 @@ | ||
| 6 | 6 | exit; // Exit if accessed directly. |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | class Presets { |
| 10 | - const DEFAULT_DURATION = 600; | |
| 10 | + const DEFAULT_DURATION = 300; | |
| 11 | 11 | const DEFAULT_DELAY = 0; |
| 12 | 12 | const DEFAULT_SLIDE_DISTANCE = 100; |
| 13 | 13 | const DEFAULT_SCALE_START = 0; |
| 14 | - const DEFAULT_RELATIVE_TO = 'viewport'; | |
| 15 | - const DEFAULT_END = 15; | |
| 16 | - const DEFAULT_START = 85; | |
| 14 | + const DEFAULT_EASING = 'linear'; | |
| 17 | 15 | |
| 18 | - const BASE_TRIGGERS = [ 'load', 'scrollIn' ]; | |
| 19 | - const ADDITIONAL_TRIGGERS = [ 'scrollOut', 'scrollOn', 'hover', 'click' ]; | |
| 20 | - | |
| 21 | - const DEFAULT_EASING = 'easeIn'; | |
| 22 | - const BASE_EFFECTS = [ 'fade', 'slide', 'scale' ]; | |
| 23 | - const ADDITIONAL_EFFECTS = [ 'custom' ]; | |
| 24 | - | |
| 16 | + const TRIGGERS = [ 'load', 'scrollIn' ]; // 'scrollOut' is not supported yet. | |
| 17 | + const EFFECTS = [ 'fade', 'slide', 'scale' ]; | |
| 25 | 18 | const TYPES = [ 'in', 'out' ]; |
| 26 | - const DIRECTIONS = [ 'left', 'right', 'top', 'bottom', 'top-left', 'top-right', 'bottom-left', 'bottom-right', '' ]; | |
| 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 ]; | |
| 27 | 22 | |
| 28 | - const BASE_EASING = [ 'easeIn' ]; | |
| 29 | - const ADDITIONAL_EASING = [ 'easeOut', 'easeInOut', 'backIn', 'backInOut', 'backOut', 'linear' ]; | |
| 30 | - | |
| 31 | - const DEFAULT_REPEAT = ''; | |
| 32 | - const REPEAT_OPTIONS = [ 'loop', 'times', '' ]; | |
| 33 | - | |
| 34 | - public static function easing_options() { | |
| 35 | - return array_merge( self::BASE_EASING, self::ADDITIONAL_EASING ); | |
| 23 | + public function list() { | |
| 24 | + return $this->generate_animation_options(); | |
| 36 | 25 | } |
| 37 | 26 | |
| 38 | - public static function effects_options() { | |
| 39 | - return array_merge( self::BASE_EFFECTS, self::ADDITIONAL_EFFECTS ); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public static function triggers_options() { | |
| 43 | - return array_merge( self::BASE_TRIGGERS, self::ADDITIONAL_TRIGGERS ); | |
| 44 | - } | |
| 45 | - | |
| 46 | 27 | public function defaults() { |
| 47 | 28 | return [ |
| 48 | 29 | 'defaultDuration' => self::DEFAULT_DURATION, |
| 49 | 30 | 'defaultDelay' => self::DEFAULT_DELAY, |
| @@ -48,12 +29,72 @@ | ||
| 48 | 29 | 'defaultDuration' => self::DEFAULT_DURATION, |
| 49 | 30 | 'defaultDelay' => self::DEFAULT_DELAY, |
| 50 | 31 | 'slideDistance' => self::DEFAULT_SLIDE_DISTANCE, |
| 51 | 32 | 'scaleStart' => self::DEFAULT_SCALE_START, |
| 52 | - 'defaultEasing' => self::DEFAULT_EASING, | |
| 53 | - 'relativeTo' => self::DEFAULT_RELATIVE_TO, | |
| 54 | - 'repeat' => self::DEFAULT_REPEAT, | |
| 55 | - 'start' => self::DEFAULT_START, | |
| 56 | - 'end' => self::DEFAULT_END, | |
| 33 | + 'easing' => self::DEFAULT_EASING, | |
| 57 | 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; | |
| 58 | 99 | } |
| 59 | 100 | } |