-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
166 lines (152 loc) · 5.47 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
157
158
159
160
161
162
163
164
165
166
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Katana Interview</title>
<link rel="icon" type="image/png" href="favicon.ico">
<!-- Firebase -->
<script src="firebase-8.3.1/firebase-app.js"></script>
<script src="firebase-8.3.1/firebase-auth.js"></script>
<script src="firebase-8.3.1/firebase-database.js"></script>
<!-- Ace Editor -->
<script src="ace-1.4.12/ace.js"></script>
<!-- Languages -->
<script src="ace-1.4.12/mode-text.js"></script>
<script src="ace-1.4.12/mode-c_cpp.js"></script>
<script src="ace-1.4.12/mode-csharp.js"></script>
<script src="ace-1.4.12/mode-golang.js"></script>
<script src="ace-1.4.12/mode-java.js"></script>
<script src="ace-1.4.12/mode-python.js"></script>
<!-- Themes -->
<script src="ace-1.4.12/theme-textmate.js"></script>
<!-- Keybindings -->
<script src="ace-1.4.12/keybinding-vim.js"></script>
<script src="ace-1.4.12/keybinding-emacs.js"></script>
<script src="ace-1.4.12/keybinding-sublime.js"></script>
<script src="ace-1.4.12/keybinding-vscode.js"></script>
<!-- Firepad -->
<link rel="stylesheet" href="firepad-1.5.9/firepad.css" />
<script src="firepad-1.5.9/firepad.min.js"></script>
<style>
html { height: 100%; }
body { margin: 0; height: 100%; }
#firepad-container {
visibility: hidden;
width: 100%;
height: 100%;
}
#config-fields {
position: fixed;
top: 0;
right: 10px;
margin: 10px;
padding: 10px;
border: 1px solid black;
}
</style>
</head>
<body onload="init()">
<div id="firepad-container"></div>
<div id="config-fields">
<a style="text-align:center; font-size: 1.67em; font-weight: bold;">Configuration</a>
<span style="display: block; margin-bottom: 0.4em;"></span>
<a style="font-size=1.17em; font-weight: bold;">Language: </a>
<select name="language" id="language-select">
<option value="text">Text</option>
<option value="c_cpp">C/C++</option>
<option value="csharp">C#</option>
<option value="golang">Go</option>
<option value="java">Java</option>
<option value="javascript">JavaScript</option>
<option value="python">Python</option>
</select>
<span style="display: block; margin-bottom: 0.4em;"></span>
<a style="font-size=1.17em; font-weight: bold;">Keybindings: </a>
<select name="keybinding" id="keybinding-select">
<option value="default">Ace</option>
<option value="ace/keyboard/vim">Vim</option>
<option value="ace/keyboard/emacs">Emacs</option>
<option value="ace/keyboard/sublime">Sublime</option>
<option value="ace/keyboard/vscode">VSCode</option>
</select>
</div>
<script>
//// Helper to get hash from end of URL or generate a random one.
function getRef() {
var ref = firebase.database().ref("public");
var hash = window.location.hash.replace(/#/g, '');
if (hash) {
ref = ref.child(hash);
} else {
ref = ref.push(); // generate unique location.
window.location = window.location + '#' + ref.key; // add it as a hash to the URL.
}
return ref;
}
function today() {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();
return mm + '/' + dd + '/' + yyyy;
}
function initEditor() {
//// Get Firebase Database reference.
var firepadRef = getRef();
//// Create ACE
var editor = ace.edit("firepad-container");
editor.setTheme("ace/theme/textmate");
editor.$blockScrolling = Infinity;
editor.setShowPrintMargin(false);
var session = editor.getSession();
session.setUseWrapMode(true);
session.setUseWorker(false);
session.setMode("ace/mode/text");
session.setUseSoftTabs(true);
session.setTabSize(2);
//// Create Firepad.
var firepad = Firepad.fromACE(firepadRef, editor);
firepad.on('ready', function() {
if (editor.getValue() === "") {
session.setValue("Interview " + today() + " <CANDIDATE>" + "\n".repeat(40));
}
document.getElementById("firepad-container").style.visibility = "visible";
});
var languageSelector = document.getElementById("language-select");
languageSelector.onchange = function() {
session.setMode("ace/mode/" + languageSelector.value);
};
var keybindingSelector = document.getElementById("keybinding-select");
keybindingSelector.onchange = function() {
var value = keybindingSelector.value;
if (value === "default") {
editor.setKeyboardHandler(null);
} else {
editor.setKeyboardHandler(value);
}
};
}
function init() {
//// Initialize Firebase.
var firebaseConfig = {
apiKey: "AIzaSyCJ3plB5z_C1oFVUkjI3NgbnEXO5DWAGlM",
authDomain: "katanagraph-interview.firebaseapp.com",
projectId: "katanagraph-interview",
storageBucket: "katanagraph-interview.appspot.com",
messagingSenderId: "71531395473",
appId: "1:71531395473:web:fc5aec90c2baa75fd7c230"
};
//// Initialize Firebase
var authInitialized = false;
firebase.initializeApp(firebaseConfig);
firebase.auth().onAuthStateChanged((user) => {
if (user && !authInitialized) {
authInitialized = true;
initEditor();
}
});
firebase.auth().signInAnonymously();
}
</script>
</body>
</html>