improve mobile support

This commit is contained in:
torcado194 2022-03-23 21:59:31 -04:00
parent 87703ce35b
commit 06c540e053

View file

@ -36,8 +36,9 @@
/* basic layout */ /* basic layout */
html, body { html, body {
max-width: 960px;
width: 100%; width: 100%;
height: 100%;
overflow: auto;
} }
body { body {
@ -53,9 +54,12 @@
#mainContainer { #mainContainer {
position: relative; position: relative;
display: grid; display: grid;
grid-template-columns: auto auto;
justify-content: space-around; justify-content: space-around;
width: 100%; width: 100%;
max-width: 960px;
left: 0;
right: 0;
margin: auto;
margin-bottom: 40px; margin-bottom: 40px;
} }
@ -69,12 +73,18 @@
/*** title ***/ /*** title ***/
#titleContainer {
height: 0;
}
#titleContainer.active {
height: auto;
}
#title { #title {
margin: 20px 20px 4px 20px; margin: 20px 20px 4px 20px;
font-size: 26px; font-size: 26px;
display: none; display: none;
} }
#title.active { #titleContainer.active #title {
display: block; display: block;
} }
#mainContainer.vertical #title { #mainContainer.vertical #title {
@ -85,19 +95,22 @@
margin: 20px; margin: 20px;
text-align: center; text-align: center;
} }
#mainContainer.title-span #titleContainer { #mainContainer:not(.vertical).title-span #titleContainer {
grid-column: 1/3; grid-column: 1/3;
} }
/*** media column ***/ /*** media column ***/
#mediaColumn { #mediaColumn {
display: none;
grid-row: 1/3; grid-row: 1/3;
grid-column: 2; grid-column: 2;
display: flex;
flex-direction: column; flex-direction: column;
position: relative; position: relative;
} }
#mediaColumn.active {
display: flex;
}
#mainContainer.vertical #mediaColumn { #mainContainer.vertical #mediaColumn {
grid-row: 2; grid-row: 2;
grid-column: 1; grid-column: 1;
@ -301,6 +314,7 @@
font-size: 12px; font-size: 12px;
align-self: end; align-self: end;
color: var(--primaryAltTextColor); color: var(--primaryAltTextColor);
user-select: none;
} }
#controls #scrubberTrackContainer { #controls #scrubberTrackContainer {
@ -310,6 +324,7 @@
padding: 4px 0; padding: 4px 0;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
touch-action: none;
} }
#controls #scrubberTrack { #controls #scrubberTrack {
background-color: var(--primaryAltColor); background-color: var(--primaryAltColor);
@ -369,6 +384,7 @@
position: relative; position: relative;
align-self: start; align-self: start;
transition: width 0.2s; transition: width 0.2s;
touch-action: none;
} }
#controls #volumeContainer.hover #volumeTrackContainer { #controls #volumeContainer.hover #volumeTrackContainer {
width: 80px; width: 80px;
@ -610,12 +626,12 @@
<div class="riser"></div> <div class="riser"></div>
<div class="title">____</div> <div class="title">____</div>
<div class="time"></div> <div class="time"></div>
<div id="scrubberTrackContainer"> <button id="scrubberTrackContainer">
<div id="scrubberTrack"> <div id="scrubberTrack">
<div id="scrubberFill"></div> <div id="scrubberFill"></div>
</div> </div>
<div id="scrubber"></div> <div id="scrubber"></div>
</div> </button>
<button id="prevTrack" class="icon-previous"></button> <button id="prevTrack" class="icon-previous"></button>
<button id="nextTrack" class="icon-next"></button> <button id="nextTrack" class="icon-next"></button>
<div class="spacer"></div> <div class="spacer"></div>
@ -651,6 +667,7 @@
let prevTrackEl = document.getElementById('prevTrack'); let prevTrackEl = document.getElementById('prevTrack');
let titleEl = document.getElementById('title'); let titleEl = document.getElementById('title');
let titleContainerEl = document.getElementById('titleContainer');
let mediaColumnEl = document.getElementById('mediaColumn'); let mediaColumnEl = document.getElementById('mediaColumn');
let mediaContainerEl = document.getElementById('mediaContainer'); let mediaContainerEl = document.getElementById('mediaContainer');
let mediaInfoEl = document.getElementById('mediaInfo'); let mediaInfoEl = document.getElementById('mediaInfo');
@ -715,7 +732,7 @@
document.getElementById('audio').classList.remove('native'); document.getElementById('audio').classList.remove('native');
mediaVideoEl.removeAttribute('controls'); mediaVideoEl.removeAttribute('controls');
} }
mediaContainerEl.style.maxWidth = mediaContainerEl.style.maxHeight = theme.coverSize + 'px'; mediaContainerEl.style.maxWidth = theme.coverSize + 'px';
mediaColumnEl.style.maxWidth = theme.coverSize + 'px'; mediaColumnEl.style.maxWidth = theme.coverSize + 'px';
if(theme.customCSS !== undefined){ if(theme.customCSS !== undefined){
@ -728,16 +745,21 @@
} }
function loadContent(data){ function loadContent(data){
if(data.cover) loadCover(data.cover); if(data.cover){
mediaColumnEl.classList.add('active');
loadCover(data.cover);
} else {
mediaColumnEl.classList.remove('active');
}
if(data.media) loadMedia(data.media); if(data.media) loadMedia(data.media);
} }
function updateTitle(title){ function updateTitle(title){
if(title){ if(title){
titleEl.classList.add('active'); titleContainerEl.classList.add('active');
config.title = title; config.title = title;
titleEl.innerHTML = title; titleEl.innerHTML = title;
} else { } else {
titleEl.classList.remove('active'); titleContainerEl.classList.remove('active');
} }
} }
function updateDescription(description){ function updateDescription(description){
@ -759,13 +781,13 @@
let description = data.description; let description = data.description;
config = data; config = data;
console.log(data);
loadContent(data); loadContent(data);
updateTitle(title) updateTitle(title)
updateDescription(description); updateDescription(description);
updateTheme(theme); updateTheme(theme);
document.title = titleEl.textContent;
try { try {
volume = parseFloat(localStorage.getItem('volume')); volume = parseFloat(localStorage.getItem('volume'));
muted = parseInt(localStorage.getItem('muted')); muted = parseInt(localStorage.getItem('muted'));
@ -844,7 +866,6 @@
loaderEl = document.createElement('audio'); loaderEl = document.createElement('audio');
} }
loaderEl.addEventListener('loadedmetadata', e => { loaderEl.addEventListener('loadedmetadata', e => {
console.log('loaded metadata', entry.title);
entry.duration = e.target.duration; entry.duration = e.target.duration;
trackEl.querySelector('.duration').textContent = toHMS(entry.duration); trackEl.querySelector('.duration').textContent = toHMS(entry.duration);
if(entry === currentEntry){ if(entry === currentEntry){
@ -859,7 +880,6 @@
trackEl.querySelector('button').setAttribute('title', 'error loading file'); trackEl.querySelector('button').setAttribute('title', 'error loading file');
}); });
loaderEl.addEventListener('canplay', e => { loaderEl.addEventListener('canplay', e => {
console.log('can play', entry.title);
removeLoading(entry, true); removeLoading(entry, true);
}); });
loaderEl.volume = 0; loaderEl.volume = 0;
@ -1022,11 +1042,11 @@
} }
let scrubberDragged = false; let scrubberDragged = false;
scrubberTrackContainerEl.addEventListener('mousedown', e => { scrubberTrackContainerEl.addEventListener('pointerdown', e => {
scrubberDragged = true; scrubberDragged = true;
scrub(e.clientX); scrub(e.clientX);
}); });
document.addEventListener('mouseup', e => { document.addEventListener('pointerup', e => {
if(scrubberDragged){ if(scrubberDragged){
scrubberDragged = false; scrubberDragged = false;
endScrub(); endScrub();
@ -1036,10 +1056,13 @@
endVolumeScrub(); endVolumeScrub();
} }
}); });
document.addEventListener('mousemove', e => { document.addEventListener('pointermove', e => {
scrub(e.clientX); scrub(e.clientX);
scrubVolume(e.clientX); scrubVolume(e.clientX);
}); });
document.addEventListener('pointercancel', e => {
console.log(e);
});
nextTrackEl.addEventListener('click', e => { nextTrackEl.addEventListener('click', e => {
nextTrack(); nextTrack();
@ -1179,7 +1202,7 @@
playerEl.src = entry.file; playerEl.src = entry.file;
setLoading(currentEntry); setLoading(currentEntry);
entry.trackEl.classList.add('active'); entry.trackEl.classList.add('active');
controlsEl.querySelector('.title').textContent = entry.title; controlsEl.querySelector('.title').innerHTML = entry.title;
if(entry.info){ if(entry.info){
mediaInfoEl.innerHTML = entry.info; mediaInfoEl.innerHTML = entry.info;
mediaInfoContainer.classList.add('active'); mediaInfoContainer.classList.add('active');