-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
99 lines (96 loc) · 3.57 KB
/
index.php
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
<?php
class group {
public $name;
public $val;
function __construct($c) {
$this->name = $c;
$this->val = array();
}
}
$alphas = range('a','z');
array_unshift($alphas, '#');
$alphaGroups = array();
foreach ($alphas as $t) {
$temp = new group($t);
array_push($alphaGroups, $temp);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<title>Projects</title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
</head>
<body>
<div id="mainContainer">
<div id="items">
<?php
$dirs = array_filter(glob('*'), 'is_dir');
natcasesort($dirs);
foreach ($dirs as $i => $f) {
if (ctype_alpha(substr($f,0,1))) {
array_push($alphaGroups[array_search(strtolower(substr($f,0,1)), $alphas)]->val, $f);
} else {
array_push($alphaGroups[0]->val, $f);
}
}
foreach ($alphaGroups as $i => $g) {
if (sizeof($g->val)) {
$projectLength = sizeof($g->val);
echo '<div id="agl-' . $g->name . '" class="alphaGroupLabel">' . $g->name . '<span class="alphaGroupCount">' . $projectLength;
switch ($projectLength) {
case 1:
echo ' project</span></div>';
break;
default:
echo ' projects</span></div>';
break;
}
echo '<div class="alphaGroupContents">';
foreach ($g->val as $v) {
$url = parse_url($_SERVER['REQUEST_URI'])['path'] . $v;
echo '<a href="'.$url .'" id="item-'.$i.'" class="item">'.$v.'</a>';
}
echo '</div>';
}
}
?>
</div>
</div>
<footer>
<span>Directory Viewer <span class="version">v1.1</span></span>
<span class="copy">© <?php echo date("Y"); ?> <a href="https://www.scardino.dev">Nick Scardino</a></span>
</footer>
<script>
const el = document.getElementsByClassName("alphaGroupLabel");
document.getElementById(el[0].id).classList.add('sticky');
let currentGroup = 0;
window.addEventListener('scroll', function() {
if (window.pageYOffset >= document.getElementById(el[currentGroup + 1].id).offsetTop + el[0].offsetHeight) {
currentGroup++;
document.getElementsByClassName("sticky")[0].classList.remove('sticky');
document.getElementById(el[currentGroup].id).classList.add('sticky');
} else if (currentGroup != 0 && window.pageYOffset < document.getElementsByClassName("alphaGroupContents")[currentGroup-1].offsetTop + document.getElementsByClassName("alphaGroupContents")[currentGroup-1].offsetHeight) {
currentGroup--;
document.getElementsByClassName("sticky")[0].classList.remove('sticky');
document.getElementById(el[currentGroup].id).classList.add('sticky');
}
});
window.addEventListener('keyup', function(e) {
if (document.getElementById("agl-" + e.key) && e.key != '#') {
window.scrollTo({
top: document.getElementById("agl-" + e.key).offsetTop + document.getElementById("agl-" + e.key).offsetHeight,
behavior: "smooth"
});
} else if ((!isNaN(parseFloat(e.key)) && isFinite(e.key)) || e.key == '#') {
window.scrollTo({
top: 0,
behavior: "smooth"
});
}
})
</script>
</body>
</html>