Skip to content

Commit c02ee98

Browse files
committed
Preparation in js scripts of adding skin switching on UI
- docRot and cookie handling is moded to the new skin hanling part Signed-off-by: Hofi <hofione@gmail.com>
1 parent 26ae5c1 commit c02ee98

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed

_js/custom/navigation.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
========================================================================== */
44

55
$(function () {
6-
// FIXME: How to get the real base URL (without using Liquid and Front Matter) ?!?!
7-
const docRoot = '';
86
const notFoundPageName = '404.html';
97
const contentID = 'article';
108

@@ -175,7 +173,7 @@ $(function () {
175173
error => {
176174
if (error == "Error: 404") {
177175
var baseURL = window.location.origin;
178-
var notFoundURL = baseURL + '/' + (docRoot != '' ? docRoot + '/' : '') + notFoundPageName;
176+
var notFoundURL = baseURL + '/' + docPrefix() + notFoundPageName;
179177

180178
updateContentFromUrl(notFoundURL);
181179
}
@@ -467,7 +465,7 @@ $(function () {
467465
}
468466

469467
function shouldHideTooltip(activeTarget) {
470-
return ((tooltipTarget == null || activeTarget != tooltipTarget) && (tooltip == null || (activeTarget != tooltip && activeTarget.closest('.tooltip') == null)));
468+
return ((tooltipTarget == null || activeTarget != tooltipTarget) && (tooltip == null || (activeTarget != tooltip && activeTarget != null && activeTarget.closest('.tooltip') == null)));
471469
}
472470

473471
function hideTooltip(withDelay) {
@@ -563,7 +561,7 @@ $(function () {
563561
}
564562
});
565563

566-
document.addEventListener("mouseover", function (event) {
564+
document.addEventListener('mouseover', function (event) {
567565
elementUnderCursor = event.target;
568566
});
569567

@@ -601,7 +599,7 @@ $(function () {
601599
// -------------
602600

603601
// Close search screen with Esc key or toggle with predefined hotKey
604-
$(document).on("keyup", function (event) {
602+
$(document).on('keyup', function (event) {
605603
// Define the desired hotkey (in this case, Ctrl + Shift + F)
606604
var searchHotkey = { ctrlKey: true, shiftKey: true, key: 'F' };
607605

@@ -637,7 +635,7 @@ $(function () {
637635
hideTooltip(true);
638636
}
639637

640-
$(".search__toggle").on("click", toggleSearch);
638+
$(".search__toggle").on('click', toggleSearch);
641639

642640
// -------------
643641
// Startup

_js/lunr/lunr-en.js

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,6 @@ function removeExtension(url) {
3030
return url; // If no extension found, return the original URL
3131
}
3232

33-
// Function to set a cookie
34-
function setCookie(name, value, days) {
35-
var expires = "";
36-
if (days) {
37-
var date = new Date();
38-
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
39-
expires = "; expires=" + date.toUTCString();
40-
}
41-
document.cookie = name + "=" + (value || "") + expires + "; path=/; SameSite=Strict";
42-
}
43-
44-
// Function to get a cookie value
45-
function getCookie(name) {
46-
var nameEQ = name + "=";
47-
var ca = document.cookie.split(';');
48-
for (var i = 0; i < ca.length; i++) {
49-
var c = ca[i];
50-
while (c.charAt(0) == ' ') {
51-
c = c.substring(1, c.length);
52-
}
53-
if (c.indexOf(nameEQ) == 0) {
54-
return c.substring(nameEQ.length, c.length);
55-
}
56-
}
57-
return null;
58-
}
59-
60-
61-
6233
$(document).ready(function() {
6334

6435
// Function to restore input field value from cookie
@@ -74,7 +45,7 @@ $(document).ready(function() {
7445
// Function to save input field value to cookie
7546
function saveInputValue() {
7647
var searchInput = document.getElementById('search');
77-
setCookie('search', searchInput.value, 365);
48+
setCookie('search', searchInput.value, 365*100);
7849
}
7950

8051
function onKeyUp() {

_js/main.min.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8453,7 +8453,6 @@ $(function() {
84538453
});
84548454

84558455
$(function() {
8456-
const docRoot = "";
84578456
const notFoundPageName = "404.html";
84588457
const contentID = "article";
84598458
function trimCharFromString(str, char) {
@@ -8553,7 +8552,7 @@ $(function() {
85538552
}, error => {
85548553
if (error == "Error: 404") {
85558554
var baseURL = window.location.origin;
8556-
var notFoundURL = baseURL + "/" + (docRoot != "" ? docRoot + "/" : "") + notFoundPageName;
8555+
var notFoundURL = baseURL + "/" + docPrefix() + notFoundPageName;
85578556
updateContentFromUrl(notFoundURL);
85588557
} else {
85598558
currContent.innerHTML = "<h3>Sorry, there was a problem loading the content!</h3>(" + error + ")";
@@ -8724,7 +8723,7 @@ $(function() {
87248723
}, 100);
87258724
}
87268725
function shouldHideTooltip(activeTarget) {
8727-
return (tooltipTarget == null || activeTarget != tooltipTarget) && (tooltip == null || activeTarget != tooltip && activeTarget.closest(".tooltip") == null);
8726+
return (tooltipTarget == null || activeTarget != tooltipTarget) && (tooltip == null || activeTarget != tooltip && activeTarget != null && activeTarget.closest(".tooltip") == null);
87288727
}
87298728
function hideTooltip(withDelay) {
87308729
function doHideTooltip() {

0 commit comments

Comments
 (0)