mirror of
https://github.com/miniflux/v2.git
synced 2025-08-16 18:01:37 +00:00
refactor(js): code cleanup and add jshint comments
This commit is contained in:
parent
3e1a7e411c
commit
62410659d5
2 changed files with 248 additions and 132 deletions
93
internal/ui/static/js/bootstrap.js
vendored
93
internal/ui/static/js/bootstrap.js
vendored
|
@ -1,5 +1,7 @@
|
|||
disableSubmitButtonsOnFormSubmit();
|
||||
initializeMediaPlayerHandlers();
|
||||
|
||||
// Initialize the keyboard shortcuts if enabled.
|
||||
if (!document.querySelector("body[data-disable-keyboard-shortcuts=true]")) {
|
||||
const keyboardHandler = new KeyboardHandler();
|
||||
keyboardHandler.on("g u", () => goToPage("unread"));
|
||||
|
@ -47,40 +49,11 @@ if (!document.querySelector("body[data-disable-keyboard-shortcuts=true]")) {
|
|||
keyboardHandler.listen();
|
||||
}
|
||||
|
||||
// Initialize the touch handler for mobile devices.
|
||||
const touchHandler = new TouchHandler();
|
||||
touchHandler.listen();
|
||||
|
||||
if (WebAuthnHandler.isWebAuthnSupported()) {
|
||||
const webauthnHandler = new WebAuthnHandler();
|
||||
|
||||
onClick("#webauthn-delete", () => { webauthnHandler.removeAllCredentials(); });
|
||||
|
||||
const registerButton = document.getElementById("webauthn-register");
|
||||
if (registerButton !== null) {
|
||||
registerButton.disabled = false;
|
||||
|
||||
onClick("#webauthn-register", () => {
|
||||
webauthnHandler.register().catch((err) => WebAuthnHandler.showErrorMessage(err));
|
||||
});
|
||||
}
|
||||
|
||||
const loginButton = document.getElementById("webauthn-login");
|
||||
if (loginButton !== null) {
|
||||
const abortController = new AbortController();
|
||||
loginButton.disabled = false;
|
||||
|
||||
onClick("#webauthn-login", () => {
|
||||
const usernameField = document.getElementById("form-username");
|
||||
if (usernameField !== null) {
|
||||
abortController.abort();
|
||||
webauthnHandler.login(usernameField.value).catch(err => WebAuthnHandler.showErrorMessage(err));
|
||||
}
|
||||
});
|
||||
|
||||
webauthnHandler.conditionalLogin(abortController).catch(err => WebAuthnHandler.showErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize click handlers.
|
||||
onClick(":is(a, button)[data-save-entry]", (event) => handleSaveEntry(event.target));
|
||||
onClick(":is(a, button)[data-toggle-bookmark]", (event) => handleBookmark(event.target));
|
||||
onClick(":is(a, button)[data-fetch-content-entry]", handleFetchOriginalContent);
|
||||
|
@ -137,6 +110,7 @@ if ("serviceWorker" in navigator) {
|
|||
}
|
||||
}
|
||||
|
||||
// PWA install prompt handling.
|
||||
window.addEventListener('beforeinstallprompt', (e) => {
|
||||
let deferredPrompt = e;
|
||||
const promptHomeScreen = document.getElementById('prompt-home-screen');
|
||||
|
@ -157,33 +131,34 @@ window.addEventListener('beforeinstallprompt', (e) => {
|
|||
}
|
||||
});
|
||||
|
||||
// Save and resume media position
|
||||
const lastPositionElements = document.querySelectorAll("audio[data-last-position],video[data-last-position]");
|
||||
lastPositionElements.forEach((element) => {
|
||||
if (element.dataset.lastPosition) {
|
||||
element.currentTime = element.dataset.lastPosition;
|
||||
}
|
||||
element.ontimeupdate = () => handlePlayerProgressionSaveAndMarkAsReadOnCompletion(element);
|
||||
});
|
||||
// PassKey handling.
|
||||
if (WebAuthnHandler.isWebAuthnSupported()) {
|
||||
const webauthnHandler = new WebAuthnHandler();
|
||||
|
||||
// Set media playback rate
|
||||
const playbackRateElements = document.querySelectorAll("audio[data-playback-rate],video[data-playback-rate]");
|
||||
playbackRateElements.forEach((element) => {
|
||||
if (element.dataset.playbackRate) {
|
||||
element.playbackRate = element.dataset.playbackRate;
|
||||
if (element.dataset.enclosureId){
|
||||
// In order to display properly the speed we need to do it on bootstrap.
|
||||
// Could not do it backend side because I didn't know how to do it because of the template inclusion and
|
||||
// the way the initial playback speed is handled. See enclosure_media_controls.html if you want to try to fix this
|
||||
document.querySelectorAll(`span.speed-indicator[data-enclosure-id="${element.dataset.enclosureId}"]`).forEach((speedI)=>{
|
||||
speedI.innerText = `${parseFloat(element.dataset.playbackRate).toFixed(2)}x`;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
onClick("#webauthn-delete", () => { webauthnHandler.removeAllCredentials(); });
|
||||
|
||||
// Set enclosure media controls handlers
|
||||
const mediaControlsElements = document.querySelectorAll("button[data-enclosure-action]");
|
||||
mediaControlsElements.forEach((element) => {
|
||||
element.addEventListener("click", () => handleMediaControl(element));
|
||||
});
|
||||
const registerButton = document.getElementById("webauthn-register");
|
||||
if (registerButton !== null) {
|
||||
registerButton.disabled = false;
|
||||
|
||||
onClick("#webauthn-register", () => {
|
||||
webauthnHandler.register().catch((err) => WebAuthnHandler.showErrorMessage(err));
|
||||
});
|
||||
}
|
||||
|
||||
const loginButton = document.getElementById("webauthn-login");
|
||||
if (loginButton !== null) {
|
||||
const abortController = new AbortController();
|
||||
loginButton.disabled = false;
|
||||
|
||||
onClick("#webauthn-login", () => {
|
||||
const usernameField = document.getElementById("form-username");
|
||||
if (usernameField !== null) {
|
||||
abortController.abort();
|
||||
webauthnHandler.login(usernameField.value).catch(err => WebAuthnHandler.showErrorMessage(err));
|
||||
}
|
||||
});
|
||||
|
||||
webauthnHandler.conditionalLogin(abortController).catch(err => WebAuthnHandler.showErrorMessage(err));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue