-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
156 lines (146 loc) · 4.7 KB
/
index.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FSTraversal</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style type="text/css">
body {
background-color: #eee;
}
h1 {
font-size: 25px;
}
#left-pane {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 300px;
}
#right-pane {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin-left: 300px;
}
#vars-block {
margin: 5px;
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid #ccc;
}
#examples {
margin-top: 30px;
padding: 5px;
padding-top: 15px;
border-top: 1px solid #ccc;
}
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin-bottom: 150px;
}
#output {
position: absolute;
right: 0;
bottom: 0;
left: 0;
margin: 0;
height: 150px;
}
</style>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js"></script>
<script src="//unpkg.com/[email protected]/dist/familysearch-javascript-sdk.min.js"></script>
<script src="fs-traversal.min.js"></script>
<script>
var fsClient;
$(document).ready(function() {
takeOverConsole();
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
$('#run').click(function() {
// Make sure we have an access token
var token = $('#fs-token').val();
fsClient = new FamilySearch({
app_key: 'fs-traversal-demo',
environment: 'production',
access_token: token,
redirect_uri: '/'
});
var source = editor.getSession().toString();
$('#output').empty();
try {
eval(source);
} catch(e) {
$('#output').append($('<div class="console-message">').text(e.message));
}
});
var examples = $('.example').click(function() {
$('.example.active').removeClass('active');
$(this).addClass('active');
var scriptId = 'examples/'+$(this).data('example')+'.js';
$.get( scriptId, function( data ) {
editor.getSession().getDocument().setValue(data);
editor.moveCursorTo(0,0);
}, 'text');
}).first().click();
});
function takeOverConsole(){
var console = window.console;
if (!console) return;
function intercept(method){
var original = console[method];
console[method] = function(){
// do sneaky stuff
$('#output').append($('<div class="console-message">').text(Array.prototype.slice.apply(arguments).join(' ')));
$('#output').scrollTop($('#output')[0].scrollHeight)
if (original.apply){
// Do this for normal browsers
original.apply(console, arguments)
}else{
// Do this for IE
var message = Array.prototype.slice.apply(arguments).join(' ');
original(message);
}
}
}
var methods = ['log', 'warn', 'error'];
for (var i = 0; i < methods.length; i++)
intercept(methods[i]);
}
</script>
</head>
<body>
<div id="left-pane">
<h1><a href="https://github.com/genealogysystems/fs-traversal">FSTraversal Demo</a></h1>
<div id="vars-block">
<div class="form-group">
<label for="fs-token">Access Token</label>
<p>Get an <a href="https://familysearch.org/platform/" target="_blank">access token</a> then paste it in the input field below.</p>
<input type="text" class="form-control" id="fs-token" placeholder="access token" />
</div>
<button class="btn btn-primary" id="run">Run It!</button>
</div>
<div id="examples">
<h3>Examples</h3>
<ul class="list-group">
<a class="example list-group-item" data-example="basic">A Basic Example</a>
<a class="example list-group-item" data-example="throttled">Throttle yourself</a>
<a class="example list-group-item" data-example="kitchen-sink">The kitchen sink</a>
</ul>
</div>
</div>
<div id="right-pane">
<div id="editor"></div>
<pre id="output"></pre>
</div>
</body>
</html>