mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-19 04:06:04 +01:00
Fix capability classes being removed on page navigation
The body tag gets replaced by Turbo on page navigation, removing the classes.
This commit is contained in:
parent
29a3bfea88
commit
c8f5511a38
4 changed files with 17 additions and 13 deletions
|
@ -5,6 +5,7 @@ import { definitionsFromContext } from '@hotwired/stimulus-webpack-helpers';
|
|||
|
||||
import start from 'retrospring/common';
|
||||
import initAnswerbox from 'retrospring/features/answerbox/index';
|
||||
import initCapabilities from 'retrospring/features/capabilities';
|
||||
import initInbox from 'retrospring/features/inbox/index';
|
||||
import initUser from 'retrospring/features/user';
|
||||
import initSettings from 'retrospring/features/settings/index';
|
||||
|
@ -18,6 +19,7 @@ import initFront from 'retrospring/features/front';
|
|||
import initWebpush from 'retrospring/features/webpush';
|
||||
|
||||
start();
|
||||
document.addEventListener('turbo:load', initCapabilities);
|
||||
document.addEventListener('DOMContentLoaded', initAnswerbox);
|
||||
document.addEventListener('DOMContentLoaded', initInbox);
|
||||
document.addEventListener('DOMContentLoaded', initUser);
|
||||
|
|
|
@ -7,10 +7,6 @@ import { answerboxSmileHandler } from './smile';
|
|||
import { answerboxSubscribeHandler } from './subscribe';
|
||||
|
||||
export default (): void => {
|
||||
if ('share' in navigator) {
|
||||
document.body.classList.add('cap-web-share');
|
||||
}
|
||||
|
||||
registerEvents([
|
||||
{ type: 'click', target: '[name=ab-share]', handler: shareEventHandler, global: true },
|
||||
{ type: 'click', target: '[data-action=ab-submarine]', handler: answerboxSubscribeHandler, global: true },
|
||||
|
|
13
app/javascript/retrospring/features/capabilities/index.ts
Normal file
13
app/javascript/retrospring/features/capabilities/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
export default (): void => {
|
||||
if ('share' in navigator) {
|
||||
document.body.classList.add('cap-web-share');
|
||||
}
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
document.body.classList.add('cap-service-worker');
|
||||
}
|
||||
|
||||
if ('Notification' in window) {
|
||||
document.body.classList.add('cap-notification');
|
||||
}
|
||||
}
|
|
@ -3,15 +3,8 @@ import { enableHandler } from './enable';
|
|||
import { dismissHandler } from "./dismiss";
|
||||
|
||||
export default (): void => {
|
||||
const swCapable = 'serviceWorker' in navigator;
|
||||
if (swCapable) {
|
||||
document.body.classList.add('cap-service-worker');
|
||||
}
|
||||
|
||||
const notificationCapable = 'Notification' in window;
|
||||
if (notificationCapable) {
|
||||
document.body.classList.add('cap-notification');
|
||||
}
|
||||
const swCapable = document.body.classList.contains('cap-service-worker');
|
||||
const notificationCapable = document.body.classList.contains('cap-notification');
|
||||
|
||||
if (swCapable && notificationCapable) {
|
||||
navigator.serviceWorker.getRegistration().then(registration => {
|
||||
|
|
Loading…
Reference in a new issue