so://phie

outline

A web-based drawing app
git clone git://soophie.de/outline

blob: 83ee74b03c9e90e7c050093110a5c4840b8f0677 (3144 bytes)[doc][blame][raw]

1import { FIREBASE, LOCALES } from './constant.js';

2import { uuid, query } from './util.js';

3

4import locale from './mod/locale.js';

5import cookie from './mod/cookie.js';

6

7let node;

8let state = {

9 deferredPrompt: null

10};

11

12export function init() {

13

14 locale.init();

15 locale.load('./asset/lang', LOCALES);

16

17 node = query({

18 notification: '.notification',

19 cookie: '.cookie',

20 accept: '.button.accept'

21 });

22

23 let elements = document.querySelectorAll('[data-event]');

24 for(let element of elements) {

25 let value = element.dataset.event;

26

27 if(value === 'play') {

28 element.addEventListener('click', function() {

29 window.location.href = '/app';

30 });

31 }

32

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 }

47

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 });

58

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: 400

69 });

70

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: 600

81 });

82

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: 600

93 });

94

95 window.addEventListener('beforeinstallprompt', function(event) {

96 event.preventDefault();

97 state.deferredPrompt = event;

98 });

99

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 load_resources();

106 });

107 }

108 else {

109 load_resources();

110 }

111}

112

113function load_resources() {

114 let dark_mode = localStorage.getItem('outline.custom.dark-mode');

115 if(dark_mode && dark_mode === 'true') {

116 document.body.classList.add('theme-dark');

117 }

118 try {

119 firebase.initializeApp(FIREBASE);

120 firebase.analytics();

121 }

122 catch(error) {

123 console.warn('Unable to load Google Analytics!');

124 }

125}

126

127function show_notification(message) {

128 let code = uuid();

129 state.timestamp = code;

130 let content = node.notification.querySelector('.content');

131 content.textContent = locale.get()[message];

132 node.notification.animate([

133 { opacity: 0 },

134 { opacity: 1 }

135 ], {

136 duration: 200,

137 fill: 'both'

138 });

139 setTimeout(function() {

140 if(state.timestamp === code) {

141 node.notification.animate([

142 { opacity: 1 },

143 { opacity: 0 }

144 ], {

145 duration: 200,

146 fill: 'both'

147 });

148 }

149 }, 5000);

150}