diff options
| Commit | f56ddb062197fc9ac3e8584a74452b02b1c7a682 (patch) | |
|---|---|---|
| Author | 2026-09-27 22:26:42 +0300 | |
| Committer | 2026-09-27 22:29:35 +0300 | |
| Files | b64ad40d8822d9a6060b3880d1276b7be8703650 /cgit.js | |
| cgit_theme-f56ddb062197fc9ac3e8584a74452b02b1c7a682.tar cgit_theme-f56ddb062197fc9ac3e8584a74452b02b1c7a682.tar.gz cgit_theme-f56ddb062197fc9ac3e8584a74452b02b1c7a682.zip | ||
| Parent | c310a5d0478aa171d6ed0dbaefb000d1f29f7b95 (diff) | |
feat!: Rework, following cgit fork modifications
1 files changed, 17 insertions, 81 deletions
| -rw-r--r-- | cgit.js | 98 |
@@ -1,88 +1,24 @@ -/* This does client-side modifications which should probably be implemented on - * HTML generation, inside cgit. But they aren't (shouldn't be) very heavy or - * slow, so it's probably ok. - */ - -// Proper device scaling -const viewport = document.createElement("meta"); -viewport.id = "viewport"; -viewport.name = "viewport"; -viewport.content = "width=device-width initial-scale=1"; -document.head.appendChild(viewport); - document.addEventListener("DOMContentLoaded", function(){ - // Edit file tree - const list = document.getElementsByClassName('list')[0] - - if (list !== undefined && list.summary === "tree listing") { - const table = list.children[0] - const rows = table.children + for (list of document.getElementsByClassName('list')) { + if (list.summary === "tree listing") { + const table = list.children[0] + const rows = table.children - // Reorder directories (and submodules) before files - var lastDir = 1 - for (let i = 1; i < rows.length; ++i) { - if (!rows[i].children[0].innerText.startsWith('-')) { - if (i > lastDir) { - table.insertBefore(rows[i], rows[lastDir]) - } - ++lastDir - } - } - - // Human-readable size format - for (const row of rows) { - if (row.children[2].classList.contains('ls-size')) { - let size = row.children[2].innerText - if (size < 1024) { - size += ' B' - } - else if (size < 1048576) { - size = (size / 1024).toFixed(1) + ' KiB' - } - else if (size < 1073741824) { - size = (size / 1048576).toFixed(1) + ' MiB' + // Reorder directories (and submodules) before files + // This is done here instead of during page generation for two reasons: + // 1. Implementing it in generation would be difficult, since the logic + // is done by a git function + // 2. It could be argued if your browser doesn't support javascript, + // navigation would be easier if everything is ordered normally + var lastDir = rows[1].getAttribute('summary') == '----------' ? 2 : 1 + for (let i = 1; i < rows.length; ++i) { + if (!rows[i].getAttribute('summary').startsWith('-')) { + if (i > lastDir) { + table.insertBefore(rows[i], rows[lastDir]) + } + ++lastDir } - else { - size = (size / 1073741824).toFixed(1) + ' GiB' - } - row.children[2].innerText = size } } } - - // Edit the tabs - const tabs = document.getElementsByClassName('tabs')[0].children[0].children[0].children[0] - - if (tabs !== undefined && tabs.children.length === 7) { - const about = tabs.children[0] - const summary = tabs.children[1] - const refs = tabs.children[2] - const log = tabs.children[3] - const tree = tabs.children[4] - const commit = tabs.children[5] - const diff = tabs.children[6] - - tabs.insertBefore(tree, refs) - tabs.insertBefore(log, refs) - - about.innerText = 'README' - summary.innerText = 'Summary' - tree.innerText = 'Files' - log.innerText = 'Commits' - } - else if (tabs !== undefined && tabs.children.length === 6) { - const summary = tabs.children[0] - const refs = tabs.children[1] - const log = tabs.children[2] - const tree = tabs.children[3] - const commit = tabs.children[4] - const diff = tabs.children[5] - - tabs.insertBefore(tree, refs) - tabs.insertBefore(log, refs) - - summary.innerText = 'Summary' - tree.innerText = 'Files' - log.innerText = 'Commits' - } }); |
