Add Stimulus capabilities controller
This commit is contained in:
parent
e81e85cf9a
commit
07ea833d13
|
@ -0,0 +1,21 @@
|
|||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
export default class extends Controller {
|
||||
connect(): void {
|
||||
const capabilities = [];
|
||||
|
||||
if ('share' in navigator) {
|
||||
capabilities.push('cap-web-share');
|
||||
}
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
capabilities.push('cap-service-worker');
|
||||
}
|
||||
|
||||
if ('Notification' in window) {
|
||||
capabilities.push('cap-notification');
|
||||
}
|
||||
|
||||
this.element.classList.add(...capabilities);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import CharacterCountController from "retrospring/controllers/character_count_co
|
|||
import CharacterCountWarningController from "retrospring/controllers/character_count_warning_controller";
|
||||
import FormatPopupController from "retrospring/controllers/format_popup_controller";
|
||||
import CollapseController from "retrospring/controllers/collapse_controller";
|
||||
import CapabilitiesController from "retrospring/controllers/capabilities_controller";
|
||||
|
||||
/**
|
||||
* This module sets up Stimulus and our controllers
|
||||
|
@ -17,6 +18,7 @@ export default function (): void {
|
|||
window['Stimulus'] = Application.start();
|
||||
window['Stimulus'].register('announcement', AnnouncementController);
|
||||
window['Stimulus'].register('autofocus', AutofocusController);
|
||||
window['Stimulus'].register('capabilities', CapabilitiesController);
|
||||
window['Stimulus'].register('character-count', CharacterCountController);
|
||||
window['Stimulus'].register('character-count-warning', CharacterCountWarningController);
|
||||
window['Stimulus'].register('collapse', CollapseController);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
= csrf_meta_tags
|
||||
= yield(:og)
|
||||
= yield(:meta)
|
||||
%body{ class: user_signed_in? ? '' : 'not-logged-in' }
|
||||
%body{ class: user_signed_in? ? nil : 'not-logged-in', data: { controller: "capabilities" } }
|
||||
- if user_signed_in?
|
||||
= render 'navigation/main'
|
||||
- else
|
||||
|
|
Loading…
Reference in New Issue