PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.9
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.9
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / assets / js / addons / ma-navmenu.js

ma-navmenu.js in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.9, at assets/js/addons/ma-navmenu.js

249 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(){
2 //#region dev/js/common/utils.js
3 /**
4 * Master Addons - Shared Utilities
5 *
6 * Common helper functions used across all widget handlers.
7 */
8 /**
9 * Get element settings from Elementor
10 *
11 * @param {jQuery} $element - The jQuery element
12 * @param {string} setting - Optional specific setting key
13 * @returns {*} Settings object or specific setting value
14 */
15 function getElementSettings($element, setting) {
16 var elementSettings = {}, modelCID = $element.data("model-cid");
17 if (typeof elementorFrontend !== "undefined" && elementorFrontend.isEditMode() && modelCID) {
18 var settings = elementorFrontend.config.elements.data[modelCID], type = settings.attributes.widgetType || settings.attributes.elType, settingsKeys = elementorFrontend.config.elements.keys[type];
19 if (!settingsKeys) {
20 settingsKeys = elementorFrontend.config.elements.keys[type] = [];
21 jQuery.each(settings.controls, function(name, control) {
22 if (control.frontend_available) settingsKeys.push(name);
23 });
24 }
25 jQuery.each(settings.getActiveControls(), function(controlKey) {
26 if (-1 !== settingsKeys.indexOf(controlKey)) elementSettings[controlKey] = settings.attributes[controlKey];
27 });
28 } else elementSettings = $element.data("settings") || {};
29 return getItems(elementSettings, setting);
30 }
31 /**
32 * Get nested items from an object
33 *
34 * @param {Object} items - The items object
35 * @param {string} itemKey - Dot-notation key path
36 * @returns {*} The value at the key path
37 */
38 function getItems(items, itemKey) {
39 if (itemKey) {
40 var keyStack = itemKey.split("."), currentKey = keyStack.splice(0, 1);
41 if (!keyStack.length) return items[currentKey];
42 if (!items[currentKey]) return;
43 return getItems(items[currentKey], keyStack.join("."));
44 }
45 return items;
46 }
47 /**
48 * Get unique loop scope ID
49 *
50 * @param {jQuery} $scope - The scope element
51 * @returns {string} The unique ID
52 */
53 function getUniqueLoopScopeId($scope) {
54 if ($scope.data("jltma-template-widget-id")) return $scope.data("jltma-template-widget-id");
55 return $scope.data("id");
56 }
57 /**
58 * Observe target element with IntersectionObserver
59 *
60 * @param {Element} target - The target element to observe
61 * @param {Function} callback - Callback when element intersects
62 * @param {Object} options - IntersectionObserver options
63 */
64 function jltMAObserveTarget(target, callback, options = {}) {
65 new IntersectionObserver(function(entries, observer) {
66 entries.forEach(function(entry) {
67 if (entry.isIntersecting) callback(entry);
68 });
69 }, options).observe(target);
70 }
71 /**
72 * Strip HTML tags from text
73 *
74 * @param {string} text - Text to strip
75 * @returns {string} Text without HTML tags
76 */
77 function stripTags(text) {
78 return text.replace(/<\/?[^>]+(>|$)/g, "");
79 }
80 /**
81 * Check if in Elementor edit mode
82 *
83 * @returns {boolean} True if in edit mode
84 */
85 function isEditMode() {
86 return typeof elementorFrontend !== "undefined" && elementorFrontend.isEditMode();
87 }
88 //#endregion
89 //#region dev/js/addons/free/ma-navmenu.js
90 /**
91 * Start nav menu widget script
92 */
93 (function($, elementor) {
94 "use strict";
95 var JLTMA_NavMenu = function($scope, $) {
96 getElementSettings($scope);
97 var $menuContainer = $scope.find(".jltma-nav-menu-element"), $menuID = $menuContainer.data("menu-id"), $menu_type = $menuContainer.data("menu-layout");
98 $menuContainer.data("menu-trigger");
99 $menuContainer.data("menu-offcanvas");
100 var $menu_toggletype = $menuContainer.data("menu-toggletype"), $submenu_animation = $menuContainer.data("menu-animation"), $menu_container_id = $menuContainer.data("menu-container-id"), $sticky_type = $menuContainer.data("sticky-type"), navbar_height = $("#" + $menu_container_id).outerHeight(), menu_container_selector = $("#" + $menu_container_id);
101 if ($menu_type == "onepage") {
102 $(document).on("click", ".jltma-navbar-nav li a", function(e) {
103 if ($(this).attr("href")) {
104 var self = $(this), el = self.get(0), href = el.href, hasHash = href.indexOf("#"), enable = self.parents(".jltma-navbar-nav-default").hasClass("jltma-one-page-enabled");
105 if (hasHash !== -1 && href.length > 1 && enable && el.pathname == window.location.pathname) {
106 e.preventDefault();
107 self.parents(".jltma-menu-container").find(".jltma-close").trigger("click");
108 }
109 }
110 });
111 $(document).on("click", function(e) {
112 $(e.target);
113 if ($(".navbar-collapse").hasClass("show") === true) $(".jltma-one-page-enabled").removeClass("show");
114 });
115 } else {
116 "" + $submenu_animation;
117 var submenu_selector = $(".jltma-dropdown.jltma-sub-menu");
118 $("#" + $menuID + " .jltma-menu-has-children").hover(function() {
119 if (submenu_selector.hasClass("fade-up")) submenu_selector.removeClass("fade-up");
120 if (submenu_selector.hasClass("fade-down")) submenu_selector.removeClass("fade-down");
121 $(".jltma-dropdown.jltma-sub-menu").addClass($submenu_animation);
122 });
123 if ($sticky_type == "fixed-onscroll") {
124 if ($(window).width() > 768) $(function() {
125 $(window).scroll(function() {
126 if ($(window).scrollTop() >= 10) menu_container_selector.removeClass("" + $menu_container_id).addClass("jltma-on-scroll-fixed");
127 else menu_container_selector.removeClass("jltma-on-scroll-fixed").addClass("" + $menu_container_id);
128 });
129 });
130 }
131 if ($sticky_type == "sticky-top") {
132 if ($(window).width() > 768) $(function() {
133 $(window).scroll(function() {
134 if ($(window).scrollTop() >= 10) menu_container_selector.removeClass("" + $menu_container_id).addClass("sticky-top");
135 else menu_container_selector.removeClass("sticky-top").addClass("" + $menu_container_id);
136 });
137 });
138 }
139 if ($sticky_type == "smart-scroll") {
140 $("body").css("padding-top", navbar_height + "px");
141 menu_container_selector.addClass("jltma-smart-scroll");
142 if ($(".jltma-smart-scroll").length > 0) {
143 var last_scroll_top = 0;
144 $(window).on("scroll", function() {
145 var scroll_top = $(this).scrollTop();
146 if (scroll_top < last_scroll_top) $(".jltma-smart-scroll").removeClass("scrolled-down").addClass("scrolled-up");
147 else $(".jltma-smart-scroll").removeClass("scrolled-up").addClass("scrolled-down");
148 last_scroll_top = scroll_top;
149 });
150 }
151 }
152 if ($sticky_type == "nav-fixed-top") {
153 if ($(window).width() > 768) $(function() {
154 $("body").css("padding-top", navbar_height + "px");
155 menu_container_selector.addClass("jltma-fixed-top");
156 });
157 }
158 if ($menu_toggletype == "toggle") $("#" + $menuID + " .navbar-nav.toggle .jltma-menu-dropdown-toggle").click(function(e) {
159 $(this).parents(".dropdown").toggleClass("open");
160 e.stopPropagation();
161 });
162 var $widget = $scope;
163 var $toggle = $scope.find(".jltma-nav-menu__toggle-container");
164 var $dropdown = $scope.find(".jltma-nav-menu__dropdown");
165 var $closeBtn = $scope.find(".jltma-nav-menu__dropdown-close");
166 var $backdrop = $scope.find(".jltma-nav-menu__backdrop");
167 var dropdownType = $dropdown.data("menu-type");
168 var lockBody = dropdownType === "offcanvas" || dropdownType === "popup";
169 var keyNs = "keydown.jltmaNav-" + ($widget.attr("data-id") || "");
170 $toggle.off(".jltmaNav");
171 $closeBtn.off(".jltmaNav");
172 $backdrop.off(".jltmaNav");
173 $dropdown.off(".jltmaNav");
174 $(document).off(keyNs);
175 if ($toggle.length === 0) return;
176 function jltmaOpen() {
177 $widget.addClass("jltma-is-open");
178 $toggle.attr("aria-expanded", "true");
179 if (lockBody) {
180 $dropdown.attr("aria-hidden", "false");
181 $("body").addClass("jltma-menu-locked");
182 }
183 }
184 function jltmaClose() {
185 $widget.removeClass("jltma-is-open");
186 $toggle.attr("aria-expanded", "false");
187 if (lockBody) {
188 $dropdown.attr("aria-hidden", "true");
189 $("body").removeClass("jltma-menu-locked");
190 }
191 }
192 function jltmaIsOpen() {
193 return $widget.hasClass("jltma-is-open");
194 }
195 $toggle.on("click.jltmaNav", function(e) {
196 e.preventDefault();
197 e.stopPropagation();
198 if (jltmaIsOpen()) jltmaClose();
199 else jltmaOpen();
200 });
201 $toggle.on("keydown.jltmaNav", function(e) {
202 if (e.key === "Enter" || e.key === " ") {
203 e.preventDefault();
204 if (jltmaIsOpen()) jltmaClose();
205 else jltmaOpen();
206 }
207 });
208 $closeBtn.on("click.jltmaNav", function(e) {
209 e.preventDefault();
210 jltmaClose();
211 });
212 if (lockBody) {
213 $backdrop.on("click.jltmaNav", jltmaClose);
214 $(document).on(keyNs, function(e) {
215 if (e.key === "Escape" && jltmaIsOpen()) jltmaClose();
216 });
217 $dropdown.on("click.jltmaNav", "a[href]:not([href=\"#\"]):not([href=\"\"])", function() {
218 jltmaClose();
219 });
220 }
221 if (dropdownType === "default" || dropdownType === "icon") $dropdown.on("click.jltmaNav", "a", function(e) {
222 var $li = $(this).parent("li.menu-item-has-children");
223 if (!$li.length) return;
224 if (!$li.children("ul").first().length) return;
225 if (!$li.hasClass("jltma-submenu-open")) {
226 e.preventDefault();
227 e.stopPropagation();
228 $li.addClass("jltma-submenu-open");
229 }
230 });
231 }
232 };
233 $(window).on("elementor/frontend/init", function() {
234 if (typeof elementorFrontend !== "undefined" && elementorFrontend.hooks) elementorFrontend.hooks.addAction("frontend/element_ready/ma-navmenu.default", JLTMA_NavMenu);
235 });
236 $(function() {
237 $(".jltma-nav-menu__toggle-container").each(function() {
238 var $scope = $(this).closest(".elementor-element, .elementor-widget, [data-widget_type]").first();
239 if (!$scope.length) $scope = $(this).parent();
240 JLTMA_NavMenu($scope, $);
241 });
242 });
243 })(jQuery, window.elementorFrontend);
244 /**
245 * End nav menu widget script
246 */
247 //#endregion
248 })();
249