| OLD | NEW |
| (Empty) |
| 1 {% comment %} | |
| 2 So you want to add more samples: | |
| 3 1 - Create a new pre element below containing the code you want to show. | |
| 4 2 - Give it a unique id of the form "sample-name" | |
| 5 3 - In the main page, add a new option to the select element and make sure value
matches | |
| 6 the name from step #2. | |
| 7 | |
| 8 TODO: These samples are just place holders and should be replaced with something
real. | |
| 9 {% endcomment %} | |
| 10 <div style="display:none"> | |
| 11 | |
| 12 {% comment %} hello dart {% endcomment %} | |
| 13 <pre id="sample-hello">main() { | |
| 14 print('Hello, Dart!'); | |
| 15 }</pre> | |
| 16 | |
| 17 | |
| 18 {% comment %} fibonacci {% endcomment %} | |
| 19 <pre id="sample-fib">int fib(int n) { | |
| 20 if (n <= 1) return n; | |
| 21 return fib(n - 1) + fib(n - 2); | |
| 22 } | |
| 23 | |
| 24 main() { | |
| 25 print('fib(20) = ${fib(20)}'); | |
| 26 }</pre> | |
| 27 | |
| 28 | |
| 29 {% comment %} point{% endcomment %} | |
| 30 <pre id="sample-point">class Point { | |
| 31 Point(this.x, this.y); | |
| 32 distanceTo(Point other) { | |
| 33 var dx = x - other.x; | |
| 34 var dy = y - other.y; | |
| 35 return Math.sqrt(dx * dx + dy * dy); | |
| 36 } | |
| 37 var x, y; | |
| 38 } | |
| 39 | |
| 40 main() { | |
| 41 Point p = new Point(2, 3); | |
| 42 Point q = new Point(3, 4); | |
| 43 print('distance from p to q = ${p.distanceTo(q)}'); | |
| 44 } | |
| 45 </pre> | |
| 46 | |
| 47 </div> | |
| 48 | |
| 49 <script type="text/javascript"> | |
| 50 function show(name) { | |
| 51 var editor = document.getElementById('samples-editor'); | |
| 52 var code = document.getElementById('sample-' + name); | |
| 53 if (editor.setCode) | |
| 54 editor.setCode(code.textContent); | |
| 55 else if (editor.textContent) | |
| 56 editor.textContent = code.textContent; | |
| 57 else | |
| 58 editor.innerText = code.innerText; | |
| 59 } | |
| 60 | |
| 61 window.addEventListener('load', function(e) { | |
| 62 var list = document.getElementById('samples-list'); | |
| 63 document.getElementById('samples-list').addEventListener('change', functio
n(e) { | |
| 64 show(list.value); | |
| 65 }, false); | |
| 66 }, false); | |
| 67 </script> | |
| 68 | |
| OLD | NEW |