PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.1
Elementor Website Builder – more than just a page builder v3.22.1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / menu-anchor.php

menu-anchor.php in Elementor Website Builder – more than just a page builder 3.22.1, at includes/widgets/menu-anchor.php

187 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 protected function is_dynamic_content(): bool {
75 return false;
76 }
77
78 /**
79 * Register menu anchor widget controls.
80 *
81 * Adds different input fields to allow the user to change and customize the widget settings.
82 *
83 * @since 3.1.0
84 * @access protected
85 */
86 protected function register_controls() {
87 $this->start_controls_section(
88 'section_anchor',
89 [
90 'label' => esc_html__( 'Menu Anchor', 'elementor' ),
91 ]
92 );
93
94 $this->add_control(
95 'anchor',
96 [
97 'label' => esc_html__( 'The ID of Menu Anchor.', 'elementor' ),
98 'type' => Controls_Manager::TEXT,
99 'ai' => [
100 'active' => false,
101 ],
102 'placeholder' => esc_html__( 'For Example: About', 'elementor' ),
103 'description' => esc_html__( 'This ID will be the CSS ID you will have to use in your own page, Without #.', 'elementor' ),
104 'label_block' => true,
105 'dynamic' => [
106 'active' => true,
107 ],
108 ]
109 );
110
111 $this->add_control(
112 'anchor_note',
113 [
114 'type' => Controls_Manager::ALERT,
115 'alert_type' => 'warning',
116 'content' => sprintf(
117 /* translators: %s: Accepted chars. */
118 esc_html__( 'Note: The ID link ONLY accepts these chars: %s', 'elementor' ),
119 '`A-Z, a-z, 0-9, _ , -`'
120 ),
121 ]
122 );
123
124 $this->end_controls_section();
125 }
126
127 /**
128 * Render menu anchor widget output on the frontend.
129 *
130 * Written in PHP and used to generate the final HTML.
131 *
132 * @since 1.0.0
133 * @access protected
134 */
135 protected function render() {
136 $anchor = $this->get_settings_for_display( 'anchor' );
137
138 if ( empty( $anchor ) ) {
139 return;
140 }
141
142 $this->add_render_attribute(
143 'inner',
144 [
145 'class' => 'elementor-menu-anchor',
146 'id' => sanitize_html_class( $anchor ),
147 ]
148 );
149 ?>
150 <div <?php $this->print_render_attribute_string( 'inner' ); ?>></div>
151 <?php
152 }
153
154 /**
155 * Render menu anchor widget output in the editor.
156 *
157 * Written as a Backbone JavaScript template and used to generate the live preview.
158 *
159 * @since 2.9.0
160 * @access protected
161 */
162 protected function content_template() {
163 ?>
164 <#
165 if ( '' === settings.anchor ) {
166 return;
167 }
168
169 view.addRenderAttribute(
170 'inner',
171 {
172 'class': 'elementor-menu-anchor',
173 'id': settings.anchor,
174 }
175 );
176 #>
177 <div {{{ view.getRenderAttributeString( 'inner' ) }}}></div>
178 <?php
179 }
180
181 protected function on_save( array $settings ) {
182 $settings['anchor'] = sanitize_html_class( $settings['anchor'] );
183
184 return $settings;
185 }
186 }
187