forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox.html
44 lines (42 loc) · 1.35 KB
/
sandbox.html
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
<!--
- Copyright (c) 2012 The Chromium Authors. All rights reserved.
- Use of this source code is governed by a BSD-style license that can be
- found in the LICENSE file.
-->
<!doctype html>
<html>
<head>
<script src="handlebars-1.0.0.beta.6.js"></script>
</head>
<body>
<script id="hello-world-template" type="text/x-handlebars-template">
<div class="entry">
<h1>Hello, {{thing}}!</h1>
</div>
</script>
<script>
var templates = [];
var source = document.getElementById('hello-world-template').innerHTML;
templates['hello'] = Handlebars.compile(source);
// Set up message event handler:
window.addEventListener('message', function(event) {
var command = event.data.command;
var name = event.data.name || 'hello';
switch(command) {
case 'render':
event.source.postMessage({
name: name,
html: templates[name](event.data.context)
}, event.origin);
break;
// You could imagine additional functionality. For instance:
//
// case 'new':
// templates[event.data.name] = Handlebars.compile(event.data.source);
// event.source.postMessage({name: name, success: true}, event.origin);
// break;
}
});
</script>
</body>
</html>