-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
87 lines (73 loc) · 2.86 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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>netitor demo</title>
<link rel="stylesheet" href="demo/styles.css">
</head>
<body>
<section>
<div id="editor"></div>
<div id="nfo"></div>
<div id="output"></div>
</section>
<save-sketch></save-sketch>
<script src="build/netitor.js"></script>
<script src="demo/helper-functions.js"></script>
<script src="demo/save-sketch.js"></script>
<script>
const ne = new Netitor({
ele: '#editor',
render: '#output',
renderWithErrors: true,
// theme: 'moz-light',
language: 'html',
code: '<h1>Hello World Wide Web</h1>'
})
// •.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•
// •.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸ examples for saving/loading to URL
// if there is code saved in the URL load it to the editor
if (ne.hasCodeInHash) ne.loadFromHash()
// here we're creating a shortcut to save the current sketch to the URL
// if when the user either presses Ctrl+S or ⌘+S
window.addEventListener('keydown', (e) => {
// console.log(e.key);
if((e.ctrlKey || e.metaKey) && e.key === 's'){
e.preventDefault()
ne.saveToHash() // update the address bar w/the code hash
// <save-sketch> is a custom element that creates the save dialogue
// located in demo/save-sketch.js of this repo
document.querySelector('save-sketch').displaySaveDialogue()
}
})
// •.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•
// •.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•*•.¸¸¸.•* handling Netitor's events
reset()
ne.on('lint-error', (eve) => {
// console.log('lint-error', eve)
markErrors(eve)
})
ne.on('edu-info', (eve) => {
// console.log('edu-info', eve)
// just one example for how u might make use of our built in edu info
if (eve.nfo) {
ne.spotlight(eve.line)
document.querySelector('#nfo').className = ''
if (eve.language === 'html') showHTMLNFO(eve)
else if (eve.language === 'css') showCSSNFO(eve)
else if (eve.language === 'javascript') showJSNFO(eve)
}
})
ne.on('cursor-activity', (eve) => {
// console.log('cursor-activity', eve)
// in this example we're not using the cursor info returned by this
// event, instead we're just using the notice of such an event to
// reset the #nfo element of any prior info or error messages
reset()
})
ne.on('hint-select', (eve) => {
// console.log('hint-select', eve)
})
</script>
</body>
</html>