84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
import Cookies from 'js-cookie';
|
|
|
|
export default function settings() {
|
|
return {
|
|
|
|
/**
|
|
* @type {boolean}
|
|
*/
|
|
start: false,
|
|
|
|
/**
|
|
* Two keys, default and alternate.
|
|
* @type {Object}
|
|
*/
|
|
xfUrls: {},
|
|
|
|
/**
|
|
* @type {number[]}
|
|
*/
|
|
entriesPerPage: [ 12, 30, 48 ],
|
|
|
|
/**
|
|
* @type {string}
|
|
*/
|
|
currentTheme: Cookies.get("theme") ?? 'default',
|
|
|
|
/**
|
|
* @type {number}
|
|
*/
|
|
currentEntriesPerPage: Cookies.get("entries_per_page") ?? 30,
|
|
|
|
/**
|
|
*
|
|
* @param {string} newTheme default|alternate
|
|
*/
|
|
themeChanged( newTheme ){
|
|
if( newTheme !== "default" && newTheme !== "alternate" )
|
|
return;
|
|
|
|
if( newTheme === this.currentTheme )
|
|
return;
|
|
|
|
this.currentTheme = newTheme;
|
|
document.documentElement.classList.toggle('light-mode', this.currentTheme === 'alternate');
|
|
|
|
Cookies.set('theme', this.currentTheme, { expires: 365, path: '/', domain: window.getConfig('session-domain') } );
|
|
this.syncXF();
|
|
},
|
|
|
|
/**
|
|
*
|
|
* @return {Promise<void>}
|
|
*/
|
|
async syncXF(){
|
|
await fetch(this.xfUrls[this.currentTheme ?? 'default'], { method: "GET", credentials: "include", mode: "no-cors" });
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
toggleTheme(){
|
|
this.themeChanged(this.currentTheme === 'default' ? 'alternate' : 'default');
|
|
},
|
|
|
|
/**
|
|
*
|
|
* @param n
|
|
*/
|
|
entriesPerPageChanged( n ){
|
|
if( !this.entriesPerPage.includes(n) )
|
|
return;
|
|
|
|
this.entriesPerPage = n;
|
|
Cookies.set('entries_per_page', this.entriesPerPage, { expires: 365, path: '/', domain: window.getConfig('session-domain') } );
|
|
if( window.Livewire ){
|
|
Livewire.dispatch('entriesPerPageChanged', {n});
|
|
}
|
|
},
|
|
|
|
open(){ this.start = !this.start; },
|
|
close(){ this.start = false; },
|
|
}
|
|
}
|