| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- <?php
- namespace Elementor;
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- /**
- * Elementor social icons widget.
- *
- * Elementor widget that displays icons to social pages like Facebook and Twitter.
- *
- * @since 1.0.0
- */
- class Widget_Social_Icons extends Widget_Base {
- /**
- * Get widget name.
- *
- * Retrieve social icons widget name.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget name.
- */
- public function get_name() {
- return 'social-icons';
- }
- /**
- * Get widget title.
- *
- * Retrieve social icons widget title.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget title.
- */
- public function get_title() {
- return __( 'Social Icons', 'elementor' );
- }
- /**
- * Get widget icon.
- *
- * Retrieve social icons widget icon.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget icon.
- */
- public function get_icon() {
- return 'eicon-social-icons';
- }
- /**
- * Get widget keywords.
- *
- * Retrieve the list of keywords the widget belongs to.
- *
- * @since 2.1.0
- * @access public
- *
- * @return array Widget keywords.
- */
- public function get_keywords() {
- return [ 'social', 'icon', 'link' ];
- }
- /**
- * Register social icons widget controls.
- *
- * Adds different input fields to allow the user to change and customize the widget settings.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _register_controls() {
- $this->start_controls_section(
- 'section_social_icon',
- [
- 'label' => __( 'Social Icons', 'elementor' ),
- ]
- );
- $repeater = new Repeater();
- $repeater->add_control(
- 'social',
- [
- 'label' => __( 'Icon', 'elementor' ),
- 'type' => Controls_Manager::ICON,
- 'label_block' => true,
- 'default' => 'fa fa-wordpress',
- 'include' => [
- 'fa fa-android',
- 'fa fa-apple',
- 'fa fa-behance',
- 'fa fa-bitbucket',
- 'fa fa-codepen',
- 'fa fa-delicious',
- 'fa fa-digg',
- 'fa fa-dribbble',
- 'fa fa-envelope',
- 'fa fa-facebook',
- 'fa fa-flickr',
- 'fa fa-foursquare',
- 'fa fa-github',
- 'fa fa-google-plus',
- 'fa fa-houzz',
- 'fa fa-instagram',
- 'fa fa-jsfiddle',
- 'fa fa-linkedin',
- 'fa fa-medium',
- 'fa fa-meetup',
- 'fa fa-mixcloud',
- 'fa fa-odnoklassniki',
- 'fa fa-pinterest',
- 'fa fa-product-hunt',
- 'fa fa-reddit',
- 'fa fa-rss',
- 'fa fa-shopping-cart',
- 'fa fa-skype',
- 'fa fa-slideshare',
- 'fa fa-snapchat',
- 'fa fa-soundcloud',
- 'fa fa-spotify',
- 'fa fa-stack-overflow',
- 'fa fa-steam',
- 'fa fa-stumbleupon',
- 'fa fa-telegram',
- 'fa fa-thumb-tack',
- 'fa fa-tripadvisor',
- 'fa fa-tumblr',
- 'fa fa-twitch',
- 'fa fa-twitter',
- 'fa fa-vimeo',
- 'fa fa-vk',
- 'fa fa-weibo',
- 'fa fa-weixin',
- 'fa fa-whatsapp',
- 'fa fa-wordpress',
- 'fa fa-xing',
- 'fa fa-yelp',
- 'fa fa-youtube',
- 'fa fa-500px',
- ],
- ]
- );
- $repeater->add_control(
- 'link',
- [
- 'label' => __( 'Link', 'elementor' ),
- 'type' => Controls_Manager::URL,
- 'label_block' => true,
- 'default' => [
- 'is_external' => 'true',
- ],
- 'placeholder' => __( 'https://your-link.com', 'elementor' ),
- ]
- );
- $this->add_control(
- 'social_icon_list',
- [
- 'label' => __( 'Social Icons', 'elementor' ),
- 'type' => Controls_Manager::REPEATER,
- 'fields' => $repeater->get_controls(),
- 'default' => [
- [
- 'social' => 'fa fa-facebook',
- ],
- [
- 'social' => 'fa fa-twitter',
- ],
- [
- 'social' => 'fa fa-google-plus',
- ],
- ],
- 'title_field' => '<i class="{{ social }}"></i> {{{ social.replace( \'fa fa-\', \'\' ).replace( \'-\', \' \' ).replace( /\b\w/g, function( letter ){ return letter.toUpperCase() } ) }}}',
- ]
- );
- $this->add_control(
- 'shape',
- [
- 'label' => __( 'Shape', 'elementor' ),
- 'type' => Controls_Manager::SELECT,
- 'default' => 'rounded',
- 'options' => [
- 'rounded' => __( 'Rounded', 'elementor' ),
- 'square' => __( 'Square', 'elementor' ),
- 'circle' => __( 'Circle', 'elementor' ),
- ],
- 'prefix_class' => 'elementor-shape-',
- ]
- );
- $this->add_responsive_control(
- 'align',
- [
- 'label' => __( 'Alignment', 'elementor' ),
- 'type' => Controls_Manager::CHOOSE,
- 'options' => [
- 'left' => [
- 'title' => __( 'Left', 'elementor' ),
- 'icon' => 'fa fa-align-left',
- ],
- 'center' => [
- 'title' => __( 'Center', 'elementor' ),
- 'icon' => 'fa fa-align-center',
- ],
- 'right' => [
- 'title' => __( 'Right', 'elementor' ),
- 'icon' => 'fa fa-align-right',
- ],
- ],
- 'default' => 'center',
- 'selectors' => [
- '{{WRAPPER}}' => 'text-align: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'view',
- [
- 'label' => __( 'View', 'elementor' ),
- 'type' => Controls_Manager::HIDDEN,
- 'default' => 'traditional',
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_social_style',
- [
- 'label' => __( 'Icon', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- ]
- );
- $this->add_control(
- 'icon_color',
- [
- 'label' => __( 'Color', 'elementor' ),
- 'type' => Controls_Manager::SELECT,
- 'default' => 'default',
- 'options' => [
- 'default' => __( 'Official Color', 'elementor' ),
- 'custom' => __( 'Custom', 'elementor' ),
- ],
- ]
- );
- $this->add_control(
- 'icon_primary_color',
- [
- 'label' => __( 'Primary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'condition' => [
- 'icon_color' => 'custom',
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon:not(:hover)' => 'background-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'icon_secondary_color',
- [
- 'label' => __( 'Secondary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'condition' => [
- 'icon_color' => 'custom',
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon:not(:hover) i' => 'color: {{VALUE}};',
- ],
- ]
- );
- $this->add_responsive_control(
- 'icon_size',
- [
- 'label' => __( 'Size', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 6,
- 'max' => 300,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon' => 'font-size: {{SIZE}}{{UNIT}};',
- ],
- ]
- );
- $this->add_responsive_control(
- 'icon_padding',
- [
- 'label' => __( 'Padding', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon' => 'padding: {{SIZE}}{{UNIT}};',
- ],
- 'default' => [
- 'unit' => 'em',
- ],
- 'tablet_default' => [
- 'unit' => 'em',
- ],
- 'mobile_default' => [
- 'unit' => 'em',
- ],
- 'range' => [
- 'em' => [
- 'min' => 0,
- 'max' => 5,
- ],
- ],
- ]
- );
- $icon_spacing = is_rtl() ? 'margin-left: {{SIZE}}{{UNIT}};' : 'margin-right: {{SIZE}}{{UNIT}};';
- $this->add_responsive_control(
- 'icon_spacing',
- [
- 'label' => __( 'Spacing', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 0,
- 'max' => 100,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon:not(:last-child)' => $icon_spacing,
- ],
- ]
- );
- $this->add_group_control(
- Group_Control_Border::get_type(),
- [
- 'name' => 'image_border', // We know this mistake - TODO: 'icon_border' (for hover control condition also)
- 'selector' => '{{WRAPPER}} .elementor-social-icon',
- 'separator' => 'before',
- ]
- );
- $this->add_control(
- 'border_radius',
- [
- 'label' => __( 'Border Radius', 'elementor' ),
- 'type' => Controls_Manager::DIMENSIONS,
- 'size_units' => [ 'px', '%' ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
- ],
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_social_hover',
- [
- 'label' => __( 'Icon Hover', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- ]
- );
- $this->add_control(
- 'hover_primary_color',
- [
- 'label' => __( 'Primary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'condition' => [
- 'icon_color' => 'custom',
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon:hover' => 'background-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'hover_secondary_color',
- [
- 'label' => __( 'Secondary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'condition' => [
- 'icon_color' => 'custom',
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon:hover i' => 'color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'hover_border_color',
- [
- 'label' => __( 'Border Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'condition' => [
- 'image_border_border!' => '',
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-social-icon:hover' => 'border-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'hover_animation',
- [
- 'label' => __( 'Hover Animation', 'elementor' ),
- 'type' => Controls_Manager::HOVER_ANIMATION,
- ]
- );
- $this->end_controls_section();
- }
- /**
- * Render social icons widget output on the frontend.
- *
- * Written in PHP and used to generate the final HTML.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function render() {
- $settings = $this->get_settings_for_display();
- $class_animation = '';
- if ( ! empty( $settings['hover_animation'] ) ) {
- $class_animation = ' elementor-animation-' . $settings['hover_animation'];
- }
- ?>
- <div class="elementor-social-icons-wrapper">
- <?php
- foreach ( $settings['social_icon_list'] as $index => $item ) {
- $social = str_replace( 'fa fa-', '', $item['social'] );
- $link_key = 'link_' . $index;
- $this->add_render_attribute( $link_key, 'href', $item['link']['url'] );
- if ( $item['link']['is_external'] ) {
- $this->add_render_attribute( $link_key, 'target', '_blank' );
- }
- if ( $item['link']['nofollow'] ) {
- $this->add_render_attribute( $link_key, 'rel', 'nofollow' );
- }
- ?>
- <a class="elementor-icon elementor-social-icon elementor-social-icon-<?php echo $social . $class_animation; ?>" <?php echo $this->get_render_attribute_string( $link_key ); ?>>
- <span class="elementor-screen-only"><?php echo ucwords( $social ); ?></span>
- <i class="<?php echo $item['social']; ?>"></i>
- </a>
- <?php } ?>
- </div>
- <?php
- }
- /**
- * Render social icons widget output in the editor.
- *
- * Written as a Backbone JavaScript template and used to generate the live preview.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _content_template() {
- ?>
- <div class="elementor-social-icons-wrapper">
- <# _.each( settings.social_icon_list, function( item ) {
- var link = item.link ? item.link.url : '',
- social = item.social.replace( 'fa fa-', '' ); #>
- <a class="elementor-icon elementor-social-icon elementor-social-icon-{{ social }} elementor-animation-{{ settings.hover_animation }}" href="{{ link }}">
- <span class="elementor-screen-only">{{{ social }}}</span>
- <i class="{{ item.social }}"></i>
- </a>
- <# } ); #>
- </div>
- <?php
- }
- }
|