This repository was archived by the owner on Oct 4, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 883
/
Copy pathcode.html
75 lines (67 loc) · 2.58 KB
/
code.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
<!doctype html>
<!-- See http://www.firepad.io/docs/ for detailed embedding docs. -->
<html>
<head>
<metacharset="utf-8" />
<!-- Firebase -->
<scriptsrc="https://www.gstatic.com/firebasejs/5.5.4/firebase.js"></script>
<!-- CodeMirror and its JavaScript mode file -->
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/codemirror.js"></script>
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/mode/javascript/javascript.js"></script>
<linkrel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/codemirror.css" />
<!-- Firepad -->
<linkrel="stylesheet" href="https://firepad.io/releases/v1.5.9/firepad.css" />
<scriptsrc="https://firepad.io/releases/v1.5.9/firepad.min.js"></script>
<style>
html { height:100%; }
body { margin:0; height:100%; position: relative; }
/* Height / width / positioning can be customized for your use case.
For demo purposes, we make firepad fill the entire browser. */
#firepad-container {
width:100%;
height:100%;
}
</style>
</head>
<bodyonload="init()">
<divid="firepad-container"></div>
<script>
functioninit(){
//// Initialize Firebase.
//// TODO: replace with your Firebase project configuration.
varconfig={
apiKey: '<API_KEY>',
authDomain: "firepad-gh-tests.firebaseapp.com",
databaseURL: "https://firepad-gh-tests.firebaseio.com"
};
firebase.initializeApp(config);
//// Get Firebase Database reference.
varfirepadRef=getExampleRef();
//// Create CodeMirror (with line numbers and the JavaScript mode).
varcodeMirror=CodeMirror(document.getElementById('firepad-container'),{
lineNumbers: true,
mode: 'javascript'
});
//// Create Firepad.
varfirepad=Firepad.fromCodeMirror(firepadRef,codeMirror,{
defaultText: '// JavaScript Editing with Firepad!\nfunction go() {\n var message = "Hello, world.";\n console.log(message);\n}'
});
}
// Helper to get hash from end of URL or generate a random one.
functiongetExampleRef(){
varref=firebase.database().ref();
varhash=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.
}
if(typeofconsole!=='undefined'){
console.log('Firebase data: ',ref.toString());
}
returnref;
}
</script>
</body>
</html>