-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (44 loc) · 1.46 KB
/
Copy pathapp.js
File metadata and controls
55 lines (44 loc) · 1.46 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
/* Single File ToDo App
*/
console.log('Hello world. SFA loaded.')
const dom = document
console.log('location: ', dom.location)
const here = dom.location.href
const thisDoc = $rdf.sym(here)
const store = new $rdf.LiveStore()
async function save (dom) {
console.log('Saving ...', thisDoc)
const targetURI = thisDoc.uri + ".edited.html"
console.log('Saving dom...', dom)
const contentType = 'text/html'
const data = '<html>\n' + dom.head.outerHTML + '\n' + dom.body.outerHTML + '\n</html>\n'
console.log('Data to save <<<' + data + '>>>')
if (confirm('Saving to ' + targetURI)) {
try {
await store.fetcher.webOperation('PUT', targetURI, { data, contentType })
} catch (err) {
const message = 'Save ' + targetURI + ' failed: ' + err
console.error(message)
alert(message)
}
} else {
console.log('Aborted by user')
}
}
function saveButton () {
const button = dom.createElement('button');
button.textContent = "Save";
return button
}
function main (){
const h1 = dom.createElement('h1')
console.log('dom.body', dom.body)
const body = dom.body
dom.body.append(h1)
h1.textContent = "Hello Single Page ToDo App"
const button = saveButton(dom)
body.append(button)
button.addEventListener('click', _event => save(dom))
console.log('main done.')
}
dom.addEventListener("DOMContentLoaded", main)