PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.5
Elementor Website Builder – more than just a page builder v3.24.5
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.24.5, at includes/widgets/menu-anchor.php

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