forked from google/santa-tracker-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembed.html
More file actions
157 lines (135 loc) · 4.5 KB
/
embed.html
File metadata and controls
157 lines (135 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!--
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title msgid="meta_title">Google Santa Tracker</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:100,300,400,600,700,800|Lobster">
<link rel="stylesheet" href="sass/santatracker.css">
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-37048309-' + (location.hostname == 'santatracker.google.com' ? 1 : 2), 'auto');
ga('set', 'transport', 'beacon');
</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>
<link id="DEV" comment="element removed in prod" />
<link id="ES5_ADAPTER" comment="replaced with es5 adapter in prod">
<script>
window.Polymer = {
noUrlSettings: true,
dom: 'shadow',
lazyRegister: 'max',
useNativeCSSProperties: true,
};
const skipElements = ['santa-chrome', 'santa-badge', 'santa-sidebar', 'santa-overlay', 'santa-hint'];
const realCEDefine = customElements.define;
customElements.define = (name, ctor) => {
if (skipElements.indexOf(name) === -1) {
return realCEDefine.call(customElements, name, ctor);
}
};
window.addEventListener('DOMContentLoaded', function() {
// initial route is always /embed.html#route
window.santaApp.route = window.location.hash.substr(1);
});
// Disable some default scenes, but allow everything else. This must be added above `santaApp`
// (both in execution and DOM) so `capture: true` is respected.
document.addEventListener('beforeload', (ev) => {
const route = ev.detail;
if (route === 'village' || route === 'tracker') {
ev.preventDefault();
window.santaApp.fire('embed', 'ongotovillage'); // user requested to go 'home'
}
ev.stopPropagation(); // otherwise, allow everything
}, {capture: true});
</script>
<link rel="import" href="elements/elements_en.html" crossorigin />
</head>
<body unresolved class="scrollock">
<santa-app id="santaApp" mode="embed"></santa-app>
<script>
(function() {
const s = window.santaApp;
let messagePort = null;
let queue = {};
/**
* Send a message to the controlling interface.
*
* @param {string|{type: string, data: *}} message
*/
function send(message) {
if (typeof message === 'string') {
message = {type: message, data: null};
} else if (!message.type) {
console.warn('unhandled embed message', message);
return;
}
console.debug('sending to embed', message);
if (!messagePort) {
queue[message.type] = message.data;
return;
}
messagePort.postMessage(JSON.stringify(message));
}
/**
* Handles recieving a message from the controller.
*
* @param {string} message
*/
function recv(message) {
console.debug('handling incoming', message);
switch (message) {
case 'mute':
s.userMute = true;
break;
case 'unmute':
s.userMute = false;
break;
case 'restart':
case 'restartGame':
s.onRestartGame();
break;
case 'pauseGame':
case 'pause':
s.userPause = true;
break;
case 'resumeGame':
case 'resume':
s.onResumeGame();
break;
default:
console.warn('unhandled from messagePort', message);
}
}
window._testRecv = recv;
window.addEventListener('message', (e) => {
if (e.source === null && (e.data === '' || e.data === 'santaandroid')) {
// great
} else {
console.debug('ignoring incoming message', e);
return;
}
messagePort = e.ports[0];
messagePort.onmessage = (e) => recv(e.data);
console.debug('got messagePort from embed', messagePort, 'clearing queue', queue);
for (const k in queue) {
messagePort.postMessage(JSON.stringify({type: k, data: queue[k]}))
}
queue = null;
});
s.addEventListener('embed', (e) => send(e.detail));
}());
</script>
</body>
</html>