Skip to content

Commit

Permalink
Hiding the tooltip on scroll and showing the search page
Browse files Browse the repository at this point in the history
Signed-off-by: Hofi <hofione@gmail.com>
  • Loading branch information
HofiOne committed May 8, 2024
1 parent 1fa5bd3 commit cbef09f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 30 deletions.
15 changes: 15 additions & 0 deletions _js/custom/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ $(function () {
const toolTipArrowSize = 10;
var tooltip = null;
var tooltipTarget = null;
var elementUnderCursor = null;
var shouldShowTooltip = false;
var showTimeoutFuncID;
var hideTimeoutFuncID;
Expand Down Expand Up @@ -469,6 +470,17 @@ $(function () {
shouldShowTooltip = true;
}
});

document.addEventListener('scroll', (event) => {
if (elementUnderCursor == null || shouldHideTooltip(elementUnderCursor)) {
if (tooltipTarget)
hideTooltip(true);
}
});

document.addEventListener("mouseover", function (event) {
elementUnderCursor = event.target;
});
}

// -------------
Expand Down Expand Up @@ -530,6 +542,9 @@ $(function () {
// set focus back to the initial content otherwise the focus will not get back to the search input once again
$(".initial-content").find("input").focus();
}

if (tooltipTarget)
hideTooltip(true);
}

$(".search__toggle").on("click", toggleSearch);
Expand Down
72 changes: 42 additions & 30 deletions _js/main.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -8489,15 +8489,6 @@ $(function() {
}
}
}
function finalizeContent(anchorId) {
adjustSidebars();
updateNavLinks();
addPageAnchors();
addTOCScrolling();
if (ClipboardJS.isSupported()) addCodeBlocksTitle();
addContentTooltips();
if (anchorId) scrollToAnchor(anchorId);
}
function loadContentFromUrl(url, onSuccess, onError) {
fetch(url).then(response => {
if (false == response.ok) {
Expand Down Expand Up @@ -8530,6 +8521,15 @@ $(function() {
}
return anchorId;
}
function finalizeContent(anchorId) {
adjustSidebars();
updateNavLinks();
addPageAnchors();
addTOCScrolling();
if (ClipboardJS.isSupported()) addCodeBlocksTitle();
addContentTooltips();
if (anchorId) scrollToAnchor(anchorId);
}
function updateContentFromUrl(url) {
var currContent = document.querySelector(contentID);
loadContentFromUrl(url, newContent => {
Expand Down Expand Up @@ -8653,6 +8653,7 @@ $(function() {
const toolTipArrowSize = 10;
var tooltip = null;
var tooltipTarget = null;
var elementUnderCursor = null;
var shouldShowTooltip = false;
var showTimeoutFuncID;
var hideTimeoutFuncID;
Expand Down Expand Up @@ -8735,19 +8736,15 @@ $(function() {
shouldShowTooltip = true;
}
});
document.addEventListener("scroll", event => {
if (elementUnderCursor == null || shouldHideTooltip(elementUnderCursor)) {
if (tooltipTarget) hideTooltip(true);
}
});
document.addEventListener("mouseover", function(event) {
elementUnderCursor = event.target;
});
}
finalizeContent();
window.addEventListener("popstate", function() {
updateContentFromUrl(window.location.pathname);
});
});

$(function() {
lunr.tokenizer.separator = /[\s\-_]+/;
});

$(function() {
$("#main").fitVids();
var initiallySticky = $(".sidebar").hasClass("sticky");
var stickySideBar = function() {
var show = $(".author__urls-wrapper").find("button").length === 0 ? $(window).width() > 1024 : !$(".author__urls-wrapper").find("button").is(":visible");
Expand All @@ -8759,15 +8756,10 @@ $(function() {
$(".sidebar").removeClass("sticky");
}
};
stickySideBar();
$(window).resize(function() {
$(window).on("resize", function() {
stickySideBar();
});
$(".author__urls-wrapper").find("button").on("click", function() {
$(".author__urls").toggleClass("is--visible");
$(".author__urls-wrapper").find("button").toggleClass("open");
});
$(document).keyup(function(event) {
$(document).on("keyup", function(event) {
var searchHotkey = {
ctrlKey: true,
shiftKey: true,
Expand All @@ -8784,13 +8776,33 @@ $(function() {
$(".initial-content").toggleClass("is--hidden");
if ($(".initial-content").hasClass("is--hidden")) {
setTimeout(function() {
$(".search-content").find("input").focus();
}, 400);
var input = $(".search-content").find("input");
input.trigger("focus");
input.trigger("select");
}, 250);
} else {
$(".initial-content").find("input").focus();
}
if (tooltipTarget) hideTooltip(true);
}
$(".search__toggle").on("click", toggleSearch);
stickySideBar();
finalizeContent();
window.addEventListener("popstate", function() {
updateContentFromUrl(window.location.pathname);
});
});

$(function() {
lunr.tokenizer.separator = /[\s\-_]+/;
});

$(function() {
$("#main").fitVids();
$(".author__urls-wrapper").find("button").on("click", function() {
$(".author__urls").toggleClass("is--visible");
$(".author__urls-wrapper").find("button").toggleClass("open");
});
$("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif'],a[href$='.webp']").has("> img").addClass("image-popup");
$(".image-popup").magnificPopup({
type: "image",
Expand Down

0 comments on commit cbef09f

Please sign in to comment.