| 1 |
jQuery(document).ready(function ($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
$('body').on('click', '.easyel-wrapper-link', function (e) { |
| 5 |
const $el = $(this); |
| 6 |
const settings = $el.data('easyel-wrapper-link'); |
| 7 |
|
| 8 |
if (!settings || !settings.url) return; |
| 9 |
|
| 10 |
const url = settings.url.trim(); |
| 11 |
|
| 12 |
if (url.startsWith('#')) { |
| 13 |
e.preventDefault(); |
| 14 |
const target = $(url); |
| 15 |
if (target.length) { |
| 16 |
$('html, body').animate({ scrollTop: target.offset().top }, 600); |
| 17 |
} |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
if (url.startsWith('mailto:')) { |
| 22 |
window.open(url, '_self'); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
if (url.startsWith('tel:')) { |
| 27 |
window.open(url, '_self'); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
if (!/^https?:\/\//i.test(url)) return; |
| 32 |
|
| 33 |
e.preventDefault(); |
| 34 |
|
| 35 |
const linkId = 'easyel-wrapper-link-' + $el.data('id'); |
| 36 |
|
| 37 |
if ($('#' + linkId).length === 0) { |
| 38 |
$('<a/>', { |
| 39 |
id: linkId, |
| 40 |
href: url, |
| 41 |
target: settings.is_external ? '_blank' : '_self', |
| 42 |
rel: settings.is_external ? 'noopener noreferrer' : '', |
| 43 |
class: 'easyel-hidden-link' |
| 44 |
}).appendTo('body'); |
| 45 |
} |
| 46 |
|
| 47 |
document.getElementById(linkId).click(); |
| 48 |
}); |
| 49 |
}); |
| 50 |
|