| 1 |
<?php |
| 2 |
// Exit if accessed directly. |
| 3 |
if (! defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Elementor Darkify widget. |
| 9 |
* |
| 10 |
* This class handles the creation of a custom Elementor widget |
| 11 |
* for displaying Switcher in the Darkify Pro plugin. |
| 12 |
* |
| 13 |
* @since 1.0 |
| 14 |
*/ |
| 15 |
class Elementor_Darkify extends \Elementor\Widget_Base |
| 16 |
{ |
| 17 |
|
| 18 |
/** |
| 19 |
* Get widget name. |
| 20 |
* |
| 21 |
* Returns the widget name for use in Elementor. |
| 22 |
* |
| 23 |
* @since 1.0 |
| 24 |
* @return string Widget name. |
| 25 |
*/ |
| 26 |
public function get_name() |
| 27 |
{ |
| 28 |
return 'darkify'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Get widget title. |
| 33 |
* |
| 34 |
* Returns the display title of the widget in Elementor. |
| 35 |
* |
| 36 |
* @since 1.0 |
| 37 |
* @return string Widget title. |
| 38 |
*/ |
| 39 |
public function get_title() |
| 40 |
{ |
| 41 |
return esc_html__('Dark Mode Switcher', 'darkify'); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get widget icon. |
| 46 |
* |
| 47 |
* Returns the icon for the widget that will appear in the Elementor editor. |
| 48 |
* |
| 49 |
* @since 1.0 |
| 50 |
* @return string Widget icon class. |
| 51 |
*/ |
| 52 |
public function get_icon() |
| 53 |
{ |
| 54 |
return 'eicon-adjust'; |
| 55 |
} |
| 56 |
|
| 57 |
public function get_style_depends() |
| 58 |
{ |
| 59 |
return ['theme-classic', 'theme-expand', 'theme-inner-moon', 'theme-within', 'theme-orbit']; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Get widget categories. |
| 64 |
* |
| 65 |
* Defines the category or categories the widget belongs to in Elementor. |
| 66 |
* |
| 67 |
* @since 1.0 |
| 68 |
* @return array Widget categories. |
| 69 |
*/ |
| 70 |
public function get_categories() |
| 71 |
{ |
| 72 |
return ['basic']; |
| 73 |
} |
| 74 |
|
| 75 |
protected function _register_controls() |
| 76 |
{ |
| 77 |
// ---------------------------------------- Darkify Settings ------------------------------ |
| 78 |
$this->start_controls_section( |
| 79 |
'darkify__settings', |
| 80 |
array( |
| 81 |
'label' => esc_html__('Darkify', 'darkify'), |
| 82 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 83 |
) |
| 84 |
); |
| 85 |
// Switch style. |
| 86 |
$this->add_control( |
| 87 |
'darkify_switch_heading', |
| 88 |
[ |
| 89 |
'label' => __('Switch Style', 'darkify'), |
| 90 |
'type' => \Elementor\Controls_Manager::HEADING, |
| 91 |
] |
| 92 |
); |
| 93 |
$this->add_control( |
| 94 |
'style', |
| 95 |
[ |
| 96 |
'type' => 'darkify_switch', |
| 97 |
'options' => array_merge(['classic', 'expand', 'inner-moon', 'within', 'orbit', 'around', 'dark-side', 'horizon', 'eclipse', 'lightbulb', 'dark-inner', 'half-sun', 'simple', 'duality', 'dual', 'shift']), |
| 98 |
'description' => __('Select the Dark Mode Switch Style', 'darkify'), |
| 99 |
'default' => 1, |
| 100 |
'id' => 'darkify-switch', |
| 101 |
'classes' => 'darkify-switch-style-elementor', |
| 102 |
'assets_url' => DARKIFY_DIR_URL . 'src/Admin/assets/images/', |
| 103 |
] |
| 104 |
); |
| 105 |
$this->add_control( |
| 106 |
'size', |
| 107 |
[ |
| 108 |
'label' => __('Switch Size', 'darkify'), |
| 109 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 110 |
'options' => [ |
| 111 |
'0.6' => __('XS', 'darkify'), |
| 112 |
'0.8' => __('S', 'darkify'), |
| 113 |
'1.0' => __('M', 'darkify'), |
| 114 |
'1.2' => __('L', 'darkify'), |
| 115 |
'1.4' => __('XL', 'darkify'), |
| 116 |
'1.6' => __('XXL', 'darkify'), |
| 117 |
'custom' => __('Custom', 'darkify'), |
| 118 |
], |
| 119 |
'default' => '1.0', |
| 120 |
] |
| 121 |
); |
| 122 |
$this->add_control( |
| 123 |
'custom_size', |
| 124 |
[ |
| 125 |
'label' => __('Custom Switch Size', 'darkify'), |
| 126 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 127 |
'min' => 40, |
| 128 |
'max' => 5000, |
| 129 |
'step' => 10, |
| 130 |
'default' => 100, |
| 131 |
'condition' => array( |
| 132 |
'size' => 'custom', |
| 133 |
), |
| 134 |
] |
| 135 |
); |
| 136 |
// ---------------------- |
| 137 |
// 1. SWITCH BACKGROUND |
| 138 |
// ---------------------- |
| 139 |
$this->add_control( |
| 140 |
'switch_bg_heading', |
| 141 |
[ |
| 142 |
'label' => __('Switch Background', 'darkify'), |
| 143 |
'type' => \Elementor\Controls_Manager::HEADING, |
| 144 |
] |
| 145 |
); |
| 146 |
$this->add_control( |
| 147 |
'switch_bg_light', |
| 148 |
[ |
| 149 |
'label' => __('Light Mode', 'darkify'), |
| 150 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 151 |
'default' => '#121116', |
| 152 |
'selectors' => [ |
| 153 |
'{{WRAPPER}} .darkify_switch_style, {{WRAPPER}} .switch-shift .theme-toggle .toggle-thumb' => 'background-color: {{VALUE}};', |
| 154 |
] |
| 155 |
] |
| 156 |
); |
| 157 |
$this->add_control( |
| 158 |
'switch_bg_dark', |
| 159 |
[ |
| 160 |
'label' => __('Dark Mode', 'darkify'), |
| 161 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 162 |
'default' => '#ffffff', |
| 163 |
'selectors' => [ |
| 164 |
'.darkify_dark_mode_enabled {{WRAPPER}} .darkify_switch_style, .darkify_dark_mode_enabled {{WRAPPER}} .switch-shift .theme-toggle .toggle-thumb' => 'background-color: {{VALUE}};', |
| 165 |
], |
| 166 |
] |
| 167 |
); |
| 168 |
// ---------------------- |
| 169 |
// 2. SWITCH ICON COLOR |
| 170 |
// ---------------------- |
| 171 |
$this->add_control( |
| 172 |
'switch_icon_heading', |
| 173 |
[ |
| 174 |
'label' => __('Switch Icon Color', 'darkify'), |
| 175 |
'type' => \Elementor\Controls_Manager::HEADING, |
| 176 |
'condition' => array( |
| 177 |
'style!' => ['duality', 'shift'], |
| 178 |
), |
| 179 |
] |
| 180 |
); |
| 181 |
$this->add_control( |
| 182 |
'switch_icon_light', |
| 183 |
[ |
| 184 |
'label' => __('Light Mode', 'darkify'), |
| 185 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 186 |
'default' => '#ffffff', |
| 187 |
'condition' => array( |
| 188 |
'style!' => ['duality', 'shift', 'dual'], |
| 189 |
), |
| 190 |
'selectors' => [ |
| 191 |
'{{WRAPPER}} .darkify_switch_style svg' => 'color: {{VALUE}}; stroke: {{VALUE}};', |
| 192 |
'{{WRAPPER}} .darkify_switch_style.switch-orbit .theme-toggle svg' => 'fill: {{VALUE}};', |
| 193 |
], |
| 194 |
] |
| 195 |
); |
| 196 |
$this->add_control( |
| 197 |
'switch_icon_dark', |
| 198 |
[ |
| 199 |
'label' => __('Dark Mode', 'darkify'), |
| 200 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 201 |
'default' => '#121116', |
| 202 |
'condition' => array( |
| 203 |
'style!' => ['duality', 'shift', 'dual'], |
| 204 |
), |
| 205 |
'selectors' => [ |
| 206 |
'.darkify_dark_mode_enabled {{WRAPPER}} .darkify_switch_style svg' => 'color: {{VALUE}}; stroke: {{VALUE}};', |
| 207 |
'{{WRAPPER}} .darkify_switch_style.switch-orbit .theme-toggle .toggle-sun svg' => 'fill: {{VALUE}};', |
| 208 |
], |
| 209 |
] |
| 210 |
); |
| 211 |
// ---------------------- |
| 212 |
// 4. SWITCH BORDER |
| 213 |
// ---------------------- |
| 214 |
$this->add_control( |
| 215 |
'switch_border_heading', |
| 216 |
[ |
| 217 |
'label' => __('Switch Border', 'darkify'), |
| 218 |
'type' => \Elementor\Controls_Manager::HEADING, |
| 219 |
] |
| 220 |
); |
| 221 |
// Border Width |
| 222 |
$this->add_control( |
| 223 |
'switch_border_width', |
| 224 |
[ |
| 225 |
'label' => __('Width', 'darkify'), |
| 226 |
'type' => \Elementor\Controls_Manager::SLIDER, |
| 227 |
'size_units' => ['px'], |
| 228 |
'range' => [ |
| 229 |
'px' => [ |
| 230 |
'min' => 0, |
| 231 |
'max' => 10, |
| 232 |
], |
| 233 |
], |
| 234 |
'default' => [ |
| 235 |
'size' => 0, |
| 236 |
], |
| 237 |
'selectors' => [ |
| 238 |
'{{WRAPPER}} .darkify_switch_style' => 'border-width: {{SIZE}}{{UNIT}};', |
| 239 |
], |
| 240 |
] |
| 241 |
); |
| 242 |
$this->add_control( |
| 243 |
'switch_border_light', |
| 244 |
[ |
| 245 |
'label' => __('Light Color', 'darkify'), |
| 246 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 247 |
'default' => '#121116', |
| 248 |
'selectors' => [ |
| 249 |
'{{WRAPPER}} .darkify_switch_style' => 'border-color: {{VALUE}};', |
| 250 |
], |
| 251 |
] |
| 252 |
); |
| 253 |
$this->add_control( |
| 254 |
'switch_border_dark', |
| 255 |
[ |
| 256 |
'label' => __('Dark Color', 'darkify'), |
| 257 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 258 |
'default' => '#ffffff', |
| 259 |
'selectors' => [ |
| 260 |
'.darkify_dark_mode_enabled {{WRAPPER}} .darkify_switch_style' => 'border-color: {{VALUE}};', |
| 261 |
], |
| 262 |
] |
| 263 |
); |
| 264 |
// Border Radius |
| 265 |
$this->add_control( |
| 266 |
'switch_border_radius', |
| 267 |
[ |
| 268 |
'label' => __('Radius', 'darkify'), |
| 269 |
'type' => \Elementor\Controls_Manager::SLIDER, |
| 270 |
'size_units' => ['px'], |
| 271 |
'range' => [ |
| 272 |
'px' => [ |
| 273 |
'min' => 0, |
| 274 |
'max' => 100, |
| 275 |
], |
| 276 |
], |
| 277 |
'default' => [ |
| 278 |
'size' => 7, |
| 279 |
], |
| 280 |
'selectors' => [ |
| 281 |
'{{WRAPPER}} .darkify_switch_style' => 'border-radius: {{SIZE}}{{UNIT}};', |
| 282 |
], |
| 283 |
] |
| 284 |
); |
| 285 |
$this->add_responsive_control( |
| 286 |
'align', |
| 287 |
[ |
| 288 |
'label' => __('Alignment', 'darkify'), |
| 289 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 290 |
'options' => [ |
| 291 |
'left' => [ |
| 292 |
'title' => __('Left', 'darkify'), |
| 293 |
'icon' => 'dashicons dashicons-editor-alignleft', |
| 294 |
], |
| 295 |
'center' => [ |
| 296 |
'title' => __('Center', 'darkify'), |
| 297 |
'icon' => 'dashicons dashicons-editor-aligncenter', |
| 298 |
], |
| 299 |
'right' => [ |
| 300 |
'title' => __('Right', 'darkify'), |
| 301 |
'icon' => 'dashicons dashicons-editor-alignright', |
| 302 |
], |
| 303 |
], |
| 304 |
'toggle' => true, |
| 305 |
'default' => 'left', |
| 306 |
'selectors' => [ |
| 307 |
'{{WRAPPER}}' => 'display: flex; justify-content: {{VALUE}};', |
| 308 |
], |
| 309 |
] |
| 310 |
); |
| 311 |
// End section |
| 312 |
$this->end_controls_section(); |
| 313 |
} |
| 314 |
|
| 315 |
protected function render() |
| 316 |
{ |
| 317 |
$settings = $this->get_settings_for_display(); |
| 318 |
|
| 319 |
$style = isset($settings['style']) ? $settings['style'] : 1; |
| 320 |
$size = isset($settings['size']) ? $settings['size'] : 1; |
| 321 |
$custom_size = isset($settings['custom_size']) ? $settings['custom_size'] : 100; |
| 322 |
if ('custom' === $size) { |
| 323 |
$switcher_size = $custom_size; |
| 324 |
} else { |
| 325 |
$switcher_size = $size * 100; |
| 326 |
} |
| 327 |
|
| 328 |
echo do_shortcode(wp_sprintf('[darkify switch="%s" icon_size="40px" light_mode_bg="#121116" dark_mode_bg="#ffffff" light_mode_color="#ffffff" dark_mode_color="#121116" border="0px" border_light_color="#121119" border_dark_color="#ffffff" border_radius="7px" switch_size="%s"]', esc_attr($style), esc_attr($switcher_size))); |
| 329 |
} |
| 330 |
} |
| 331 |
|