Files
monica/resources/js/methods.js
T

40 lines
1.1 KiB
JavaScript
Vendored
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { computed } from 'vue';
import { trans } from 'laravel-vue-i18n';
import emitter from 'tiny-emitter/instance';
/**
* Flash a message.
*
* @param {string} message
* @param {string} level
*/
export const flash = (message, level = 'success') => {
emitter.emit('flash', { message, level });
};
export const isDark = () => {
return (
localStorage.theme === 'dark' ||
(!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
);
};
/**
* Get the message in case WebAuthn is not supported.
*
* @return {string}
*/
export const webAuthnNotSupportedMessage = computed(() =>
!window.isSecureContext && window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1'
? trans('WebAuthn only supports secure connections. Please load this page with https scheme.')
: trans('Your browser doesnt currently support WebAuthn.'),
);
export default {
flash,
isDark,
$on: (...args) => emitter.on(...args),
$once: (...args) => emitter.once(...args),
$off: (...args) => emitter.off(...args),
};