Skip to content

Commit

Permalink
Add information modal
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenyDEV committed Aug 13, 2023
1 parent 7b2155b commit 6cff941
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 1 deletion.
25 changes: 25 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@

</head>
<body>
<div id="modal-1" class="modal">

<div class="modal-inner">
<a class="js-close-modal">&times;</a>
<div class="modal-content">

<h3>Information</h3>

<p id="settings-version"> Dynamic v#.#.# </p>
<div class="settings-connected">
<div class="connectedindicator">
</div>
<div id="service-status">service online</div>
</div>
</div><!-- .modal-content -->
</div><!-- .modal-inner -->

</div><!-- .modal -->


<canvas></canvas>
<h1> Dynamic </h1>
<form action="/service/route" method="POST" id="uform">
Expand All @@ -20,8 +39,14 @@ <h1> Dynamic </h1>
<div class="copyright"> Copyright Nebula Services 2023 </div>
</div>

<button class="js-modal" data-modal="modal-1">Information</button>

<script src="/resources/scripts/index.js"></script>
<script src="/resources/scripts/backdrop.js"></script>
<script src="/resources/scripts/notice.js"></script>
<script src="/resources/scripts/settings.js"></script>



</body>
</html>
1 change: 0 additions & 1 deletion static/resources/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function prependHttps(url) {
}

function isUrl(val = "") {
// Use a regular expression to check for a valid URL pattern
const urlPattern = /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/;
return urlPattern.test(val);
}
Expand Down
109 changes: 109 additions & 0 deletions static/resources/scripts/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
'use strict';
class Modal {

constructor() {
this.triggers = document.querySelectorAll('.js-modal');
this.close = document.querySelectorAll('.js-close-modal');
this.modals = document.querySelectorAll('.modal');
this.modalInners = document.querySelectorAll('.modal-inner');

this.listeners();
}

listeners() {
window.addEventListener('keydown', this.keyDown);

this.triggers.forEach(el => {
el.addEventListener('click', this.openModal, false);
});

this.modals.forEach(el => {
el.addEventListener('transitionend', this.revealModal, false);
el.addEventListener('click', this.backdropClose, false);
});

this.close.forEach(el => {
el.addEventListener('click', Modal.hideModal, false);
});

this.modalInners.forEach(el => {
el.addEventListener('transitionend', this.closeModal, false);
});
}

keyDown(e) {
if (27 === e.keyCode && document.body.classList.contains('modal-body')) {
Modal.hideModal();
}
}

backdropClose(el) {
if (!el.target.classList.contains('modal-visible')) {
return;
}

let backdrop = el.currentTarget.dataset.backdrop !== undefined ? el.currentTarget.dataset.backdrop : true;

if (backdrop === true) {
Modal.hideModal();
}
}

static hideModal() {
let modalOpen = document.querySelector('.modal.modal-visible');

modalOpen.querySelector('.modal-inner').classList.remove('modal-reveal');
document.querySelector('.modal-body').addEventListener('transitionend', Modal.modalBody, false);
document.body.classList.add('modal-fadeOut');
}

closeModal(el) {
if ('opacity' === el.propertyName && !el.target.classList.contains('modal-reveal')) {
document.querySelector('.modal.modal-visible').classList.remove('modal-visible');
}
}

openModal(el) {
if (!el.currentTarget.dataset.modal) {
console.error('No data-modal attribute defined!');
return;
}

let modalID = el.currentTarget.dataset.modal;
let modal = document.getElementById(modalID);

document.body.classList.add('modal-body');
modal.classList.add('modal-visible');
}

revealModal(el) {
if ('opacity' === el.propertyName && el.target.classList.contains('modal-visible')) {
el.target.querySelector('.modal-inner').classList.add('modal-reveal');
}
}

static modalBody(el) {
if ('opacity' === el.propertyName && el.target.classList.contains('modal') && !el.target.classList.contains('modal-visible')) {
document.body.classList.remove('modal-body', 'modal-fadeOut');
}
}}
new Modal();

window.addEventListener('DOMContentLoaded', function (){
console.log('buh')
const versionInd = document.getElementById('settings-version')
const xhr = new XMLHttpRequest();
xhr.open("GET", '/version');
xhr.send();
xhr.responseType = "json";
xhr.onload = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.response)
versionInd.innerText = `Dynamic v${xhr.response.version}`
} else {
versionInd.innerText = 'Unable to get version'
}
};

})

151 changes: 151 additions & 0 deletions static/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,155 @@ canvas {
height: 100%;
position: absolute;
z-index: -2;
}
@-webkit-keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@-webkit-keyframes fadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes fadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.modal-body {
overflow: hidden;
position: relative;
}
.modal-body:before {
position: fixed;
display: block;
content: "";
top: 0px;
bottom: 0px;
right: 0px;
left: 0px;
background-color: rgba(0, 0, 0, 0.75);
z-index: 10;
}
.modal-body:before {
-webkit-animation: fadeIn 320ms ease;
animation: fadeIn 320ms ease;
transition: opacity ease 320ms;
}
.modal-body.modal-fadeOut:before {
opacity: 0;
}

.modal {
transition: all ease 0.01s;
display: block;
opacity: 0;
height: 0;
position: fixed;
content: "";
top: 0;
left: 0;
right: 0;
z-index: 999;
text-align: center;
overflow: hidden;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.modal.modal-visible {
opacity: 1;
height: auto;
bottom: 0;
}

.modal-inner {
transition: all ease 320ms;
transform: translateY(-50px);
position: relative;
display: inline-block;
background-color: #1a1a1a;
width: 90%;
max-width: 625px;
opacity: 0;
margin: 40px 0;
border-radius: 4px;
box-shadow: 0 30px 18px -20px #020202;
}
.modal-inner.modal-reveal {
transform: translateY(0);
opacity: 1;
}

.js-close-modal {
transition: color 320ms ease;
color: #9e9e9e;
opacity: 0.75;
position: absolute;
z-index: 2;
right: 0px;
top: 0px;
width: 30px;
height: 30px;
line-height: 30px;
font-size: 20px;
cursor: pointer;
text-align: center;
}

.js-close-modal:hover {
color: #000;
}

#settings-version {
position: absolute;
left: 0;
bottom: 0;
margin-left: 11px;
margin-bottom: 5px;
color: #b4b4b482;
}
.settings-connected {
position: absolute;
right: 0;
bottom: 0;
margin-right: 13px;
margin-bottom: 5px;
color: #b4b4b482;
display: flex;
}

.connectedindicator {
width: 20px;
height: 20px;
background: #30ff30;
border-radius: 53px;
margin-right: 13px;
margin-top: 2px;
}

button {
position: absolute;
right: 4px;
top: 4px;
background: transparent;
border: transparent;
color: #ffffff30;
}

0 comments on commit 6cff941

Please sign in to comment.