Skip to content

Commit

Permalink
feat Site: Add progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
prplwtf committed May 25, 2024
1 parent 494d5ab commit df8e643
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 7 deletions.
8 changes: 8 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ProgressBarElement {
border-top: 4px var(--bs-danger) solid;
position: fixed;
left: 0;
top: 0;
transition: width .4s, left 1s;
z-index: 5;
}
2 changes: 1 addition & 1 deletion configuration/Configuration.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Application:
Title: "Gravity"
Title: "gravity"
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Scripts and stylesheets -->
<link href="./assets/style.css" rel="stylesheet">
<link href="./vendor/css/materialstyle.min.css" rel="stylesheet">
<link href="./vendor/css/bootstrap-icons.min.css" rel="stylesheet">
<script src="./vendor/js/materialstyle.min.js"></script>
Expand All @@ -20,13 +21,16 @@
<script src="./src/App.js"></script>
<script src="./src/imports/ImportElements.js"></script>
<script src="./src/imports/ImportConfigurations.js"></script>
<script src="./src/router/ProgressBar.js"></script>
<script src="./src/router/Route.js"></script>
<script src="./src/router/Import.js"></script>
<script src="./src/router/Unload.js"></script>

</head>
<body>

<div id="ProgressBarElement" style="width: 0%"></div>

<div class="container py-5">
<div id="App"></div>
</div>
Expand Down
9 changes: 5 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
document.addEventListener("DOMContentLoaded", (async () => {
// Register global variables
App = document.getElementById("App")
AppTitle = document.getElementById("AppTitle")
var App = document.getElementById("App")
var AppTitle = document.getElementById("AppTitle")
var ProgressBarElement = document.getElementById("ProgressBarElement")

// Import components
await ImportConfigurations()
await ImportElements()

// Navigate home
// Navigate
var interval = setInterval(function() {
if (typeof window.Configuration == 'undefined') return;
clearInterval(interval);

Route("")
Route(window.location.hash)
}, 10);
}))
4 changes: 3 additions & 1 deletion src/components/elements/NavigationBarElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function NavigationBarElement() {
if(window.location.hash != "#blog") {
ButtonClass = "btn-danger"
}

return `
<div class="row">
<div class="col-9">
Expand All @@ -11,8 +12,9 @@ function NavigationBarElement() {
</h3>
</div>
<div class="col-3">
<button class="btn ${ButtonClass} float-end" onclick="Route('#blog')">
<button type="button" class="btn ${ButtonClass} float-end rounded-5" onclick="Route('#blog')">
Blogs
<span class="ripple-surface"></span>
</button>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/sections/BlogSection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function BlogSection() {
ProgressBar(100)
return `
${NavigationBarElement()}
<p> blog section </p>
Expand Down
2 changes: 1 addition & 1 deletion src/imports/ImportElements.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
async function ImportElements() {
const Elements = [
{ Identifier: "NavigationBarElement", Path: "NavigationBarElement.js" }
{ Identifier: "NavigationBarElement", Path: "NavigationBarElement.js" },
]

for (let i = Elements.length - 1; i >= 0; i--) {
Expand Down
25 changes: 25 additions & 0 deletions src/router/ProgressBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var IsAnimating = false

function ProgressBar(length) {
if(IsAnimating) return;

ProgressBarElement.style.opacity = 1
IsAnimating = true

if(length == 100) {
ProgressBarElement.style.width = length+"%"
ProgressBarElement.style.left = length+"%"
setTimeout(() => {
ProgressBarElement.style.opacity = 0
ProgressBarElement.style.width = 0
ProgressBarElement.style.left = 0
}, 1000);
setTimeout(() => {
IsAnimating = false
}, 2000)
return;
}

ProgressBarElement.style.width = length+"%"
IsAnimating = false
}
7 changes: 7 additions & 0 deletions src/router/Route.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
function Route(view) {
window.location.hash = view
Unload("Section")
ProgressBar(25)


// #
if(view == "" || view == "#") {
return Import("./src/components/sections/RootSection.js", "Section", function() {
App.innerHTML = `${RootSection()}`
ProgressBar(100)
})
}

// #blog
if(view == "#blog") {
return Import("./src/components/sections/BlogSection.js", "Section", function() {
App.innerHTML = `${BlogSection()}`
ProgressBar(100)
})
}

ProgressBar(100)
return App.innerHTML = `An unknown error occured, check your browser console for more information.`
}

Expand Down

0 comments on commit df8e643

Please sign in to comment.