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

164 lines 3.4 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 /**
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 'ai' => [
96 'active' => false,
97 ],
98 'placeholder' => esc_html__( 'For Example: About', 'elementor' ),
99 'description' => esc_html__( 'This ID will be the CSS ID you will have to use in your own page, Without #.', 'elementor' ),
100 'label_block' => true,
101 'dynamic' => [
102 'active' => true,
103 ],
104 ]
105 );
106
107 $this->add_control(
108 'anchor_note',
109 [
110 'type' => Controls_Manager::RAW_HTML,
111 'raw' => sprintf(
112 /* translators: %s: Accepted chars. */
113 esc_html__( 'Note: The ID link ONLY accepts these chars: %s', 'elementor' ),
114 '`A-Z, a-z, 0-9, _ , -`'
115 ),
116 'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning',
117 ]
118 );
119
120 $this->end_controls_section();
121 }
122
123 /**
124 * Render menu anchor widget output on the frontend.
125 *
126 * Written in PHP and used to generate the final HTML.
127 *
128 * @since 1.0.0
129 * @access protected
130 */
131 protected function render() {
132 $anchor = $this->get_settings_for_display( 'anchor' );
133
134 if ( ! empty( $anchor ) ) {
135 $this->add_render_attribute( 'inner', 'id', sanitize_html_class( $anchor ) );
136 }
137
138 $this->add_render_attribute( 'inner', 'class', 'elementor-menu-anchor' );
139 ?>
140 <div <?php $this->print_render_attribute_string( 'inner' ); ?>></div>
141 <?php
142 }
143
144 /**
145 * Render menu anchor widget output in the editor.
146 *
147 * Written as a Backbone JavaScript template and used to generate the live preview.
148 *
149 * @since 2.9.0
150 * @access protected
151 */
152 protected function content_template() {
153 ?>
154 <div class="elementor-menu-anchor"{{{ settings.anchor ? ' id="' + settings.anchor + '"' : '' }}}></div>
155 <?php
156 }
157
158 protected function on_save( array $settings ) {
159 $settings['anchor'] = sanitize_html_class( $settings['anchor'] );
160
161 return $settings;
162 }
163 }
164