Skip to content

Commit

Permalink
Added a common selection clear function
Browse files Browse the repository at this point in the history
Signed-off-by: Hofi <hofione@gmail.com>
  • Loading branch information
HofiOne committed May 22, 2024
1 parent a309968 commit 927342d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions _includes/globals.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
};
}

function clearFocus() {
if (document.activeElement instanceof HTMLElement)
document.activeElement.blur();
}

function getElementPositionRelativeToRoot(element) {
var rect = element.getBoundingClientRect();

Expand Down
9 changes: 6 additions & 3 deletions _js/custom/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ $(function () {
if (anchorId)
scrollToAnchor(anchorId);
// Clear any focus (e.g back navigation keeps the previously clicked link focused)
window.trigger('blur');
clearFocus();
}

function updateContentFromUrl(url) {
Expand Down Expand Up @@ -786,8 +786,8 @@ $(function () {

if (tooltipTarget)
hideTooltip(true);
// NOTE: event.target is not always the toggle here, use it directly instead of the event
$("#search-button").trigger('blur');

clearFocus();
}

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

if ($(".initial-content").hasClass("is--hidden"))
toggleSearch();

// Listen for popstate events and update content accordingly
window.addEventListener('popstate', function () {
updateContentFromUrl(window.location.pathname);
Expand Down
5 changes: 3 additions & 2 deletions _js/main.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -8539,7 +8539,7 @@ $(function() {
if (ClipboardJS.isSupported()) addCodeBlocksTitle();
addContentTooltips();
if (anchorId) scrollToAnchor(anchorId);
window.trigger("blur");
clearFocus();
}
function updateContentFromUrl(url) {
var currContent = document.querySelector(contentID);
Expand Down Expand Up @@ -8925,12 +8925,13 @@ $(function() {
$(".initial-content").find("input").focus();
}
if (tooltipTarget) hideTooltip(true);
$("#search-button").trigger("blur");
clearFocus();
}
$("#search-button").on("click", toggleSearch);
}
stickySideBar();
finalizeContent();
if ($(".initial-content").hasClass("is--hidden")) toggleSearch();
window.addEventListener("popstate", function() {
updateContentFromUrl(window.location.pathname);
});
Expand Down

0 comments on commit 927342d

Please sign in to comment.