A web-based drawing app
git clone git://soophie.de/outline
blob: d3dab37560b5290a9c3bc753eeea2505638ed6ff (3278 bytes)[doc][blame][raw]
1
import { FIREBASE, LOCALES } from './constant.js';2
import { uuid, query } from './util.js';4
import locale from './mod/locale.js';5
import cookie from './mod/cookie.js';7
let node;8
let state = {9
deferredPrompt: null10
};12
export function init() {14
locale.init();15
locale.load('./asset/lang', LOCALES);17
node = query({18
notification: '.notification',19
cookie: '.cookie',20
accept: '.button.accept'21
});23
let elements = document.querySelectorAll('[data-event]');24
for(let element of elements) {25
let value = element.dataset.event;27
if(value === 'play') {28
element.addEventListener('click', function() {29
window.location.href = '/app';30
});31
}33
if(value === 'install') {34
element.addEventListener('click', function() {35
if(state.deferredPrompt) {36
/*37
state.deferredPrompt.prompt();38
state.deferredPrompt.userChoice.then(function(result) {39
let installed = result.outcome === 'accepted';40
});41
*/42
}43
else {44
show_notification('main.upcoming');45
}46
});47
}48
}50
let header = document.querySelector('header');51
header.classList.remove('transparent');52
header.animate([53
{ opacity: 0 },54
{ opacity: 1 }55
], {56
duration: 400,57
fill: 'both',58
easing: 'ease-in'59
});61
let brand_logo = document.querySelector('.brand-logo');62
brand_logo.classList.remove('transparent');63
brand_logo.animate([64
{ opacity: 0 },65
{ opacity: 1 }66
], {67
duration: 200,68
fill: 'both',69
easing: 'ease-in',70
delay: 40071
});73
let logo = document.querySelector('.logo');74
logo.classList.remove('transparent');75
logo.animate([76
{ opacity: 0, marginTop: '50px' },77
{ opacity: 1, marginTop: 0 }78
], {79
duration: 400,80
fill: 'both',81
easing: 'ease-out',82
delay: 60083
});85
let info = document.querySelector('.header-info');86
info.classList.remove('transparent');87
info.animate([88
{ opacity: 0, marginTop: '50px' },89
{ opacity: 1, marginTop: 0 }90
], {91
duration: 400,92
fill: 'both',93
easing: 'ease-out',94
delay: 60095
});97
window.addEventListener('beforeinstallprompt', function(event) {98
event.preventDefault();99
state.deferredPrompt = event;100
});102
if(!cookie.hasAccepted()) {103
node.cookie.classList.remove('hidden');104
cookie.requestPermission(node.accept)105
.then(function() {106
node.cookie.classList.add('hidden');107
load_resources();108
});109
}110
else {111
load_resources();112
}113
}115
function load_resources() {116
let dark_mode = localStorage.getItem('outline.custom.dark-mode');117
if(dark_mode && dark_mode === 'true') {118
document.body.classList.add('theme-dark');119
}120
let lang = localStorage.getItem('outline.custom.lang');121
if(lang && LOCALES.includes(lang)) {122
locale.change(lang);123
}124
try {125
firebase.initializeApp(FIREBASE);126
firebase.analytics();127
}128
catch(error) {129
console.warn('Unable to load Google Analytics!');130
}131
}133
function show_notification(message) {134
let code = uuid();135
state.timestamp = code;136
let content = node.notification.querySelector('.content');137
content.textContent = locale.get()[message];138
node.notification.animate([139
{ opacity: 0 },140
{ opacity: 1 }141
], {142
duration: 200,143
fill: 'both'144
});145
setTimeout(function() {146
if(state.timestamp === code) {147
node.notification.animate([148
{ opacity: 1 },149
{ opacity: 0 }150
], {151
duration: 200,152
fill: 'both'153
});154
}155
}, 5000);156
}