|
1 | 1 | <html> |
2 | 2 | <head> |
3 | 3 | <title>HTMLBars example</title> |
| 4 | + <style type="text/css"> |
| 5 | + #inputs { |
| 6 | + overflow: hidden; |
| 7 | + } |
| 8 | + |
| 9 | + #inputs label { |
| 10 | + float: left; |
| 11 | + } |
| 12 | + |
| 13 | + #inputs textarea { |
| 14 | + display: block; |
| 15 | + width: 300px; |
| 16 | + height: 150px; |
| 17 | + margin: 5px 10px 5px 0px; |
| 18 | + font-family: monospace; |
| 19 | + } |
| 20 | + </style> |
4 | 21 | </head> |
5 | 22 | <body> |
6 | | - <label> |
7 | | - Data |
8 | | - <textarea id="data">{"name": "Bob"}</textarea> |
9 | | - </label> |
10 | | - |
11 | | - <label> |
12 | | - Template |
13 | | - <textarea id="template">Howdy {{name}}</textarea> |
14 | | - </label> |
15 | | - |
16 | | - <label> |
17 | | - Options |
18 | | - <textarea id="options">{ "disableComponentGeneration": true }</textarea> |
19 | | - </label> |
20 | | - |
21 | | - <label> |
22 | | - <input id="skip-render" type="checkbox"> |
23 | | - Skip render? |
24 | | - </label> |
25 | | - |
26 | | - <button id="run-template">Compile and Render</button> |
| 23 | + <div id="inputs"> |
| 24 | + <label> |
| 25 | + Data |
| 26 | + <textarea id="data">{"name": "Bob"}</textarea> |
| 27 | + </label> |
| 28 | + |
| 29 | + <label> |
| 30 | + Template |
| 31 | + <textarea id="template">Howdy {{name}}</textarea> |
| 32 | + </label> |
| 33 | + |
| 34 | + <label> |
| 35 | + Options |
| 36 | + <textarea id="options">{ "disableComponentGeneration": true }</textarea> |
| 37 | + </label> |
| 38 | + </div> |
| 39 | + |
| 40 | + <div id="actions"> |
| 41 | + <button id="compile-template">Compile</button> |
| 42 | + <button id="run-template">Compile and Render</button> |
| 43 | + </div> |
| 44 | + |
27 | 45 | <hr> |
| 46 | + |
28 | 47 | <div id="output"></div> |
29 | 48 |
|
30 | 49 | <script src="../assets/loader.js"></script> |
31 | 50 | <script src="../amd/dom-helper.amd.js"></script> |
32 | 51 | <script src="../amd/htmlbars-compiler.amd.js"></script> |
33 | 52 | <script src="../amd/htmlbars-runtime.amd.js"></script> |
34 | 53 | <script> |
35 | | - var button = document.getElementById('run-template'), |
| 54 | + var compileBtn = document.getElementById('compile-template'), |
| 55 | + runBtn = document.getElementById('run-template'), |
36 | 56 | dataarea = document.getElementById('data'), |
37 | 57 | textarea = document.getElementById('template'), |
38 | 58 | output = document.getElementById('output'), |
|
46 | 66 |
|
47 | 67 | var templateSource = localStorage.getItem('templateSource'); |
48 | 68 | var data = localStorage.getItem('templateData'); |
49 | | - var shouldRender = localStorage.getItem('shouldRender'); |
50 | 69 |
|
51 | 70 | if (templateSource) { |
52 | 71 | textarea.value = templateSource; |
|
56 | 75 | dataarea.value = data; |
57 | 76 | } |
58 | 77 |
|
59 | | - if (shouldRender === "false") { |
60 | | - skipRender.checked = true; |
61 | | - } |
| 78 | + compileBtn.addEventListener('click', function() { compile(false); }); |
| 79 | + runBtn.addEventListener('click', function() { compile(true); }); |
62 | 80 |
|
63 | | - button.addEventListener('click', function() { |
| 81 | + function compile(shouldRender) { |
64 | 82 | var source = textarea.value, |
65 | 83 | data = dataarea.value, |
66 | | - shouldRender = !skipRender.checked, |
67 | 84 | compileOptions; |
68 | 85 |
|
69 | 86 | localStorage.setItem('templateSource', source); |
70 | 87 | localStorage.setItem('templateData', data); |
71 | | - localStorage.setItem('shouldRender', shouldRender); |
72 | 88 |
|
73 | 89 | try { |
74 | 90 | data = JSON.parse(data); |
|
104 | 120 | output.innerHTML += 'Failure to run template: '+e.message; |
105 | 121 | throw(e); |
106 | 122 | } |
107 | | - }); |
| 123 | + } |
108 | 124 | </script> |
109 | 125 | </body> |
110 | 126 | </html> |
0 commit comments