forked from DrDub/Language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaultWidget.html
70 lines (70 loc) · 2.29 KB
/
defaultWidget.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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>default widget</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../libs/handlebars-1.0.rc.1.js"></script>
<script type="text/javascript" src="../libs/jQuery-URL-Parser/purl.js"></script>
<style>
.category {
color:blue;
}
.details {
color:green;
}
.component {
color:orange;
}
</style>
<script>
Handlebars.registerHelper('stringify', function(object) {
return JSON.stringify($.extend({}, object), 2, 4);
});
$(function(){
var interpId = $.url().param('interpId');
$.getJSON('../interpretations/' + interpId, function(data) {
//$('.content').text(data);
var template = Handlebars.compile($("#componentTemplate").html());
Handlebars.registerPartial("component", $("#componentTemplate").html());
$('.content').html(template(data.root));
$('.detailsBtn').click(function(){
$(this).siblings().toggle();
});
$('.detailsBtn').siblings().toggle();
});
});
</script>
</head>
<body>
<div class="content"></div>
<script id="componentTemplate" type="text/x-handlebars-template">
{{#if category}}
<div class="category">{{category}}</div>
<div class="details"><button class="detailsBtn">details</button><pre>{{stringify this}}</pre></div>
<ul>
{{#each interpretations}}
<li class="interpretation">
{{#each this}}
<span class="component">{{> component}}</span>
{{/each}}
</li>
{{/each}}
</ul>
{{else}}
{{#if terminal}}
<p>Terminal: {{terminal}}</p>
{{else}}
{{#if regex}}
<p>RegExp: {{regex}}</p>
<p>Match: {{match}}</p>
{{else}}
<h3>Unknown type</h3>
{{stringify this}}
{{/if}}
{{/if}}
{{/if}}
</script>
</body>
</html>