A web-based drawing app
git clone git://soophie.de/outline
blob: 96638efb8c11a0d9ab6c009a98177318e59a4f6d (2488 bytes)[doc][blame][raw]
1
import { LOCALES } from '../constant.js';2
import { uuid, query } from '../util.js';4
import locale from '../mod/locale.js';6
let node;7
let state = {8
deferredPrompt: null9
};11
export function init() {13
locale.init('en');14
locale.load('./asset/lang', LOCALES);16
node = query({17
notification: '.notification'18
});20
let elements = document.querySelectorAll('[data-event]');21
for(let element of elements) {22
let value = element.dataset.event;24
if(value === 'play') {25
element.addEventListener('click', function() {26
window.location.href = '/app';27
});28
}30
if(value === 'install') {31
element.addEventListener('click', function() {32
if(state.deferredPrompt) {33
state.deferredPrompt.prompt();34
state.deferredPrompt.userChoice.then(function(result) {35
// let installed = result.outcome === 'accepted';36
});37
}38
else {39
show_notification('main.upcoming');40
}41
});42
}43
}45
let header = document.querySelector('header');46
header.classList.remove('transparent');47
header.animate([48
{ opacity: 0 },49
{ opacity: 1 }50
], {51
duration: 400,52
fill: 'both',53
easing: 'ease-in'54
});56
let brand_logo = document.querySelector('.brand-logo');57
brand_logo.classList.remove('transparent');58
brand_logo.animate([59
{ opacity: 0 },60
{ opacity: 1 }61
], {62
duration: 200,63
fill: 'both',64
easing: 'ease-in',65
delay: 40066
});68
let logo = document.querySelector('.logo');69
logo.classList.remove('transparent');70
logo.animate([71
{ opacity: 0, marginTop: '50px' },72
{ opacity: 1, marginTop: 0 }73
], {74
duration: 400,75
fill: 'both',76
easing: 'ease-out',77
delay: 60078
});80
let info = document.querySelector('.header-info');81
info.classList.remove('transparent');82
info.animate([83
{ opacity: 0, marginTop: '50px' },84
{ opacity: 1, marginTop: 0 }85
], {86
duration: 400,87
fill: 'both',88
easing: 'ease-out',89
delay: 60090
});92
window.addEventListener('beforeinstallprompt', function(event) {93
event.preventDefault();94
state.deferredPrompt = event;95
});96
}98
function show_notification(message) {99
let code = uuid();100
state.timestamp = code;101
let content = node.notification.querySelector('.content');102
content.textContent = locale.get()[message];103
node.notification.animate([104
{ opacity: 0 },105
{ opacity: 1 }106
], {107
duration: 200,108
fill: 'both'109
});110
setTimeout(function() {111
if(state.timestamp === code) {112
node.notification.animate([113
{ opacity: 1 },114
{ opacity: 0 }115
], {116
duration: 200,117
fill: 'both'118
});119
}120
}, 5000);121
}