| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor menu anchor widget. |
| 10 |
* |
| 11 |
* Elementor widget that allows to link and menu to a specific position on the |
| 12 |
* page. |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
class Widget_Menu_Anchor extends Widget_Base { |
| 17 |
|
| 18 |
/** |
| 19 |
* Get widget name. |
| 20 |
* |
| 21 |
* Retrieve menu anchor widget name. |
| 22 |
* |
| 23 |
* @since 1.0.0 |
| 24 |
* @access public |
| 25 |
* |
| 26 |
* @return string Widget name. |
| 27 |
*/ |
| 28 |
public function get_name() { |
| 29 |
return 'menu-anchor'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get widget title. |
| 34 |
* |
| 35 |
* Retrieve menu anchor widget title. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* @access public |
| 39 |
* |
| 40 |
* @return string Widget title. |
| 41 |
*/ |
| 42 |
public function get_title() { |
| 43 |
return esc_html__( 'Menu Anchor', 'elementor' ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get widget icon. |
| 48 |
* |
| 49 |
* Retrieve menu anchor widget icon. |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* @access public |
| 53 |
* |
| 54 |
* @return string Widget icon. |
| 55 |
*/ |
| 56 |
public function get_icon() { |
| 57 |
return 'eicon-anchor'; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Get widget keywords. |
| 62 |
* |
| 63 |
* Retrieve the list of keywords the widget belongs to. |
| 64 |
* |
| 65 |
* @since 2.1.0 |
| 66 |
* @access public |
| 67 |
* |
| 68 |
* @return array Widget keywords. |
| 69 |
*/ |
| 70 |
public function get_keywords() { |
| 71 |
return [ 'menu', 'anchor', 'link' ]; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Register menu anchor widget controls. |
| 76 |
* |
| 77 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 78 |
* |
| 79 |
* @since 3.1.0 |
| 80 |
* @access protected |
| 81 |
*/ |
| 82 |
protected function register_controls() { |
| 83 |
$this->start_controls_section( |
| 84 |
'section_anchor', |
| 85 |
[ |
| 86 |
'label' => esc_html__( 'Anchor', 'elementor' ), |
| 87 |
] |
| 88 |
); |
| 89 |
|
| 90 |
$this->add_control( |
| 91 |
'anchor', |
| 92 |
[ |
| 93 |
'label' => esc_html__( 'The ID of Menu Anchor.', 'elementor' ), |
| 94 |
'type' => Controls_Manager::TEXT, |
| 95 |
'placeholder' => esc_html__( 'For Example: About', 'elementor' ), |
| 96 |
'description' => esc_html__( 'This ID will be the CSS ID you will have to use in your own page, Without #.', 'elementor' ), |
| 97 |
'label_block' => true, |
| 98 |
] |
| 99 |
); |
| 100 |
|
| 101 |
$this->add_control( |
| 102 |
'anchor_note', |
| 103 |
[ |
| 104 |
'type' => Controls_Manager::RAW_HTML, |
| 105 |
'raw' => sprintf( esc_html__( 'Note: The ID link ONLY accepts these chars: %s', 'elementor' ), '`A-Z, a-z, 0-9, _ , -`' ), |
| 106 |
'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning', |
| 107 |
] |
| 108 |
); |
| 109 |
|
| 110 |
$this->end_controls_section(); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Render menu anchor widget output on the frontend. |
| 115 |
* |
| 116 |
* Written in PHP and used to generate the final HTML. |
| 117 |
* |
| 118 |
* @since 1.0.0 |
| 119 |
* @access protected |
| 120 |
*/ |
| 121 |
protected function render() { |
| 122 |
$anchor = $this->get_settings_for_display( 'anchor' ); |
| 123 |
|
| 124 |
if ( ! empty( $anchor ) ) { |
| 125 |
$this->add_render_attribute( 'inner', 'id', sanitize_html_class( $anchor ) ); |
| 126 |
} |
| 127 |
|
| 128 |
$this->add_render_attribute( 'inner', 'class', 'elementor-menu-anchor' ); |
| 129 |
?> |
| 130 |
<div <?php $this->print_render_attribute_string( 'inner' ); ?>></div> |
| 131 |
<?php |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Render menu anchor widget output in the editor. |
| 136 |
* |
| 137 |
* Written as a Backbone JavaScript template and used to generate the live preview. |
| 138 |
* |
| 139 |
* @since 2.9.0 |
| 140 |
* @access protected |
| 141 |
*/ |
| 142 |
protected function content_template() { |
| 143 |
?> |
| 144 |
<div class="elementor-menu-anchor"{{{ settings.anchor ? ' id="' + settings.anchor + '"' : '' }}}></div> |
| 145 |
<?php |
| 146 |
} |
| 147 |
} |
| 148 |
|