Added a navigation at bottom with "Back" button in fullscreen

* Refactor all buttons with "noback" to support custom backgrounds
* Create calcCustomCss function that creates custom background-color hover colors automatically
* Other refactors
This commit is contained in:
Niko 2022-02-25 15:25:21 +01:00
parent e973da1aa8
commit 6bf5ee7fcd
12 changed files with 124 additions and 19 deletions

View File

@ -23,7 +23,7 @@
<header class="flex">
<div id="nav-container" class="flex center">
<div class="flex">
<div id="fedilove-icon" class="flex center icon button round">
<div id="fedilove-icon" class="flex center icon button noback round">
<a class="center" href="#">
<img class="fedilove-icon" src="/assets/images/icon-proto-1.png"/>
</a>
@ -47,7 +47,7 @@
</div>
</div>
<?php if ($actor !== null): ?>
<div class="flex icon button round">
<div class="flex icon button noback round">
<a class="center" href="javascript:app.navmenu.show()">
<img class="avatar round"
src="<?php echo htmlspecialchars($actor->icon) ?>"/>

View File

@ -6,7 +6,7 @@ $alt_s = false;
if ($id !== false)
$alt_s = 'alt_'.$id;
?>
<a class="component icon button <?php echo ($class ?? '') ?>"
<a class="component icon button noback <?php echo ($class ?? '') ?>"
<?php if ($id !== false): ?>
id="<?php echo $id ?>"
<?php endif ?>

View File

@ -33,4 +33,20 @@ $actor = $database->getActorByUsername($user->username);
</div>
</div>
<div id="nav-full" class="fixed-top size-max height-mobile" style="display:none">
<div class="panel nostyle flex size-max">
<div class="content center height-max">
<div id="buttons" class="content absolute-bottom">
<div style="display: flow-root; margin: 2em">
<div class="component button round floating right"
style="background-color: #db71ff"
onclick="window.history.back()">
<i class="fa fa-arrow-left fa-fw"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<?php tpl('app.footer') ?>

View File

