traits
5 months ago
accordion.php
2 weeks ago
alert.php
2 weeks ago
audio.php
2 weeks ago
button.php
2 weeks ago
common-base.php
2 weeks ago
common-optimized.php
1 year ago
common.php
1 year ago
counter.php
2 weeks ago
divider.php
2 weeks ago
google-maps.php
2 weeks ago
heading.php
2 weeks ago
html.php
2 weeks ago
icon-box.php
2 weeks ago
icon-list.php
2 weeks ago
icon.php
2 weeks ago
image-box.php
2 weeks ago
image-carousel.php
2 weeks ago
image-gallery.php
2 weeks ago
image.php
2 weeks ago
inner-section.php
2 years ago
menu-anchor.php
2 weeks ago
progress.php
2 weeks ago
rating.php
2 weeks ago
read-more.php
2 weeks ago
shortcode.php
2 weeks ago
sidebar.php
1 year ago
social-icons.php
2 weeks ago
spacer.php
2 weeks ago
star-rating.php
2 weeks ago
tabs.php
2 weeks ago
testimonial.php
2 weeks ago
text-editor.php
2 weeks ago
toggle.php
2 weeks ago
video.php
2 weeks ago
wordpress.php
1 year ago
menu-anchor.php
209 lines
| 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 | public function has_widget_inner_wrapper(): bool { |
| 93 | return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Register menu anchor widget controls. |
| 98 | * |
| 99 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 100 | * |
| 101 | * @since 3.1.0 |
| 102 | * @access protected |
| 103 | */ |
| 104 | protected function register_controls() { |
| 105 | $this->start_controls_section( |
| 106 | 'section_anchor', |
| 107 | [ |
| 108 | 'label' => esc_html__( 'Menu Anchor', 'elementor' ), |
| 109 | ] |
| 110 | ); |
| 111 | |
| 112 | $this->add_control( |
| 113 | 'anchor', |
| 114 | [ |
| 115 | 'label' => esc_html__( 'The ID of Menu Anchor.', 'elementor' ), |
| 116 | 'type' => Controls_Manager::TEXT, |
| 117 | 'ai' => [ |
| 118 | 'active' => false, |
| 119 | ], |
| 120 | 'placeholder' => esc_html__( 'For Example: About', 'elementor' ), |
| 121 | 'description' => esc_html__( 'This ID will be the CSS ID you will have to use in your own page, Without #.', 'elementor' ), |
| 122 | 'label_block' => true, |
| 123 | 'dynamic' => [ |
| 124 | 'active' => true, |
| 125 | ], |
| 126 | ] |
| 127 | ); |
| 128 | |
| 129 | $this->add_control( |
| 130 | 'anchor_note', |
| 131 | [ |
| 132 | 'type' => Controls_Manager::ALERT, |
| 133 | 'alert_type' => 'warning', |
| 134 | 'content' => sprintf( |
| 135 | /* translators: %s: Accepted chars. */ |
| 136 | esc_html__( 'Note: The ID link ONLY accepts these chars: %s', 'elementor' ), |
| 137 | '`A-Z, a-z, 0-9, _ , -`' |
| 138 | ), |
| 139 | ] |
| 140 | ); |
| 141 | |
| 142 | $this->end_controls_section(); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Render menu anchor widget output on the frontend. |
| 147 | * |
| 148 | * Written in PHP and used to generate the final HTML. |
| 149 | * |
| 150 | * @since 1.0.0 |
| 151 | * @access protected |
| 152 | */ |
| 153 | protected function render() { |
| 154 | $anchor = $this->get_settings_for_display( 'anchor' ); |
| 155 | |
| 156 | if ( empty( $anchor ) ) { |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | $this->add_render_attribute( |
| 161 | 'inner', |
| 162 | [ |
| 163 | 'class' => 'elementor-menu-anchor', |
| 164 | 'id' => sanitize_html_class( $anchor ), |
| 165 | ] |
| 166 | ); |
| 167 | ?> |
| 168 | <div <?php $this->print_render_attribute_string( 'inner' ); ?>></div> |
| 169 | <?php |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Render menu anchor widget output in the editor. |
| 174 | * |
| 175 | * Written as a Backbone JavaScript template and used to generate the live preview. |
| 176 | * |
| 177 | * @since 2.9.0 |
| 178 | * @access protected |
| 179 | */ |
| 180 | protected function content_template() { |
| 181 | ?> |
| 182 | <# |
| 183 | if ( '' === settings.anchor ) { |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | view.addRenderAttribute( |
| 188 | 'inner', |
| 189 | { |
| 190 | 'class': 'elementor-menu-anchor', |
| 191 | 'id': settings.anchor, |
| 192 | } |
| 193 | ); |
| 194 | #> |
| 195 | <div {{{ view.getRenderAttributeString( 'inner' ) }}}></div> |
| 196 | <?php |
| 197 | } |
| 198 | |
| 199 | public function render_markdown(): string { |
| 200 | return ''; |
| 201 | } |
| 202 | |
| 203 | protected function on_save( array $settings ) { |
| 204 | $settings['anchor'] = sanitize_html_class( $settings['anchor'] ); |
| 205 | |
| 206 | return $settings; |
| 207 | } |
| 208 | } |
| 209 |