- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / examples / howto / sandbox / sandbox.html
1 <!--
2   - Copyright (c) 2012 The Chromium Authors. All rights reserved.
3   - Use of this source code is governed by a BSD-style license that can be
4   - found in the LICENSE file.
5   -->
6 <!doctype html>
7 <html>
8   <head>
9     <script src="handlebars-1.0.0.beta.6.js"></script>
10   </head>
11   <body>
12     <script id="hello-world-template" type="text/x-handlebars-template">
13       <div class="entry">
14         <h1>Hello, {{thing}}!</h1>
15       </div>
16     </script>
17     <script>
18       var templates = [];
19       var source = document.getElementById('hello-world-template').innerHTML;
20       templates['hello'] = Handlebars.compile(source);
21
22       // Set up message event handler:
23       window.addEventListener('message', function(event) {
24         var command = event.data.command;
25         var name = event.data.name || 'hello';
26         switch(command) {
27           case 'render':
28             event.source.postMessage({
29               name: name,
30               html: templates[name](event.data.context)
31             }, event.origin);
32             break;
33
34           // You could imagine additional functionality. For instance:
35           //
36           // case 'new':
37           //   templates[event.data.name] = Handlebars.compile(event.data.source);
38           //   event.source.postMessage({name: name, success: true}, event.origin);
39           //   break;
40         }
41       });
42     </script>
43   </body>
44 </html>