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

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