| 1 |
jQuery(document).ready(function ($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function initWrapperLink($el) { |
| 5 |
// Avoid double init (Elementor may re-render in editor). |
| 6 |
if ($el.data('easyelWrapperLinkInit')) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
const settings = $el.data('easyel-wrapper-link'); |
| 11 |
if (!settings || !settings.url) { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
const url = String(settings.url).trim(); |
| 16 |
if (!url) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
$el.data('easyelWrapperLinkInit', true); |
| 21 |
|
| 22 |
// The wrapper needs to be a positioning context for the overlay. |
| 23 |
if ($el.css('position') === 'static') { |
| 24 |
$el.css('position', 'relative'); |
| 25 |
} |
| 26 |
|
| 27 |
// Build a real <a> overlay so the browser shows the URL in the |
| 28 |
// status bar on hover (like a normal anchor) and supports native |
| 29 |
// behaviours: ctrl/middle click to open in new tab, right-click |
| 30 |
// "Open link in new tab", copy link address, etc. |
| 31 |
const $overlay = $('<a>', { |
| 32 |
'class': 'easyel-wrapper-link-overlay', |
| 33 |
'href': url, |
| 34 |
'aria-label': url, |
| 35 |
'tabindex': '-1' |
| 36 |
}); |
| 37 |
|
| 38 |
const rel = []; |
| 39 |
if (settings.is_external) { |
| 40 |
$overlay.attr('target', '_blank'); |
| 41 |
rel.push('noopener', 'noreferrer'); |
| 42 |
} |
| 43 |
if (settings.nofollow) { |
| 44 |
rel.push('nofollow'); |
| 45 |
} |
| 46 |
if (rel.length) { |
| 47 |
$overlay.attr('rel', rel.join(' ')); |
| 48 |
} |
| 49 |
|
| 50 |
$overlay.css({ |
| 51 |
position: 'absolute', |
| 52 |
top: 0, |
| 53 |
left: 0, |
| 54 |
width: '100%', |
| 55 |
height: '100%', |
| 56 |
'z-index': 1, |
| 57 |
margin: 0, |
| 58 |
padding: 0, |
| 59 |
border: 0, |
| 60 |
background: 'transparent', |
| 61 |
'text-decoration': 'none', |
| 62 |
'font-size': 0, |
| 63 |
'line-height': 0 |
| 64 |
}); |
| 65 |
|
| 66 |
// Smooth scroll for anchor links, handled natively otherwise. |
| 67 |
if (url.startsWith('#')) { |
| 68 |
$overlay.on('click', function (e) { |
| 69 |
const target = $(url); |
| 70 |
if (target.length) { |
| 71 |
e.preventDefault(); |
| 72 |
$('html, body').animate( |
| 73 |
{ scrollTop: target.offset().top }, |
| 74 |
600 |
| 75 |
); |
| 76 |
} |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
$el.prepend($overlay); |
| 81 |
|
| 82 |
// Keep real interactive children (links, buttons, inputs) above the |
| 83 |
// overlay so they remain clickable on their own. |
| 84 |
$el.find('a, button, input, select, textarea, [role="button"], .elementor-button') |
| 85 |
.not('.easyel-wrapper-link-overlay') |
| 86 |
.each(function () { |
| 87 |
const $child = $(this); |
| 88 |
if ($child.css('position') === 'static') { |
| 89 |
$child.css('position', 'relative'); |
| 90 |
} |
| 91 |
$child.css('z-index', 2); |
| 92 |
}); |
| 93 |
} |
| 94 |
|
| 95 |
$('.easyel-wrapper-link').each(function () { |
| 96 |
initWrapperLink($(this)); |
| 97 |
}); |
| 98 |
|
| 99 |
// Re-init for widgets rendered after load (Elementor frontend / editor). |
| 100 |
if (window.elementorFrontend && elementorFrontend.hooks) { |
| 101 |
elementorFrontend.hooks.addAction('frontend/element_ready/global', function ($scope) { |
| 102 |
const $links = $scope.hasClass('easyel-wrapper-link') |
| 103 |
? $scope |
| 104 |
: $scope.find('.easyel-wrapper-link'); |
| 105 |
$links.each(function () { |
| 106 |
initWrapperLink($(this)); |
| 107 |
}); |
| 108 |
}); |
| 109 |
} |
| 110 |
}); |
| 111 |
|