| @@ -1,0 +1,176 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace King_Addons\Animations; | |
| 4 | + | |
| 5 | +use Elementor\Base_Data_Control; | |
| 6 | + | |
| 7 | +if (!defined('ABSPATH')) { | |
| 8 | + exit; | |
| 9 | +} | |
| 10 | + | |
| 11 | +class Animations extends Base_Data_Control | |
| 12 | +{ | |
| 13 | + private static array $_animations = []; | |
| 14 | + | |
| 15 | + private static array $pro_animations = [ | |
| 16 | + 'Fade' => [ | |
| 17 | + 'fade-in' => 'Fade In', | |
| 18 | + 'fade-out' => 'Fade Out', | |
| 19 | + ], | |
| 20 | + 'Slide' => [ | |
| 21 | + 'pro-sltp' => 'Slide Top (Pro)', | |
| 22 | + 'pro-slrt' => 'Slide Right (Pro)', | |
| 23 | + 'pro-slxrt' => 'Slide X Right (Pro)', | |
| 24 | + 'pro-slbt' => 'Slide Bottom (Pro)', | |
| 25 | + 'pro-sllt' => 'Slide Left (Pro)', | |
| 26 | + 'pro-slxlt' => 'Slide X Left (Pro)', | |
| 27 | + ], | |
| 28 | + 'Skew' => [ | |
| 29 | + 'pro-sktp' => 'Skew Top (Pro)', | |
| 30 | + 'pro-skrt' => 'Skew Right (Pro)', | |
| 31 | + 'pro-skbt' => 'Skew Bottom (Pro)', | |
| 32 | + 'pro-sklt' => 'Skew Left (Pro)', | |
| 33 | + ], | |
| 34 | + 'Scale' => [ | |
| 35 | + 'pro-scup' => 'Scale Up (Pro)', | |
| 36 | + 'pro-scdn' => 'Scale Down (Pro)', | |
| 37 | + ], | |
| 38 | + 'Roll' => [ | |
| 39 | + 'pro-rllt' => 'Roll Left (Pro)', | |
| 40 | + 'pro-rlrt' => 'Roll Right (Pro)', | |
| 41 | + ], | |
| 42 | + ]; | |
| 43 | + | |
| 44 | + private static array $free_animations = [ | |
| 45 | + 'Fade' => [ | |
| 46 | + 'fade-in' => 'Fade In', | |
| 47 | + 'fade-out' => 'Fade Out', | |
| 48 | + ], | |
| 49 | + 'Slide' => [ | |
| 50 | + 'slide-top' => 'Slide Top', | |
| 51 | + 'slide-right' => 'Slide Right', | |
| 52 | + 'slide-x-right' => 'Slide X Right', | |
| 53 | + 'slide-bottom' => 'Slide Bottom', | |
| 54 | + 'slide-left' => 'Slide Left', | |
| 55 | + 'slide-x-left' => 'Slide X Left', | |
| 56 | + ], | |
| 57 | + 'Skew' => [ | |
| 58 | + 'skew-top' => 'Skew Top', | |
| 59 | + 'skew-right' => 'Skew Right', | |
| 60 | + 'skew-bottom' => 'Skew Bottom', | |
| 61 | + 'skew-left' => 'Skew Left', | |
| 62 | + ], | |
| 63 | + 'Scale' => [ | |
| 64 | + 'scale-up' => 'Scale Up', | |
| 65 | + 'scale-down' => 'Scale Down', | |
| 66 | + ], | |
| 67 | + 'Roll' => [ | |
| 68 | + 'roll-left' => 'Roll Left', | |
| 69 | + 'roll-right' => 'Roll Right', | |
| 70 | + ], | |
| 71 | + ]; | |
| 72 | + | |
| 73 | + public function get_type(): string | |
| 74 | + { | |
| 75 | + return 'king-addons-animations'; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public static function get_animations(): array | |
| 79 | + { | |
| 80 | + self::$_animations = king_addons_freemius()->can_use_premium_code__premium_only() | |
| 81 | + ? self::$free_animations | |
| 82 | + : self::$pro_animations; | |
| 83 | + | |
| 84 | + return self::$_animations; | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Returns all valid animation slug values used by grid widgets. | |
| 89 | + * | |
| 90 | + * @return array<int, string> Animation slug list. | |
| 91 | + */ | |
| 92 | + public static function get_animation_slugs(): array | |
| 93 | + { | |
| 94 | + $slugs = ['none']; | |
| 95 | + | |
| 96 | + // Do not array_merge the two maps first: they share group keys (Slide, Skew, …), | |
| 97 | + // so the Pro map would replace the free slugs and drop values such as slide-top. | |
| 98 | + foreach ([self::$free_animations, self::$pro_animations] as $animations) { | |
| 99 | + foreach ($animations as $group) { | |
| 100 | + $slugs = array_merge($slugs, array_keys($group)); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + return array_values(array_unique($slugs)); | |
| 105 | + } | |
| 106 | + | |
| 107 | + public function content_template(): void | |
| 108 | + { | |
| 109 | + $control_uid = $this->get_control_uid(); ?> | |
| 110 | + <div class="elementor-control-field"> | |
| 111 | + <label for="<?php echo esc_attr($control_uid); ?>" class="elementor-control-title"> | |
| 112 | + {{{ data.label }}} | |
| 113 | + </label> | |
| 114 | + <div class="elementor-control-input-wrapper"> | |
| 115 | + <select id="<?php echo esc_attr($control_uid); ?>" data-setting="{{ data.name }}"> | |
| 116 | + <option value="none"><?php echo esc_html__('None', 'king-addons'); ?></option> | |
| 117 | + <?php foreach (self::get_animations() as $group_name => $animations_group) : ?> | |
| 118 | + <optgroup label="<?php echo esc_attr($group_name); ?>"> | |
| 119 | + <?php foreach ($animations_group as $animation_key => $animation_val) : ?> | |
| 120 | + <option value="<?php echo esc_attr($animation_key); ?>"> | |
| 121 | + <?php echo esc_html($animation_val); ?> | |
| 122 | + </option> | |
| 123 | + <?php endforeach; ?> | |
| 124 | + </optgroup> | |
| 125 | + <?php endforeach; ?> | |
| 126 | + </select> | |
| 127 | + </div> | |
| 128 | + </div> | |
| 129 | + <# if ( data.description ) { #> | |
| 130 | + <div class="elementor-control-field-description"> | |
| 131 | + {{{ data.description }}} | |
| 132 | + </div> | |
| 133 | + <# } #> | |
| 134 | + <?php } | |
| 135 | +} | |
| 136 | + | |
| 137 | +class Animations_Alternative extends Animations | |
| 138 | +{ | |
| 139 | + public function get_type(): string | |
| 140 | + { | |
| 141 | + return 'king-addons-animations-alt'; | |
| 142 | + } | |
| 143 | + | |
| 144 | + public function content_template(): void | |
| 145 | + { | |
| 146 | + $animations = self::get_animations(); | |
| 147 | + $control_uid = $this->get_control_uid(); | |
| 148 | + | |
| 149 | + unset($animations['Slide']['slide-x-right'], $animations['Slide']['slide-x-left']); | |
| 150 | + ?> | |
| 151 | + <div class="elementor-control-field"> | |
| 152 | + <label for="<?php echo esc_attr($control_uid); ?>" class="elementor-control-title"> | |
| 153 | + {{{ data.label }}} | |
| 154 | + </label> | |
| 155 | + <div class="elementor-control-input-wrapper"> | |
| 156 | + <select id="<?php echo esc_attr($control_uid); ?>" data-setting="{{ data.name }}"> | |
| 157 | + <option value="none"><?php echo esc_html__('None', 'king-addons'); ?></option> | |
| 158 | + <?php foreach ($animations as $group_name => $animations_group) : ?> | |
| 159 | + <optgroup label="<?php echo esc_attr($group_name); ?>"> | |
| 160 | + <?php foreach ($animations_group as $animation_key => $animation_val) : ?> | |
| 161 | + <option value="<?php echo esc_attr($animation_key); ?>"> | |
| 162 | + <?php echo esc_html($animation_val); ?> | |
| 163 | + </option> | |
| 164 | + <?php endforeach; ?> | |
| 165 | + </optgroup> | |
| 166 | + <?php endforeach; ?> | |
| 167 | + </select> | |
| 168 | + </div> | |
| 169 | + </div> | |
| 170 | + <# if ( data.description ) { #> | |
| 171 | + <div class="elementor-control-field-description"> | |
| 172 | + {{{ data.description }}} | |
| 173 | + </div> | |
| 174 | + <# } #> | |
| 175 | + <?php } | |
| 176 | +} | |