✏️ 正在编辑: datis_box.php
路径:
/home/h359620/public_html/wp-content/themes/datis/inc/elementor/widgets/datis_box/datis_box.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php namespace Datis\Widgets; if (!defined('ABSPATH')) exit; use Elementor\Widget_Base; use Elementor\Controls_Manager; use Elementor\Group_Control_Typography; use Elementor\Group_Control_Background; use Elementor\Group_Control_Border; use Elementor\Group_Control_Box_Shadow; use Elementor\Icons_Manager; if (!class_exists('Datis_Box')) { class Datis_Box extends Widget_Base { public function get_name() { return 'datis_box'; } public function get_title() { return __('Box', 'datis'); } public function get_icon() { return 'eicon-layout'; } public function get_categories() { return ['datis-widgets']; } protected function register_controls() { /* ================= CONTENT ================= */ $this->start_controls_section('section_content', [ 'label' => __('Items', 'datis'), 'tab' => Controls_Manager::TAB_CONTENT, ]); $repeater = new \Elementor\Repeater(); $repeater->add_control('number', [ 'label' => __('Number', 'datis'), 'type' => Controls_Manager::TEXT, 'default' => '01', ]); $repeater->add_control('title', [ 'label' => __('Title', 'datis'), 'type' => Controls_Manager::TEXT, 'default' => __('Idea & Research', 'datis'), ]); $repeater->add_control('desc', [ 'label' => __('Description', 'datis'), 'type' => Controls_Manager::TEXTAREA, 'rows' => 4, ]); $repeater->add_control('icon', [ 'label' => __('Icon', 'datis'), 'type' => Controls_Manager::ICONS, ]); $this->add_control('items', [ 'type' => Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(), 'title_field' => '{{{ title }}}', ]); $this->end_controls_section(); /* ================= SLIDER ================= */ $this->start_controls_section('section_slider', [ 'label' => __('Slider Settings', 'datis'), 'tab' => Controls_Manager::TAB_CONTENT, ]); $this->add_responsive_control( 'slides_per_view', [ 'label' => __('Slides Per View', 'datis'), 'type' => Controls_Manager::NUMBER, 'desktop_default' => 3, 'tablet_default' => 2, 'mobile_default' => 1, 'min' => 1, 'max' => 6, 'step' => 0.1, ] ); $this->add_responsive_control( 'space_between', [ 'label' => __('Space Between', 'datis'), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => ['min' => 0, 'max' => 100], ], 'default' => [ 'size' => 30, 'unit' => 'px', ], ] ); $this->add_control('autoplay', [ 'label' => __('Autoplay', 'datis'), 'type' => Controls_Manager::SWITCHER, ]); $this->end_controls_section(); /* ================= STYLE ================= */ $this->start_controls_section('section_style_box', [ 'label' => __('Box', 'datis'), 'tab' => Controls_Manager::TAB_STYLE, ]); /* ---- Tabs Normal / Hover ---- */ $this->start_controls_tabs('tabs_box_style'); /* NORMAL */ $this->start_controls_tab('tab_box_normal', [ 'label' => __('Normal', 'datis'), ]); $this->add_group_control(Group_Control_Background::get_type(), [ 'name' => 'box_bg', 'selector' => '{{WRAPPER}} .datis-box', ]); $this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'box_border', 'selector' => '{{WRAPPER}} .datis-box', ]); $this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'box_shadow', 'selector' => '{{WRAPPER}} .datis-box', ]); $this->end_controls_tab(); /* HOVER */ $this->start_controls_tab('tab_box_hover', [ 'label' => __('Hover', 'datis'), ]); $this->add_group_control(Group_Control_Background::get_type(), [ 'name' => 'box_bg_hover', 'selector' => '{{WRAPPER}} .datis-box:hover', ]); $this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'box_border_hover', 'selector' => '{{WRAPPER}} .datis-box:hover', ]); $this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'box_shadow_hover', 'selector' => '{{WRAPPER}} .datis-box:hover', ]); $this->end_controls_tab(); $this->end_controls_tabs(); $this->end_controls_section(); $this->start_controls_section('style_box_wrapper', [ 'label' => __('Box Wrapper', 'datis'), 'tab' => Controls_Manager::TAB_STYLE, ]); $this->add_responsive_control( 'box_max_width', [ 'label' => __('Max Width', 'datis'), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => ['min' => 200, 'max' => 600], ], 'selectors' => [ '{{WRAPPER}} .datis-box' => 'max-width: {{SIZE}}{{UNIT}};', ], ] ); $this->add_responsive_control( 'box_align', [ 'label' => __('Alignment', 'datis'), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'flex-start' => [ 'title' => __('Start', 'datis'), 'icon' => 'eicon-align-start-h', ], 'center' => [ 'title' => __('Center', 'datis'), 'icon' => 'eicon-align-center-h', ], 'flex-end' => [ 'title' => __('End', 'datis'), 'icon' => 'eicon-align-end-h', ], ], 'default' => 'center', 'selectors' => [ '{{WRAPPER}} .datis-box' => 'align-items: {{VALUE}};', ], ] ); $this->end_controls_section(); $this->start_controls_section('style_box_header', [ 'label' => __('Header Number', 'datis'), 'tab' => Controls_Manager::TAB_STYLE, ]); $this->start_controls_tabs('header_style_tabs'); $this->start_controls_tab('header_normal', [ 'label' => __('Normal', 'datis'), ]); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'header_typography', 'selector' => '{{WRAPPER}} .datis-box-header', ] ); $this->add_control( 'header_text_color', [ 'label' => __('Text Color', 'datis'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .datis-box-header' => 'color: {{VALUE}};', ], ] ); $this->add_group_control( Group_Control_Background::get_type(), [ 'name' => 'header_bg', 'selector' => '{{WRAPPER}} .datis-box-header', ] ); $this->end_controls_tab(); /* HOVER */ $this->start_controls_tab('header_hover', [ 'label' => __('Hover', 'datis'), ]); $this->add_control( 'header_text_color_hover', [ 'label' => __('Text Color', 'datis'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .datis-box:hover .datis-box-header' => 'color: {{VALUE}};', ], ] ); $this->add_group_control( Group_Control_Background::get_type(), [ 'name' => 'header_bg_hover', 'selector' => '{{WRAPPER}} .datis-box:hover .datis-box-header', ] ); $this->end_controls_tab(); $this->end_controls_tabs(); $this->end_controls_section(); $this->start_controls_section('style_box_content', [ 'label' => __('Box Content', 'datis'), 'tab' => Controls_Manager::TAB_STYLE, ]); $this->start_controls_tabs('content_style_tabs'); /* NORMAL */ $this->start_controls_tab('content_normal', [ 'label' => __('Normal', 'datis'), ]); $this->add_group_control( Group_Control_Background::get_type(), [ 'name' => 'content_bg', 'selector' => '{{WRAPPER}} .datis-box-content', ] ); $this->add_responsive_control( 'content_padding', [ 'label' => __('Padding', 'datis'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .datis-box-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->add_group_control( Group_Control_Border::get_type(), [ 'name' => 'content_border', 'selector' => '{{WRAPPER}} .datis-box-content', ] ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => 'content_shadow', 'selector' => '{{WRAPPER}} .datis-box-content', ] ); $this->end_controls_tab(); /* HOVER */ $this->start_controls_tab('content_hover', [ 'label' => __('Hover', 'datis'), ]); $this->add_group_control( Group_Control_Background::get_type(), [ 'name' => 'content_bg_hover', 'selector' => '{{WRAPPER}} .datis-box:hover .datis-box-content', ] ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => 'content_shadow_hover', 'selector' => '{{WRAPPER}} .datis-box:hover .datis-box-content', ] ); $this->end_controls_tab(); $this->end_controls_tabs(); $this->end_controls_section(); $this->start_controls_section('style_title', [ 'label' => __('Title', 'datis'), 'tab' => Controls_Manager::TAB_STYLE, ]); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'title_typography', 'selector' => '{{WRAPPER}} .box-heading', ] ); $this->add_control( 'title_color', [ 'label' => __('Color', 'datis'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .box-heading' => 'color: {{VALUE}};', ], ] ); $this->end_controls_section(); $this->start_controls_section('style_desc', [ 'label' => __('Description', 'datis'), 'tab' => Controls_Manager::TAB_STYLE, ]); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'desc_typography', 'selector' => '{{WRAPPER}} .box-details', ] ); $this->add_control( 'desc_color', [ 'label' => __('Color', 'datis'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .box-details' => 'color: {{VALUE}};', ], ] ); $this->end_controls_section(); } /* -------------------- RENDER -------------------- */ protected function render() { $settings = $this->get_settings_for_display(); if (empty($settings['items'])) return; ?> <div class="swiper datis-box-slider" data-slides-desktop="<?php echo esc_attr($settings['slides_per_view']); ?>" data-slides-tablet="<?php echo esc_attr($settings['slides_per_view_tablet']); ?>" data-slides-mobile="<?php echo esc_attr($settings['slides_per_view_mobile']); ?>" data-space="<?php echo esc_attr($settings['space_between']['size']); ?>" data-autoplay="<?php echo esc_attr($settings['autoplay']); ?>"> <div class="swiper-wrapper"> <?php foreach ($settings['items'] as $item): ?> <div class="swiper-slide"> <div class="datis-box"> <?php if (!empty($item['icon']['value'])): ?> <div class="datis-box-icon"> <?php Icons_Manager::render_icon($item['icon']); ?> </div> <?php endif; ?> <div class="datis-box-header"> <?php echo esc_html($item['number']); ?> </div> <div class="datis-box-content"> <h3 class="box-heading"> <?php echo esc_html($item['title']); ?> </h3> <p class="box-details"> <?php echo esc_html($item['desc']); ?> </p> </div> </div> </div> <?php endforeach; ?> </div> <div class="datis-box-nav mobile-only"> <div class="box-prev"></div> <div class="box-next"> <svg width="26" height="14" viewBox="0 0 26 14" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M0.75 6.75L6.75 0.75M0.75 6.75L6.75 12.75M0.75 6.75H11.25M24.75 6.75H14.25" stroke="var(--datis-secondary-color)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> </svg> </div> </div> </div> <?php } /* -------------------- ENQUEUE -------------------- */ public function __construct($data = [], $args = null) { parent::__construct($data, $args); add_action('elementor/editor/before_enqueue_scripts', [$this, 'enqueue_assets']); add_action('elementor/editor/before_enqueue_styles', [$this, 'enqueue_assets']); add_action('elementor/frontend/before_enqueue_scripts', [$this, 'enqueue_assets']); add_action('elementor/frontend/before_enqueue_styles', [$this, 'enqueue_assets']); } public function enqueue_assets() { wp_enqueue_style('datis-box', DATIS_URI . '/inc/elementor/widgets/datis_box/css/box.css', [], DATIS_VER, 'all'); wp_enqueue_script('datis-box', DATIS_URI . '/inc/elementor/widgets/datis_box/js/box.js', [], DATIS_VER, true); } } }
💾 保存文件
← 返回文件管理器