forked from jayankaghosh/jst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtryit.html
More file actions
71 lines (71 loc) · 2.14 KB
/
tryit.html
File metadata and controls
71 lines (71 loc) · 2.14 KB
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
71
<!DOCTYPE html>
<html>
<head>
<title>Try It</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="jumbotron"><h1>Try It Yourself</h1></div>
<div class="row">
<div class="col-md-12 well well-md">
<pre><div data-template="tryit" data-provider="tryit"></div></pre>
</div>
<form class="col-md-6 row tryit-form">
<div class="col-md-6 form-horizontal">
<label>Template</label>
<textarea class="form-control" rows=10 id="tryit_template">
<h1>
{{var this.messages.welcome}}
</h1>
</textarea>
</div>
<div class="col-md-6 form-horizontal">
<label>Data Provider</label>
<textarea class="form-control" rows=10 id="tryit_data_provider">
{
"messages": {
"welcome": "Hello World"
}
}
</textarea>
</div>
<div class="col-md-12">
<button class="btn btn-success">Try It</button>
</div>
</form>
<div class="col-md-6" id="output_container">
<label>Output</label>
<div class="output well well-md" data-template="tryit" data-provider="tryit"></div>
</div>
</div>
<script type="text/javascript" src="bin/JST.js"></script>
<script type="text/javascript">
(function(){
$('.tryit-form').on('submit', function(e){
e.preventDefault();
refreshOutput();
});
function refreshOutput(){
JST.setTemplate('tryit', function(){
return $('#tryit_template').val();
});
try{
JST.setProvider('tryit', JSON.parse($('#tryit_data_provider').val()));
JST.actions.parsePage($('#output_container').get(0));
}
catch(e){
throw e;
console.log(e);
alert("Please enter a valid JSON as the data provider and check if your template is proper. Check console for more errors");
}
}
refreshOutput();
})();
</script>
</div>
</body>
</html>