A web-based drawing app
git clone git://soophie.de/outline
blob: ddb420efa19fa0a1dcf67437735b1072936a6415 (2925 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
state.deferredPrompt.prompt();37
state.deferredPrompt.userChoice.then(function(result) {38
// let installed = result.outcome === 'accepted';39
});40
}41
else {42
show_notification('main.upcoming');43
}44
});45
}46
}48
let header = document.querySelector('header');49
header.classList.remove('transparent');50
header.animate([51
{ opacity: 0 },52
{ opacity: 1 }53
], {54
duration: 400,55
fill: 'both',56
easing: 'ease-in'57
});59
let brand_logo = document.querySelector('.brand-logo');60
brand_logo.classList.remove('transparent');61
brand_logo.animate([62
{ opacity: 0 },63
{ opacity: 1 }64
], {65
duration: 200,66
fill: 'both',67
easing: 'ease-in',68
delay: 40069
});71
let logo = document.querySelector('.logo');72
logo.classList.remove('transparent');73
logo.animate([74
{ opacity: 0, marginTop: '50px' },75
{ opacity: 1, marginTop: 0 }76
], {77
duration: 400,78
fill: 'both',79
easing: 'ease-out',80
delay: 60081
});83
let info = document.querySelector('.header-info');84
info.classList.remove('transparent');85
info.animate([86
{ opacity: 0, marginTop: '50px' },87
{ opacity: 1, marginTop: 0 }88
], {89
duration: 400,90
fill: 'both',91
easing: 'ease-out',92
delay: 60093
});95
window.addEventListener('beforeinstallprompt', function(event) {96
event.preventDefault();97
state.deferredPrompt = event;98
});100
if(!cookie.hasAccepted()) {101
node.cookie.classList.remove('hidden');102
cookie.requestPermission(node.accept)103
.then(function() {104
node.cookie.classList.add('hidden');105
try {106
firebase.initializeApp(FIREBASE);107
firebase.analytics();108
}109
catch(error) {110
console.warn('Unable to load Google Analytics!');111
}112
});113
}114
}116
function show_notification(message) {117
let code = uuid();118
state.timestamp = code;119
let content = node.notification.querySelector('.content');120
content.textContent = locale.get()[message];121
node.notification.animate([122
{ opacity: 0 },123
{ opacity: 1 }124
], {125
duration: 200,126
fill: 'both'127
});128
setTimeout(function() {129
if(state.timestamp === code) {130
node.notification.animate([131
{ opacity: 1 },132
{ opacity: 0 }133
], {134
duration: 200,135
fill: 'both'136
});137
}138
}, 5000);139
}