-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
245 lines (220 loc) · 6.94 KB
/
index.html
File metadata and controls
245 lines (220 loc) · 6.94 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<html>
<head>
<title>Villo API Console</title>
<!-- Include jQuery and jqConsole -->
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="lib/jqconsole.js" type="text/javascript"></script>
<!-- Include our styles -->
<link rel="stylesheet" type="text/css" href="lib/jqconsole.css">
</head>
<body>
<!--
Loader:
-->
<div id="loader">
<div class="modal-backdrop"><!-- This is just the backdrop. --></div>
<div class="modal">
<div class="bigger">API Console Setup</div>
<hr />
<div class="subbigger">Select Your Version Of Villo</div>
<div>
<div>
<input id="radioStable" type="radio" name="version" value="else">
<label for="radioStable">Latest Stable Release (<span id="latestStableVersion">0.9.7</span>)</label>
</div>
<div>
<input id="radioEdge" type="radio" name="version" checked="true" value="radioEdge">
<label for="radioEdge">Bleeding edge (<span id="bleedingEdgeVersion"></span>)</label>
</div>
</div>
<div class="subbigger">Enter Your Developer Credentials</div>
<div>
<!-- We're lazy, and it works -->
<table>
<tr>
<td>
<label>API Key</label>
</td>
<td>
<input id="setApiKey" type="text">
</td>
</tr>
<tr>
<td>
<label>App ID</label>
</td>
<td>
<input id="setAppId" type="text">
</td>
</tr>
<tr>
<td valign="top">
<label>Logging</label>
</td>
<td>
<div>
<input id="radioLogOn" type="radio" name="logMe" value="true">
<label for="radioLogOn">On</label>
</div>
<div>
<input id="radioLogOff" type="radio" name="logMe" checked="true" value="false">
<label for="radioLogOff">Off</label>
</div>
</td>
</tr>
</table>
</div>
<div class="button" onclick="startConsole();">
Contine to the Console
</div>
</div>
</div>
<script type="text/javascript">
//Just to test for this later on.
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
//Non-villo script loader:
var loadScript = function(src, callback){
var s = document.createElement('script');
s.type = "text/javascript";
s.async = true;
s.src = src;
s.addEventListener('load', function (e) {
callback(e);
}, false);
document.getElementsByTagName('head')[0].appendChild(s);
}
//Load bleeding-edge version of Villo to get the version:
$(function(){
//Get the API key.
if(supports_html5_storage()){
$("#setApiKey").val(localStorage.getItem("apiconsole.key") || "");
}
loadScript("https://raw.github.com/villo/villojs/gh-pages/villo.js", function(e){
//Set the verison:
$("#bleedingEdgeVersion").html(villo.version);
//Delete the Villo instance:
delete villo;
});
});
</script>
<!--
Console:
-->
<div id="console"></div>
<script type="text/javascript">
var startConsole = function(){
//Store the API key.
if(supports_html5_storage()){
localStorage.setItem("apiconsole.key", $("#setApiKey").val());
}
$("#loader").css("visibility", "hidden");
if($('input:radio[name=version]:checked').val() === "radioEdge"){
//Load bleeding edge:
loadScript("https://raw.github.com/villo/villoJS/gh-pages/villo.js", function(){
doneLoading();
});
}else{
//Load stable:
loadScript("lib/villo-0.9.7.js", function(){
doneLoading();
});
}
}
var doneLoading = function(){
//Call our load function:
villo.load({
"id": $("#setAppId").val(),
"version": "1.0.0",
"developer": "Villo & Guests",
"type": "desktop",
"title": "API Console",
"api": $("#setApiKey").val(),
"verbose": ($('input:radio[name=logMe]:checked').val() === "true") ? true : false
});
//Load console extension, prevent caching.
loadScript("lib/console.js?" + new Date().getTime(), function(){
villo.console.jqconsole = $('#console').jqconsole("Welcome to the new Villo API Console! Type \"help\" if you need some guidance. \n", ">>> ");
//Ctrl+E: Move into edit mode - native multi-line support.
villo.console.jqconsole.RegisterShortcut('E', function() {
//Turn it on or off:
villo.console.edit = !villo.console.edit;
if(villo.console.edit === true){
this.Write('Multi-line edit mode enabled.\n', 'jqconsole-output');
}else{
this.Write('Multi-line edit mode disabled.\n', 'jqconsole-output');
}
});
//Ctrl+D: Dump the entire console log back into the console.
/*
villo.console.jqconsole.RegisterShortcut('D', function() {
this.Write(this.Dump(), 'jqconsole-output');
});
*/
//Replace console.log with our function:
if(window.console && window.console.log){
//Keep reference to the original function:
window.console.realLog = window.console.log;
//Replace with ours:
window.console.log = function () {
var strings = [];
for (var i = 0; i < arguments.length; i++) {
if (typeof(arguments[i] == "object")) {
strings.push(JSON.stringify(arguments[i]));
} else {
strings.push(arguments[i]);
}
}
villo.console.jqconsole.Write(strings.join(" ") + "\n", "jqconsole-output");
this.realLog(arguments);
}
}else{
//No console, just create our own:
window.console = {
log: function () {
var strings = [];
for (var i = 0; i < arguments.length; i++) {
if (typeof(arguments[i] == "object")) {
strings.push(JSON.stringify(arguments[i]));
} else {
strings.push(arguments[i]);
}
}
villo.console.jqconsole.Write(strings.join(" ") + "\n", "jqconsole-output");
}
};
}
//Set up the prompt:
villo.console.startPrompt = function () {
// Start the prompt with history enabled.
villo.console.jqconsole.Prompt(true, function (input) {
// Input was had!
villo.console.run(input);
// Output input with the class jqconsole-output.
//jqconsole.Write(input + '\n', 'jqconsole-output');
// Restart the prompt.
villo.console.startPrompt();
}, function(){
if(villo.console.edit === true){
return 0;
}else{
return false;
}
});
};
villo.console.startPrompt();
});
}
//Universal callback function for dumping data into the
var callback = function(transport){
villo.console.write(transport);
}
</script>
</body>
</html>