| 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-tooltip.js |
| 90 |
/** |
| 91 |
* Start tooltip widget script |
| 92 |
*/ |
| 93 |
(function($, elementor) { |
| 94 |
"use strict"; |
| 95 |
var activeTooltipWidgets = {}; |
| 96 |
var initTooltip = function($scope, editorSettings) { |
| 97 |
if (!$scope || !$scope.length) return; |
| 98 |
if (typeof tippy === "undefined") { |
| 99 |
var retryCount = ($scope.data("ma-tooltip-retry") || 0) + 1; |
| 100 |
if (retryCount <= 10) { |
| 101 |
$scope.data("ma-tooltip-retry", retryCount); |
| 102 |
setTimeout(function() { |
| 103 |
initTooltip($scope, editorSettings); |
| 104 |
}, 100); |
| 105 |
} |
| 106 |
return; |
| 107 |
} |
| 108 |
$scope.removeData("ma-tooltip-retry"); |
| 109 |
var elementSettings = editorSettings || getElementSettings($scope), scopeId = $scope.data("id"), currentTooltipElement = null; |
| 110 |
if (!scopeId || typeof scopeId !== "string") return; |
| 111 |
try { |
| 112 |
currentTooltipElement = document.getElementById("jltma-tooltip-" + scopeId); |
| 113 |
if (!currentTooltipElement) { |
| 114 |
var $fallbackElement = $scope.find("#jltma-tooltip-" + scopeId); |
| 115 |
if ($fallbackElement && $fallbackElement.length > 0) currentTooltipElement = $fallbackElement[0]; |
| 116 |
} |
| 117 |
if (!currentTooltipElement || currentTooltipElement.nodeType !== 1) return; |
| 118 |
} catch (error) { |
| 119 |
return; |
| 120 |
} |
| 121 |
var tooltipText = elementSettings.ma_el_tooltip_text; |
| 122 |
if (!tooltipText || typeof tooltipText !== "string") return; |
| 123 |
var $jltma_el_tooltip_text = stripTags(tooltipText), $jltma_el_tooltip_direction = elementSettings.ma_el_tooltip_direction || "top", $jltma_tooltip_animation = elementSettings.jltma_tooltip_animation || "shift-away", $jltma_tooltip_arrow = elementSettings.jltma_tooltip_arrow !== false, $jltma_tooltip_duration = parseInt(elementSettings.jltma_tooltip_duration) || 300, $jltma_tooltip_delay = parseInt(elementSettings.jltma_tooltip_delay) || 300, $jltma_tooltip_trigger = elementSettings.jltma_tooltip_trigger || "mouseenter", $animateFill = elementSettings.jltma_tooltip_animation === "fill"; |
| 124 |
var $jltma_el_tooltip_text_width = 200; |
| 125 |
if (elementSettings.ma_el_tooltip_text_width && elementSettings.ma_el_tooltip_text_width.size) $jltma_el_tooltip_text_width = parseInt(elementSettings.ma_el_tooltip_text_width.size) || 200; |
| 126 |
if (currentTooltipElement._tippy) currentTooltipElement._tippy.destroy(); |
| 127 |
var appendToTarget = typeof elementorFrontend !== "undefined" && elementorFrontend.isEditMode() ? document.body : currentTooltipElement.parentNode || document.body; |
| 128 |
var tooltipConfig = { |
| 129 |
content: $jltma_el_tooltip_text, |
| 130 |
animation: $jltma_tooltip_animation, |
| 131 |
arrow: $jltma_tooltip_arrow, |
| 132 |
duration: [$jltma_tooltip_duration, $jltma_tooltip_delay], |
| 133 |
trigger: $jltma_tooltip_trigger, |
| 134 |
animateFill: $animateFill, |
| 135 |
flipOnUpdate: true, |
| 136 |
maxWidth: Math.max(50, Math.min(1e3, $jltma_el_tooltip_text_width)), |
| 137 |
zIndex: 999, |
| 138 |
allowHTML: false, |
| 139 |
theme: "jltma-tooltip-tippy-" + scopeId, |
| 140 |
interactive: true, |
| 141 |
hideOnClick: true, |
| 142 |
placement: $jltma_el_tooltip_direction, |
| 143 |
appendTo: appendToTarget |
| 144 |
}; |
| 145 |
if (elementSettings.jltma_tooltip_follow_cursor === "yes") tooltipConfig.followCursor = true; |
| 146 |
tippy(currentTooltipElement, tooltipConfig); |
| 147 |
}; |
| 148 |
var JLTMA_Tooltip = function($scope, $) { |
| 149 |
var scopeId = $scope.data("id"); |
| 150 |
if (scopeId) activeTooltipWidgets[scopeId] = $scope; |
| 151 |
initTooltip($scope); |
| 152 |
}; |
| 153 |
var editorHandlerRetries = 0; |
| 154 |
var setupEditorHandler = function() { |
| 155 |
if (typeof elementor === "undefined" || !elementor.channels || !elementor.channels.editor) { |
| 156 |
if (editorHandlerRetries < 10) { |
| 157 |
editorHandlerRetries++; |
| 158 |
setTimeout(setupEditorHandler, 500); |
| 159 |
} |
| 160 |
return; |
| 161 |
} |
| 162 |
elementor.channels.editor.on("change", function(view) { |
| 163 |
var model = view.model; |
| 164 |
if (model.get("widgetType") !== "ma-tooltip") return; |
| 165 |
var $scope = activeTooltipWidgets[model.get("id")]; |
| 166 |
if ($scope && $scope.length) { |
| 167 |
var settings = model.get("settings"); |
| 168 |
var liveSettings = settings ? settings.toJSON() : {}; |
| 169 |
clearTimeout($scope.data("tooltip-update-timer")); |
| 170 |
$scope.data("tooltip-update-timer", setTimeout(function() { |
| 171 |
initTooltip($scope, liveSettings); |
| 172 |
}, 100)); |
| 173 |
} |
| 174 |
}); |
| 175 |
}; |
| 176 |
$(window).on("elementor/frontend/init", function() { |
| 177 |
elementorFrontend.hooks.addAction("frontend/element_ready/ma-tooltip.default", JLTMA_Tooltip); |
| 178 |
if (typeof elementorFrontend !== "undefined" && elementorFrontend.isEditMode()) setupEditorHandler(); |
| 179 |
}); |
| 180 |
})(jQuery, window.elementorFrontend); |
| 181 |
/** |
| 182 |
* End tooltip widget script |
| 183 |
*/ |
| 184 |
//#endregion |
| 185 |
})(); |
| 186 |
|