mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Implements persistent audio player with ajax handled navigation
This commit is contained in:
1 parent
153c23a523
commit
0b84b2b83b
8 files changed
+200
-6
No files matched your search
+20
@@ -0,0 +1,20 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Web.Controllers.Library.WrittenContentLibrary.BookLibrary;
|
||||||
|
|
||||||
|
[Route("/library/written-content-library/books-library/books/")]
|
||||||
|
public class BooksController : Controller
|
||||||
|
{
|
||||||
|
[HttpGet("")]
|
||||||
|
public IActionResult Index()
|
||||||
|
{
|
||||||
|
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public IActionResult EditBook(Guid id)
|
||||||
|
{
|
||||||
|
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Item.cshtml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ public class FileSystemBrowserViewComponent : ViewComponent
|
|||||||
{
|
{
|
||||||
return View(new
|
return View(new
|
||||||
{
|
{
|
||||||
Path = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? @"/" : @"C:\",
|
Path = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? @"/" : @"C:\Users\",
|
||||||
ServerBasePath = $"{_serverConfigurationModel.BaseAddress}:{_serverConfigurationModel.Port}/api/v{_serverConfigurationModel.ApiVersion}/",
|
ServerBasePath = $"{_serverConfigurationModel.BaseAddress}:{_serverConfigurationModel.Port}/api/v{_serverConfigurationModel.ApiVersion}/",
|
||||||
ClientBasePath = "http://localhost:5012/", // TODO: take from appsettings or environment
|
ClientBasePath = "http://localhost:5012/", // TODO: take from appsettings or environment
|
||||||
ViewMode = FileSystemViewMode.List,
|
ViewMode = FileSystemViewMode.List,
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
<p>All books</p><a href="books/E6B599D6-3819-4FAB-B988-8F027072CF7B" class="nav-link">one</a>
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
<p>A book</p>
|
||||||
@@ -25,6 +25,16 @@
|
|||||||
@RenderBody()
|
@RenderBody()
|
||||||
</article>
|
</article>
|
||||||
</main>
|
</main>
|
||||||
|
<!--Audio player-->
|
||||||
|
<div class="audio-player-container">
|
||||||
|
<video controls
|
||||||
|
preload="auto"
|
||||||
|
height="50" width="600">
|
||||||
|
<source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
|
||||||
|
</video>
|
||||||
|
<a id="audio-player-full-height-toggle">Toggle Full Height</a>
|
||||||
|
<a id="audio-player-close">Toggle Visibility</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--Modal grid background-->
|
<!--Modal grid background-->
|
||||||
<div id="modal-background"></div>
|
<div id="modal-background"></div>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
Written Content
|
Written Content
|
||||||
</div>
|
</div>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="library/written-content/books"><span>Books</span></a></li>
|
<li><a href="library/written-content-library/books-library/books" class="nav-link"><span>Books</span></a></li>
|
||||||
<li><a href="library/written-content/magazines"><span>Magazines</span></a></li>
|
<li><a href="library/written-content/magazines"><span>Magazines</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="mobile-menu-heading">
|
<div class="mobile-menu-heading">
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
<li class="has-submenu" tabindex="0">
|
<li class="has-submenu" tabindex="0">
|
||||||
<label>Written Content</label>
|
<label>Written Content</label>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="library/written-content/books">Books</a></li>
|
<li><a href="library/written-content-library/books-library/books" class="nav-link">Books</a></li>
|
||||||
<li><a href="library/written-content/magazines">Magazines</a></li>
|
<li><a href="library/written-content/magazines">Magazines</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -45,10 +45,43 @@ body {
|
|||||||
background-color: #222;
|
background-color: #222;
|
||||||
min-width: 100%;
|
min-width: 100%;
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
padding-top: 20px;
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
bottom: 50px;
|
||||||
|
width: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
transition: bottom 1s ease, height 1s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
main.audio-player-not-shown {
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
main.audio-player-full-height {
|
||||||
|
bottom: calc(100% - 20px); /* full height minus menu height */
|
||||||
|
}
|
||||||
|
|
||||||
|
.audio-player-container {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 50px;
|
||||||
|
transition: height 1s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.audio-player-container.not-shown {
|
||||||
|
height: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.audio-player-container.full-height {
|
||||||
|
height: calc(100% - 20px); /* full height minus menu height */
|
||||||
}
|
}
|
||||||
|
|
||||||
#modal-background {
|
#modal-background {
|
||||||
@@ -101,6 +134,10 @@ main {
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#audio-player-full-height-toggle, #audio-player-close {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.text-light-one {
|
.text-light-one {
|
||||||
color: #6DCBFE;
|
color: #6DCBFE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ const progressIndicator = document.getElementById('progress-indicator');
|
|||||||
const progressIndicatorValue = document.getElementById('progress-indicator-value');
|
const progressIndicatorValue = document.getElementById('progress-indicator-value');
|
||||||
const progressIndicatorValueShadow = document.getElementById('progress-indicator-value-shadow');
|
const progressIndicatorValueShadow = document.getElementById('progress-indicator-value-shadow');
|
||||||
const progressIndicatorValueText = document.getElementById('progress-indicator-value-text');
|
const progressIndicatorValueText = document.getElementById('progress-indicator-value-text');
|
||||||
|
const audioPlayerFullHeightToggle = document.getElementById('audio-player-full-height-toggle');
|
||||||
|
const audioPlayerClose = document.getElementById('audio-player-close');
|
||||||
|
|
||||||
let enableConsoleDebugMessages = false; // whether to display debug messages at the developer console, or not
|
let enableConsoleDebugMessages = false; // whether to display debug messages at the developer console, or not
|
||||||
|
|
||||||
@@ -38,6 +38,106 @@ async function callApiGetAsync(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//+======================================================================================+
|
||||||
|
//| Website navigation |
|
||||||
|
//+======================================================================================+
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes navigation by setting the initial history state, intercepting link clicks,
|
||||||
|
* and managing back/forward browser actions.
|
||||||
|
*/
|
||||||
|
function initializeNavigation() {
|
||||||
|
// store initial state
|
||||||
|
const initialState = {
|
||||||
|
url: window.location.href,
|
||||||
|
content: document.querySelector('main').innerHTML,
|
||||||
|
title: document.title
|
||||||
|
};
|
||||||
|
history.replaceState(initialState, document.title, window.location.href);
|
||||||
|
// initial nav-link binding
|
||||||
|
bindNavigationLinks();
|
||||||
|
|
||||||
|
// handle browser back/forward
|
||||||
|
window.addEventListener('popstate', handlePopState);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds AJAX navigation behavior to links marked with .nav-link class.
|
||||||
|
*/
|
||||||
|
function bindNavigationLinks() {
|
||||||
|
document.querySelectorAll('.nav-link').forEach(link => {
|
||||||
|
// only bind if not already bound
|
||||||
|
if (!link.dataset.boundNavigation) {
|
||||||
|
link.addEventListener('click', handleNavigation);
|
||||||
|
link.dataset.boundNavigation = 'true';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles link clicks to navigate dynamically without reloading the page.
|
||||||
|
* @param {Event} e - The click event for a navigation link.
|
||||||
|
*/
|
||||||
|
async function handleNavigation(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const url = e.target.href;
|
||||||
|
await updateContent(url, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores page content and title when navigating with browser back/forward buttons.
|
||||||
|
* @param {PopStateEvent} e - The popstate event with previous state data.
|
||||||
|
*/
|
||||||
|
async function handlePopState(e) {
|
||||||
|
if (e.state) {
|
||||||
|
// if we have cached content in state, use it immediately
|
||||||
|
if (e.state.content) {
|
||||||
|
document.querySelector('main').innerHTML = e.state.content;
|
||||||
|
document.title = e.state.title;
|
||||||
|
}
|
||||||
|
// still fetch fresh content to ensure it's up to date
|
||||||
|
await updateContent(e.state.url, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads new page content and updates the URL and history if required.
|
||||||
|
* @param {string} url - URL to fetch new content from.
|
||||||
|
* @param {boolean} addToHistory - Whether to add the new state to history.
|
||||||
|
*/
|
||||||
|
async function updateContent(url, addToHistory) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url);
|
||||||
|
const html = await response.text();
|
||||||
|
|
||||||
|
// parse the new content
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const doc = parser.parseFromString(html, 'text/html');
|
||||||
|
const content = doc.querySelector('main').innerHTML;
|
||||||
|
const title = doc.querySelector('title')?.textContent || document.title;
|
||||||
|
|
||||||
|
// update the page
|
||||||
|
document.querySelector('main').innerHTML = content;
|
||||||
|
document.title = title;
|
||||||
|
|
||||||
|
// bind navigation links in the new content
|
||||||
|
bindNavigationLinks();
|
||||||
|
|
||||||
|
// save to history if needed
|
||||||
|
if (addToHistory) {
|
||||||
|
const state = {
|
||||||
|
url: url,
|
||||||
|
content: content,
|
||||||
|
title: title
|
||||||
|
};
|
||||||
|
history.pushState(state, title, url);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Navigation failed:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//+======================================================================================+
|
//+======================================================================================+
|
||||||
//| Common Helper Functions |
|
//| Common Helper Functions |
|
||||||
//+======================================================================================+
|
//+======================================================================================+
|
||||||
@@ -237,3 +337,28 @@ function getElementOffset(id) {
|
|||||||
height: 0
|
height: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the visibility of the audio player.
|
||||||
|
*/
|
||||||
|
function toggleAudioPlayerVisibility() {
|
||||||
|
const playerContainer = document.querySelector('.audio-player-container');
|
||||||
|
const contentContainer = document.querySelector('main');
|
||||||
|
playerContainer.classList.toggle('not-shown');
|
||||||
|
contentContainer.classList.toggle('audio-player-not-shown');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the display of the audio player as collapsed player, or full height player.
|
||||||
|
*/
|
||||||
|
function toggleAudioPlayerFullHeight() {
|
||||||
|
const playerContainer = document.querySelector('.audio-player-container');
|
||||||
|
const contentContainer = document.querySelector('main');
|
||||||
|
playerContainer.classList.toggle('full-height');
|
||||||
|
contentContainer.classList.toggle('audio-player-full-height');
|
||||||
|
}
|
||||||
|
|
||||||
|
audioPlayerFullHeightToggle.addEventListener('click', toggleAudioPlayerFullHeight);
|
||||||
|
audioPlayerClose.addEventListener('click', toggleAudioPlayerVisibility);
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', initializeNavigation);
|
||||||
Reference in new issue
Block a user