-
Notifications
You must be signed in to change notification settings - Fork 5
/
docs.js
162 lines (155 loc) · 5.88 KB
/
docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function swapGif(sender) {
var src = sender.src
sender.src = sender.getAttribute('data-alt');
sender.setAttribute('data-alt', src);
}
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
function applyStyle(theme) {
const root = document.body;
switch (theme) {
case "Light theme":
root.style.setProperty("--scrollbar-background", "aliceblue");
root.style.setProperty("--scrollbar-color", "#a7b8c0");
root.style.setProperty("--body-background", "aliceblue");
root.style.setProperty("--docs-menu-background", "aliceblue");
root.style.setProperty("--docs-content-background", "white");
root.style.setProperty("--search-results-background", "white");
root.style.setProperty("--search-input-background", "aliceblue");
root.style.setProperty("--page-border-color", "lightgrey");
root.style.setProperty("--shadow-color", "#c0c1d2");
root.style.setProperty("--custom-link-color", "#007bff");
root.style.setProperty("--link-active-color", "#007bff");
root.style.setProperty("--text-color", "#24292e");
root.style.setProperty("--blur-background", "rgba(255, 255, 255, 0.2)");
root.style.setProperty("--blur-background-backdrop", "rgba(255, 255, 255, 0.95)");
break;
case "Dark theme":
root.style.setProperty("--scrollbar-background", "#2F3136");
root.style.setProperty("--scrollbar-color", "#202225");
root.style.setProperty("--body-background", "#2F3136");
root.style.setProperty("--docs-menu-background", "#2F3136");
root.style.setProperty("--docs-content-background", "#36393F");
root.style.setProperty("--search-results-background", "#36393F");
root.style.setProperty("--search-input-background", "#2F3136");
root.style.setProperty("--page-border-color", "#555555");
root.style.setProperty("--shadow-color", "#202225");
root.style.setProperty("--custom-link-color", "#3094ff");
root.style.setProperty("--link-active-color", "#3094ff");
root.style.setProperty("--text-color", "#DCDDDE");
root.style.setProperty("--blur-background", "rgba(54, 57, 63, 0.2)");
root.style.setProperty("--blur-background-backdrop", "rgba(54, 57, 63, 0.95)");
break;
}
}
document.addEventListener("DOMContentLoaded", function (event) {
var a = document.querySelector("a.active");
if(a !== null)
{
a.scrollIntoView(false);
}
var themeSelect = document.getElementById("theme-select");
var themeCookie = readCookie("mddocs-theme");
if (themeCookie !== null) {
themeSelect.value = themeCookie;
} else {
if (themeSelect.value !== null) {
themeSelect.value = "Light theme";
}
createCookie("mddocs-theme", themeSelect.value, 365);
}
applyStyle(themeSelect.value);
themeSelect.addEventListener("change", function () {
var theme = this.value;
createCookie("mddocs-theme", theme, 365);
applyStyle(theme);
var theme = readCookie("mddocs-theme") === "Dark theme" ? "dark" : "light";
applyBlogTimeline(twttr, theme);
});
document.addEventListener("click", function (e) {
var searchMenu = document.getElementById("menu-search-container");
if (searchMenu !== null && searchMenu !== undefined && !searchMenu.contains(e.target)) {
var searchResults = document.getElementById("search-results-container");
searchResults.style.display = "none";
}
}, false);
});
twttr.ready(function (twttr) {
var theme = readCookie("mddocs-theme") === "Dark theme" ? "dark" : "light";
applyBlogTimeline(twttr, theme);
});
function applyBlogTimeline(twttr, theme) {
var target = document.getElementById("blog-timeline");
if (target !== null && target !== undefined){
target.innerHTML = "";
twttr.widgets.createTimeline(
{
sourceType: "profile",
screenName: "CloudbackIt"
},
target,
{
id: 'profile:CloudbackIt',
theme: theme,
tweetLimit: 3,
chrome: "noheader, noborders, nofooter"
}
);
}
}
function onFocus(input) {
innerSearch(input);
}
function searchMenu(evt, input) {
var code = evt.charCode || evt.keyCode;
if (code === 27) {
input.value = "";//clear input on escape btn
}
innerSearch(input);
}
function innerSearch(input) {
var filter = input.value.toUpperCase();
var searchResults = document.getElementById("search-results-container");
if (filter.length >= 2) {
var items = searchResults.getElementsByClassName("search-result-item");
var foundResult = false;
for (var i = 0; i < items.length; i++) {
var s = items[i];
if (s.innerText.toUpperCase().indexOf(filter) > -1) {
s.style.display = "flex";
foundResult = true;
} else {
s.style.display = "none";
}
}
var nothingFound = document.getElementById("nothing-found");
if (!foundResult) {
nothingFound.style.display = "flex";
} else {
nothingFound.style.display = "none";
}
searchResults.style.display = "flex";
} else {
searchResults.style.display = "none";
}
}