@ -8,6 +8,9 @@ body.app.fullscreen {
body.app.fullscreen main {
margin: auto !important;
}
body.app.fullscreen #app-container {
margin-bottom: 8em !important;
}
.app header {
height: 4.5em;
}
@ -69,6 +72,19 @@ img.avatar {
filter: grayscale() !important;
}
.button.floating {
padding: 1.5em;
box-shadow: 0px 0px 1em #0000005e;
border: 1px solid #0000002e;
}
.button.floating .fa {
color: #fff !important;
font-size: 1.4em;
}
.button.floating.right {
float: right;
}
a.button {
text-decoration: none;
user-select: none;
@ -112,6 +128,15 @@ main {
#nav-chat .fa { color: #62c672 }
#nav-chat.active { background: linear-gradient(#62c6723b, transparent, transparent, transparent) }
#nav-full {
user-select: none;
pointer-events: none;
}
#nav-full #buttons .button {
user-select: auto;
pointer-events: all;
}
#app-container {
max-width: 60em;
width: 100%;
@ -125,6 +150,11 @@ main {
@media (max-width: 700px) {
.panel { margin-bottom: .4em !important }
}
.panel.nostyle {
padding: 0 !important;
background: none !important;
box-shadow: none !important;
}
.panel .content {
max-width: var(--content_max_width);
width: 100%;

View File

@ -11,11 +11,11 @@ body.app {
box-shadow: 0px 0px 5px #0000001c;
}
.button:not(.disabled,.light):hover {
.button.noback:not(.disabled,.light):hover {
background: #0000000a !important;
}
.button:not(.disabled,.light):active,
.button:not(.disabled,.light):focus {
.button.noback:not(.disabled,.light):active,
.button.noback:not(.disabled,.light):focus {
background: #00000024 !important;
}

View File

@ -251,6 +251,7 @@ app.fullscreen = {
el.classList.add('absolute-top');
el.classList.add('width-max');
document.querySelector('header').style.display = 'none';
document.querySelector('#nav-full').removeAttribute('style');
document.body.classList.add('fullscreen');
},
disable: function() {
@ -258,6 +259,7 @@ app.fullscreen = {
el.classList.remove('absolute-top');
el.classList.remove('width-max');
document.querySelector('header').removeAttribute('style');
document.querySelector('#nav-full').style.display = 'none';
document.body.classList.remove('fullscreen')
},
}

View File

@ -212,11 +212,14 @@ function hashredir(tohash, fallback) {
}
function printstack() { console.error(new Error().stack) }
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
function uuidv4(sep) {
sep = sep === undefined ? true : sep;
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
if (sep) return uuid;
return uuid.replaceAll('-','');
}
function getNormalizedURI() { return window.location.pathname.replace(/\/+?$/, '') }
@ -334,12 +337,66 @@ const http = {
},
};
function buildRGB(r, g, b) {
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
return `rgb(${r}, ${g}, ${b})`;
}
function parseRGB(string) {
if (string === undefined) return null;
var rgb = string.substr(string.indexOf('(')+1).trim();
rgb = rgb.substr(0, rgb.lastIndexOf(')')).trim();
rgb = rgb.split(',');
for (var i in rgb)
rgb[i] = parseInt(rgb[i]);
return rgb;
}
function calcHeightMobile() {
document.querySelectorAll('.height-mobile').forEach(function(node) {
node.style.height = `${window.innerHeight}px`;
});
}
window.addEventListener('load', function(e) { calcHeightMobile() });
function calcCustomCss() {
var dom = document.getElementById('custom-css');
if (dom === null) {
dom = document.createElement('style');
document.body.appendChild(dom);
}
dom.innerHTML = '';
const cssObjs = document.querySelectorAll('.button.component:not(.noback)');
for (var i = 0; i < cssObjs.length; i++) {
const id = 'cs-' + uuidv4(false).substr(0,16);
const obj = cssObjs[i];
obj.setAttribute('data-cs', id);
const rgb = parseRGB(obj.style['background-color']);
if (rgb === null) continue;
const colorH = buildRGB(rgb[0]-10, rgb[1]-10, rgb[2]-10);
const colorF = buildRGB(rgb[0]-25, rgb[1]-25, rgb[2]-25);
console.log(rgb);
const _css = `
*[data-cs="{id}"]:hover { background-color: {colorH} !important }
*[data-cs="{id}"]:active,
*[data-cs="{id}"]:focus { background-color: {colorF} !important }
`.replaceAll('{id}', id)
.replaceAll('{colorH}', colorH)
.replaceAll('{colorF}', colorF)
.trim();
dom.innerHTML += _css;
}
}
window.addEventListener('load', function(e) {
calcHeightMobile();
calcCustomCss();
});
window.addEventListener('resize', function(e) { calcHeightMobile() });
(function() {
if (window.cssprops !== undefined) {

View File

@ -1,4 +1,4 @@
<div class="card-item item button dark rounder" data-id="{._id}"
<div class="card-item item button noback dark rounder" data-id="{._id}"
onclick="app.pages.home.loadQuiz('{.id}')"
onEnter="app.pages.home.loadQuiz('{.id}')"
tabindex="0">

View File

@ -1,6 +1,6 @@
<div id="meet-actions" class="height-max flex">
<div class="flex center">
<a class="component icon button light round" title="{s:alt.nav_close}"
<a class="component icon button noback light round" title="{s:alt.nav_close}"
href="javascript:window.history.back()"
style="position: absolute; left: 0; margin-left: .5em;">
<div class="ic-container flex">
@ -8,28 +8,28 @@
</div>
</a>
<a id="meet-action-discard"
class="component icon button light round" title="{s:alt.nav_discard}"
class="component icon button noback light round" title="{s:alt.nav_discard}"
href="javascript:app.pages.meet.actions.discard()">
<div class="ic-container flex">
<i class="center fa fa-times-circle fa-fw"></i>
</div>
</a>
<a id="meet-action-crush"
class="component icon button light round" title="{s:alt.nav_crush}"
class="component icon button noback light round" title="{s:alt.nav_crush}"
href="javascript:app.pages.meet.actions.crush()">
<div class="ic-container flex">
<i class="center fa fa-heart fa-fw"></i>
</div>
</a>
<a id="meet-action-quiz"
class="component icon button light round" title="{s:alt.action_quiz}"
class="component icon button noback light round" title="{s:alt.action_quiz}"
href="javascript:app.pages.meet.actions.quiz()">
<div class="ic-container flex">
<i class="center fa fa-quote-right fa-fw"></i>
</div>
</a>
<a id="meet-action-maybe"
class="component icon button light round" title="{s:alt.nav_crush}"
class="component icon button noback light round" title="{s:alt.nav_crush}"
href="javascript:app.pages.meet.actions.maybe()">
<div class="ic-container flex">
<i class="center fa fa-question-circle fa-fw"></i>

View File

@ -5,7 +5,7 @@
<p>{s:app.meet_empty_p}</p>
<br>
<a id="be-first" href="#compose"
class="button light rounder"
class="button noback light rounder"
>{s:app.be_the_first}</a>
</div>
</div>

View File

@ -13,7 +13,7 @@
<div class="type-options">
<fieldset>
{loop:options}
<label class="card-item button rounder flex">
<label class="card-item button noback rounder flex">
<div class="center">
<input type="radio" name="question_{.index}"
value="{.item}">

View File

@ -1,6 +1,6 @@
<div class="confirm flex">
<a class="width-max text-center button rounder nope"
<a class="width-max text-center button noback rounder nope"
onclick="app.toast.dismiss('{.id}', event)">{.no_text}</a>
<a class="width-max text-center button rounder yes"
<a class="width-max text-center button noback rounder yes"
onclick="app.toast.accept('{.id}', event)">{.yes_text}</a>
</div>