Skip to content

Commit 0ea38db

Browse files
authored
Further fixes of still having focus and navigation issues (#54)
- Added a common selection clear function - Search results clicking now triggers the same flow that other links we do have already
2 parents a309968 + 5cab796 commit 0ea38db

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed

_includes/globals.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
};
5353
}
5454

55+
function clearFocus() {
56+
if (document.activeElement instanceof HTMLElement)
57+
document.activeElement.blur();
58+
}
59+
5560
function getElementPositionRelativeToRoot(element) {
5661
var rect = element.getBoundingClientRect();
5762

_js/custom/navigation.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ $(function () {
149149
if (anchorId)
150150
scrollToAnchor(anchorId);
151151
// Clear any focus (e.g back navigation keeps the previously clicked link focused)
152-
window.trigger('blur');
152+
clearFocus();
153+
// Forcibly hide the search content that can remain open in certain back and force navigation cases
154+
hideSearch();
153155
}
154156

155157
function updateContentFromUrl(url) {
@@ -248,8 +250,9 @@ $(function () {
248250
// Clear focus from the clicked element, as we have other visualization for the selected items
249251
event.target.blur();
250252
}
251-
if (false == updated)
253+
if (false == updated) {
252254
console.debug("Different collection item or new tab/page requested, loading full page...")
255+
}
253256
}
254257
}
255258

@@ -779,15 +782,21 @@ $(function () {
779782
input.trigger("select");
780783
}, 100);
781784
}
782-
else {
783-
// set focus back via the initial content otherwise the focus will not get back to the search input once again
784-
$(".initial-content").find("input").focus();
785-
}
785+
// else {
786+
// // set focus back via the initial content otherwise the focus will not get back to the search input once again
787+
// $(".initial-content").find("input").focus();
788+
// }
786789

787790
if (tooltipTarget)
788791
hideTooltip(true);
789-
// NOTE: event.target is not always the toggle here, use it directly instead of the event
790-
$("#search-button").trigger('blur');
792+
793+
clearFocus();
794+
}
795+
796+
function hideSearch() {
797+
$(".search-content").removeClass("is--visible");
798+
$(".search-content__form").removeClass("is--visible");
799+
$(".initial-content").removeClass("is--hidden");
791800
}
792801

793802
$("#search-button").on('click', toggleSearch);
@@ -803,9 +812,17 @@ $(function () {
803812
// (e.g. when an inner embedded page link is opened directly in a new tab, not via the internal navigational links)
804813
finalizeContent();
805814

815+
hideSearch();
816+
806817
// Listen for popstate events and update content accordingly
807818
window.addEventListener('popstate', function () {
808819
updateContentFromUrl(window.location.pathname);
809820
});
810821

822+
window.searchResultLinkClickHandler = function (event) {
823+
// Clicking a link that url is shown in the active page will not trigger anything
824+
// just show the actual pag, hide the search panel
825+
hideSearch();
826+
handleNavLinkClick(event);
827+
};
811828
});

_js/lunr/lunr-en.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $(document).ready(function() {
8181
'<div class="list__item">' +
8282
'<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">' +
8383
'<h2 class="archive__item-title" itemprop="headline">' +
84-
'<a href="' + removeExtension(tore[ref].url) + '" rel="permalink">' + store[ref].title + '</a>' +
84+
'<a href="' + removeExtension(tore[ref].url) + '" onclick="searchResultLinkClickHandler(event)" rel="permalink">' + store[ref].title + '</a>' +
8585
'</h2>' +
8686
'<div class="archive__item-teaser">' +
8787
'<img src="' + store[ref].teaser + '" alt="">' +
@@ -95,7 +95,7 @@ $(document).ready(function() {
9595
'<div class="list__item">' +
9696
'<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">' +
9797
'<h2 class="archive__item-title" itemprop="headline">' +
98-
'<a href="' + removeExtension(store[ref].url) + '" rel="permalink">' + store[ref].title + '</a>' +
98+
'<a href="' + removeExtension(store[ref].url) + '" onclick="searchResultLinkClickHandler(event)" rel="permalink">' + store[ref].title + '</a>' +
9999
'</h2>' +
100100
'<p class="archive__item-excerpt" itemprop="description">' + store[ref].excerpt.split(" ").splice(0, 20).join(" ") + '...</p>' +
101101
'</article>' +

_js/main.min.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8539,7 +8539,8 @@ $(function() {
85398539
if (ClipboardJS.isSupported()) addCodeBlocksTitle();
85408540
addContentTooltips();
85418541
if (anchorId) scrollToAnchor(anchorId);
8542-
window.trigger("blur");
8542+
clearFocus();
8543+
hideSearch();
85438544
}
85448545
function updateContentFromUrl(url) {
85458546
var currContent = document.querySelector(contentID);
@@ -8593,7 +8594,9 @@ $(function() {
85938594
}
85948595
event.target.blur();
85958596
}
8596-
if (false == updated) console.debug("Different collection item or new tab/page requested, loading full page...");
8597+
if (false == updated) {
8598+
console.debug("Different collection item or new tab/page requested, loading full page...");
8599+
}
85978600
}
85988601
}
85998602
function updateNavLinks(event) {
@@ -8921,19 +8924,27 @@ $(function() {
89218924
input.trigger("focus");
89228925
input.trigger("select");
89238926
}, 100);
8924-
} else {
8925-
$(".initial-content").find("input").focus();
89268927
}
89278928
if (tooltipTarget) hideTooltip(true);
8928-
$("#search-button").trigger("blur");
8929+
clearFocus();
8930+
}
8931+
function hideSearch() {
8932+
$(".search-content").removeClass("is--visible");
8933+
$(".search-content__form").removeClass("is--visible");
8934+
$(".initial-content").removeClass("is--hidden");
89298935
}
89308936
$("#search-button").on("click", toggleSearch);
89318937
}
89328938
stickySideBar();
89338939
finalizeContent();
8940+
hideSearch();
89348941
window.addEventListener("popstate", function() {
89358942
updateContentFromUrl(window.location.pathname);
89368943
});
8944+
window.searchResultLinkClickHandler = function(event) {
8945+
hideSearch();
8946+
handleNavLinkClick(event);
8947+
};
89378948
});
89388949

89398950
$(function() {

0 commit comments

Comments
 (0)