Skip to content

Commit 6788bdf

Browse files
authored
Fixing detection of the targeted url in navigation click handler (#4)
Signed-off-by: Hofi <hofione@gmail.com>
2 parents 0c3891a + ad98079 commit 6788bdf

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

_js/custom/navigation.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ $(function () {
190190
// Function to handle link clicks
191191
function handleNavLinkClick(event) {
192192
if (!event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {
193-
193+
var updated = false;
194194
// Get the relative URL value and update the browser URL
195195
// Use originalTarget or explicitTarget to get the correct one even for clicks from the tooltips
196196
var anchorElement = event.originalTarget.closest('a');
@@ -201,25 +201,25 @@ $(function () {
201201
// Try to load into the inner content frame only if the collection has not changed
202202
// Otherwise let the original click flow take effect, as the nav bar must be reloaded too
203203
// for a different collection
204-
if (sameCollection(url, window.location)) {
204+
if (url.origin == window.location.origin && sameCollection(url, window.location)) {
205205
// Prevent default navigation behavior, we will use our content load method
206206
event.preventDefault();
207207

208208
var urlStr = url.pathname + url.hash;
209-
var changed = (urlStr != window.location.pathname + window.location.hash);
209+
updated = (urlStr != window.location.pathname + window.location.hash);
210210

211211
// Update the browser URL
212212
history.pushState(null, null, url);
213213

214214
// Load content based on the updated relative URL
215215
// but only if the url has changed
216-
if (changed)
216+
if (updated)
217217
updateContentFromUrl(url);
218218
}
219219
// Clear focus from the clicked element, as we have other visualization for the selected items
220220
event.target.blur();
221221
}
222-
else
222+
if (false == updated)
223223
console.debug("Different collection item requested, loading full page...")
224224
}
225225
}
@@ -342,7 +342,7 @@ $(function () {
342342
var hideTimeoutFuncID;
343343

344344
function getTooltipPos(event, tooltipTarget) {
345-
const mouseX = event.clientX;
345+
const mouseX = event.clientX;
346346
const rect = tooltipTarget.getBoundingClientRect();
347347
var computedStyle = window.getComputedStyle(tooltipTarget);
348348
var lineHeight = parseFloat(computedStyle.getPropertyValue('line-height'));
@@ -361,13 +361,13 @@ $(function () {
361361
var newPosition = position + 'px';
362362
tooltip.style.setProperty(posName, newPosition);
363363
}
364-
364+
365365
function showTooltip(event, tooltipText) {
366366
tooltip.innerHTML = tooltipText.innerHTML;
367367

368368
var tooltipPos = getTooltipPos(event, tooltipTarget)
369369
var tooltipArrowLeftShift = 2 * toolTipArrowSize;
370-
370+
371371
setArrowPosition('--tooltip-arrow-top', -1 * toolTipArrowSize);
372372
setArrowPosition('--tooltip-arrow-left', tooltipArrowLeftShift + toolTipArrowSize / 2);
373373

@@ -393,14 +393,14 @@ $(function () {
393393
function shouldHideTooltip(activeTarget) {
394394
return ((tooltipTarget == null || activeTarget != tooltipTarget) && (tooltip == null || (activeTarget != tooltip && activeTarget.closest('.tooltip') == null)));
395395
}
396-
396+
397397
function hideTooltip(withDelay) {
398398
function doHideTooltip() {
399399
if (false == shouldShowTooltip && tooltip)
400400
tooltip.classList.remove('visible');
401401
tooltipTarget = null;
402402
}
403-
403+
404404
shouldShowTooltip = false;
405405

406406
if (withDelay) {

_js/main.min.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -8565,18 +8565,20 @@ $(function() {
85658565
}
85668566
function handleNavLinkClick(event) {
85678567
if (!event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {
8568+
var updated = false;
85688569
var anchorElement = event.originalTarget.closest("a");
85698570
if (anchorElement) {
85708571
var url = new URL(anchorElement.href);
8571-
if (sameCollection(url, window.location)) {
8572+
if (url.origin == window.location.origin && sameCollection(url, window.location)) {
85728573
event.preventDefault();
85738574
var urlStr = url.pathname + url.hash;
8574-
var changed = urlStr != window.location.pathname + window.location.hash;
8575+
updated = urlStr != window.location.pathname + window.location.hash;
85758576
history.pushState(null, null, url);
8576-
if (changed) updateContentFromUrl(url);
8577+
if (updated) updateContentFromUrl(url);
85778578
}
85788579
event.target.blur();
8579-
} else console.debug("Different collection item requested, loading full page...");
8580+
}
8581+
if (false == updated) console.debug("Different collection item requested, loading full page...");
85808582
}
85818583
}
85828584
function updateNavLinks(event) {

0 commit comments

Comments
 (0)