-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython.html
More file actions
203 lines (190 loc) · 9.57 KB
/
Python.html
File metadata and controls
203 lines (190 loc) · 9.57 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./CSS/style.css">
<title>Python Kommando Huskeliste</title>
<link rel="icon" href="./Assets/Logo.png" type="image/png">
</head>
<body class="app-bg" aria-label="Python Kommando Huskeliste">
<nav aria-label="Tilbake til forsiden">
<a href="index.html" class="back-link" id="back-link">← Tilbake</a>
</nav>
<header>
<h1 id="page-title">Python Kommando Huskeliste</h1>
</header>
<main>
<section class="topbar" aria-label="Filtrering og søk">
<div class="topbar-left">
<label for="lib-select" style="font-weight:bold; color:rgb(41, 219, 219);">Velg bibliotek:</label>
<select id="lib-select">
<option value="alle">Alle</option>
<option value="standard">Standard</option>
<option value="Tkinter">tkinter</option>
<option value="Customtkinter">customtkinter</option>
<option value="os">os</option>
<option value="sys">sys</option>
<option value="math">math</option>
<option value="random">random</option>
<option value="requests">requests</option>
<option value="pandas">pandas</option>
<option value="numpy">numpy</option>
</select>
</div>
<div class="topbar-right">
<input type="text" id="search-input" placeholder="Søk etter Python..." class="search-input" style="display:none;" aria-label="Søk etter Python kommando">
<button id="search-icon" aria-label="Søk" class="search-icon-btn">
<span id="search-svg" class="search-svg">
<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</span>
</button>
</div>
</section>
<section id="categories-container" aria-label="Python kommando kategorier"></section>
</main>
<footer>
© TheFrostBunny | <a href="https://github.com/TheFrostBunny" target="_blank" rel="noopener" class="github-link">GitHub</a>
</footer>
<script src="/Javascript/script.js"></script>
<script>
fetch('./Resources/Python.json')
.then(response => response.json())
.then(data => {
const container = document.getElementById('categories-container');
const libSelect = document.getElementById('lib-select');
// Hjelpefunksjon for å finne bibliotek for en kategori eller kommando
function getCategoryLibrary(cat) {
// Matcher eksakt navn eller laverecased navn
const libs = ['os','sys','math','random','requests','pandas','numpy', "customtkinter", "tkinter"];
for (const lib of libs) {
if (cat.name && cat.name.toLowerCase() === lib) return lib;
}
return 'standard';
}
function renderCategories(selectedLib, searchText) {
container.innerHTML = '';
const search = (searchText || '').toLowerCase();
data.categories.forEach((cat, catIdx) => {
const catLib = getCategoryLibrary(cat);
if (selectedLib !== 'alle' && catLib !== selectedLib) return;
let commands = cat.commands;
if (search) {
commands = commands.filter(cmd =>
(cmd.syntax && cmd.syntax.toLowerCase().includes(search)) ||
(cmd.description && cmd.description.toLowerCase().includes(search)) ||
(cmd.details && cmd.details.join(' ').toLowerCase().includes(search)) ||
(cmd.example && cmd.example.toLowerCase().includes(search))
);
if (commands.length === 0 && !(cat.name && cat.name.toLowerCase().includes(search))) return;
}
const catDiv = document.createElement('div');
catDiv.className = 'category fade-in';
const catTitle = document.createElement('h2');
catTitle.id = `cat-${catIdx}-title`;
catTitle.textContent = cat.name;
catDiv.appendChild(catTitle);
commands.forEach((cmd, cmdIdx) => {
const cmdDiv = document.createElement('div');
cmdDiv.className = 'command';
const code = document.createElement('code');
code.id = `cmd-${catIdx}-${cmdIdx}-syntax`;
code.textContent = cmd.syntax;
cmdDiv.appendChild(code);
const desc = document.createElement('div');
desc.className = 'description';
desc.id = `cmd-${catIdx}-${cmdIdx}-desc`;
desc.textContent = cmd.description;
cmdDiv.appendChild(desc);
const detailsDiv = document.createElement('div');
detailsDiv.className = 'details';
const detailsTitle = document.createElement('h3');
detailsTitle.id = `cmd-${catIdx}-${cmdIdx}-details-title`;
detailsTitle.textContent = cmd.detailsTitle || 'Detaljert Forklaring';
detailsDiv.appendChild(detailsTitle);
const ul = document.createElement('ul');
ul.id = `cmd-${catIdx}-${cmdIdx}-details-list`;
(cmd.details || []).forEach(d => {
const li = document.createElement('li');
li.innerHTML = d;
ul.appendChild(li);
});
detailsDiv.appendChild(ul);
const exampleTitle = document.createElement('h3');
exampleTitle.id = `cmd-${catIdx}-${cmdIdx}-example-title`;
exampleTitle.textContent = cmd.exampleTitle || 'Eksempel';
detailsDiv.appendChild(exampleTitle);
const pre = document.createElement('pre');
pre.id = `cmd-${catIdx}-${cmdIdx}-example`;
pre.textContent = cmd.example;
// Legg til kopi-knapp
const copyButton = document.createElement('button');
copyButton.className = 'copy-btn';
copyButton.textContent = 'Kopier';
copyButton.addEventListener('click', function(event) {
event.stopPropagation();
navigator.clipboard.writeText(cmd.example).then(function() {
copyButton.textContent = 'Kopiert!';
setTimeout(function() {
copyButton.textContent = 'Kopier';
}, 2000);
}).catch(function() {
copyButton.textContent = 'Feil!';
});
});
pre.insertBefore(copyButton, pre.firstChild);
detailsDiv.appendChild(pre);
if (cmd.note) {
const note = document.createElement('p');
note.id = `cmd-${catIdx}-${cmdIdx}-note`;
note.textContent = cmd.note;
detailsDiv.appendChild(note);
}
cmdDiv.appendChild(detailsDiv);
// Legg til klikk for å vise/skjule detaljer
cmdDiv.addEventListener('click', function(e) {
// Ikke lukk hvis man klikker på kopier-knapp
if (e.target.classList.contains('copy-btn')) return;
const details = cmdDiv.querySelector('.details');
if (details) {
details.classList.toggle('active');
// Lukk andre åpne detaljer
document.querySelectorAll('.details.active').forEach(otherDetails => {
if (otherDetails !== details) {
otherDetails.classList.remove('active');
}
});
}
});
catDiv.appendChild(cmdDiv);
});
container.appendChild(catDiv);
});
}
// Initielt vis alle
renderCategories('alle', '');
libSelect.addEventListener('change', function() {
renderCategories(libSelect.value, document.getElementById('search-input').value);
});
document.getElementById('search-input').addEventListener('input', function() {
renderCategories(libSelect.value, this.value);
});
const searchIcon = document.getElementById('search-icon');
const searchInput = document.getElementById('search-input');
searchIcon.addEventListener('click', function() {
if (searchInput.style.display === 'none') {
searchInput.style.display = 'block';
searchInput.focus();
} else {
searchInput.value = '';
searchInput.style.display = 'none';
renderCategories(libSelect.value, '');
}
});
});
</script>
</body>
</html>