| 1 |
jQuery(document).ready(function ($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
let touchStartY = 0; |
| 5 |
let touchMoved = false; |
| 6 |
|
| 7 |
$('body') |
| 8 |
.on('touchstart', '.easyel-wrapper-link', function (e) { |
| 9 |
touchStartY = e.originalEvent.touches[0].clientY; |
| 10 |
touchMoved = false; |
| 11 |
}) |
| 12 |
.on('touchmove', '.easyel-wrapper-link', function (e) { |
| 13 |
const currentY = e.originalEvent.touches[0].clientY; |
| 14 |
if (Math.abs(currentY - touchStartY) > 10) { |
| 15 |
touchMoved = true; |
| 16 |
} |
| 17 |
}) |
| 18 |
.on('touchend click', '.easyel-wrapper-link', function (e) { |
| 19 |
if (touchMoved) { |
| 20 |
// Scroll |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
const $el = $(this); |
| 25 |
const settings = $el.data('easyel-wrapper-link'); |
| 26 |
|
| 27 |
if (!settings || !settings.url) return; |
| 28 |
|
| 29 |
const url = settings.url.trim(); |
| 30 |
|
| 31 |
// Anchor scroll |
| 32 |
if (url.startsWith('#')) { |
| 33 |
e.preventDefault(); |
| 34 |
const target = $(url); |
| 35 |
if (target.length) { |
| 36 |
$('html, body').animate( |
| 37 |
{ scrollTop: target.offset().top }, |
| 38 |
600 |
| 39 |
); |
| 40 |
} |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
// Mail / Tel |
| 45 |
if (url.startsWith('mailto:') || url.startsWith('tel:')) { |
| 46 |
window.location.href = url; |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if (!/^https?:\/\//i.test(url)) return; |
| 51 |
|
| 52 |
e.preventDefault(); |
| 53 |
|
| 54 |
if (settings.is_external) { |
| 55 |
window.open(url, '_blank', 'noopener,noreferrer'); |
| 56 |
} else { |
| 57 |
window.location.href = url; |
| 58 |
} |
| 59 |
}); |
| 60 |
}); |