-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
295 lines (274 loc) · 13.9 KB
/
index.html
File metadata and controls
295 lines (274 loc) · 13.9 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html ng-app="editor">
<head>
<title>Code Editor</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src='https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js'></script>
<style type="text/css" media="screen">
#editor {
font-family: 'Source Code Pro', monospace;
font-size: 16px;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#sharing-url {
word-break: break-all;
}
</style>
</head>
<body >
<div id="editor-container" class="container-fluid" ng-controller="EditorController">
<div id="editor" ui-ace="{theme:'monokai',
mode: 'java', onLoad: aceLoaded}">
<div id="loading-screen" class="text-center">
<h1>Loading</h1>
<p>Please wait...</p>
<i class="fa fa-circle-o-notch fa-4x fa-spin" style="color: black;"></i>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="urlModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Share Code</h4>
</div>
<div class="modal-body">
Copy this url: <br><a id='sharing-url' href=''></a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Done</button>
</div>
</div>
</div>
</div>
</div>
<div id="script-container">
<script src="static/js/lib/jquery.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js'></script>
<script src="static/js/lib/bootstrap.min.js" crossorigin="anonymous"></script>
<script src="static/js/lib/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ext-spellcheck.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ext-searchbox.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ext-beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/mode-java.js"></script>
<script src="static/js/lib/ui.ace.angular.js"></script>
<script src="static/js/lib/lz-string.js"></script>
<script>
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
</script>
<script>
angular.module('editor', ['ui.ace'])
.controller('EditorController', ['$scope', function ($scope) {
$scope.url = "https://mustangrobotics.club/editor.html";
function configureEditorLang(url, _editor) {
var ext = url.substr(url.lastIndexOf('.') + 1);
if (ext == "js") {
_editor.getSession().setMode("ace/mode/javascript");
} else if (ext == "md") {
_editor.getSession().setMode("ace/mode/markdown");
} else if (ext == "java") {
_editor.getSession().setMode("ace/mode/java");
} else if (ext == "groovy" || ext == "gradle") {
_editor.getSession().setMode("ace/mode/groovy");
}
}
function getFromRawSource(url, _editor) {
if (url == null) {
console.error("Cowardly refusing to attempt to fetch from self!");
return;
}
console.log("Getting " + url);
$.get(url, function (data) {
if (data != null) {
_editor.setValue(data);
_editor.clearSelection();
} else {
_editor.setValue('// An error occurred :(');
_editor.clearSelection();
}
}).fail(function () {
_editor.setValue('// An error occurred :(\n' +
"\t// Just in case you want to know I was trying to fetch:\n" +
"\t// '" + url + "'");
_editor.clearSelection();
});
}
$scope.aceLoaded = function (_editor) {
var data = getParameterByName('c');
var gitHub = getParameterByName('gh');
var gitHubBranch = getParameterByName('br');
//console.log(data);
function loadData() {
var json;
try {
json = atob(data);
} catch (e) {
console.log(e);
_editor.setValue("// Corrupted Data! Cannot continue. :(");
}
if (json == null || json == '') {
_editor.setValue('');
} else {
console.log(data);
var code = json;
if (code != null) {
console.log(code);
var codeData = angular.fromJson(code);
_editor.setValue(codeData);
} else {
console.log("Attempting to parse failed");
_editor.setValue("// Failed to load the data. Sorry :(\n" +
+ "// Just in case you want to know I was trying to fetch '" + url + "'");
}
}
}
function configureEditorToDefaults() {
_editor.setValue(
'public class Main {\n' +
'\tpublic static void main(String... args) {\n' +
'\t\tSystem.out.println("Hello, World! I may not be ready to see you, but #imaginethis.");\n' +
'\t}\n}');
}
function getBranch() {
if (gitHub.includes('!')) {
gitHubBranch = gitHub.substr(gitHub.lastIndexOf('!') + 1);
if (gitHubBranch.includes('>')) {
gitHubBranch = gitHubBranch.substr(0, gitHubBranch.lastIndexOf('>'));
}
gitHub = gitHub.replace('!' + gitHubBranch, "");
} else {
console.log("No branch was specified! Defaulting to 'master'");
gitHubBranch = 'master';
}
}
function resolvePath() {
if (gitHub.includes('>')) {
path = gitHub.substr(gitHub.lastIndexOf('>') + 1);
gitHub = gitHub.replace('>' + path, '');
}
if (path == null || path == "") {
path = 'README.md';
}
}
if (data == null) {
var url = getParameterByName('url');
var linkData = getParameterByName('l');
if (url != null) {
getFromRawSource(url, _editor);
configureEditorLang(url, _editor);
} else if (linkData != null) {
getFromRawSource('http://snapedit.azurewebsites.net/code.php?i=' + linkData, _editor);
// configureEditorLang(url, _editor);
} else if (gitHub != null || gitHubBranch != null) {
if (gitHub == null && gitHubBranch != null) {
_editor.setValue("// A Git branch was specified, but no repo. I also need the repo! Thanks ;)")
} else if (gitHub != null && gitHubBranch == null) {
gitHub = gitHub.replace('%3E', '>'); // Resolve the html escape sequence to the proper symbol
console.log(gitHub);
getBranch();
}
if (gitHub != null && gitHubBranch != null) {
var path = getParameterByName('gp');
if (path == null) {
resolvePath();
}
// url = 'https://raw.githubusercontent.com/' + gitHub + "/" + gitHubBranch + "/" + path
getFromRawSource('https://raw.githubusercontent.com/' + gitHub + "/" + gitHubBranch + "/" + path, _editor);
configureEditorLang(path, _editor);
}
} else {
configureEditorToDefaults();
}
} else {
loadData();
}
_editor.clearSelection();
_editor.commands.addCommand({
name: 'save',
bindKey: {win: 'Ctrl-M', mac: 'Command-M'},
exec: function (editor) {
$scope.saveCode(editor);
},
readOnly: true // false if this command should not apply in readOnly mode
});
};
$scope.saveCode = function (_editor) {
var code = _editor.getValue();
code = code.replace(/[^@\\\{}\[\]\.,:!#\$\^%\*\(\);"'<>\+=\-_\/\w\s]/gi, '');
$.post('http://snapedit.azurewebsites.net/code.php?add=5', angular.toJson({"code":code}))
.done(function(data) {
var url = "http://snapedit.azurewebsites.net/?l=" + data;
console.log(data);
$scope.url = url;
var modal = $('#urlModal');
var url_id = $('#sharing-url');
url_id.attr('href', url);
url_id.text(url);
modal.modal('show');
});
/* var data = "https://mustangrobotics.club/editor.html?c=" + btoa(angular.toJson(code));
console.log(data);
$scope.url = data;
var modal = $('#urlModal');
var url = $('#sharing-url');
url.attr('href', data);
url.text(data);
modal.modal('show'); --> */
}
}]);
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
</script>
<script src="assets/js/lib/flowtype.js"></script>
<script>
$('#editor').flowtype({
minFont: 10,
maxFont: 36,
fontRatio: 85
});
</script>
<script type="text/javascript">
WebFontConfig = {
google: {families: ['Source+Code+Pro::latin']}
};
(function () {
var wf = document.createElement('script');
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
</script>
</div>
</body>
</html>