-
Notifications
You must be signed in to change notification settings - Fork 4
/
elements.js
102 lines (97 loc) · 3.13 KB
/
elements.js
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
function protocolObject(event) {
let div = document.createElement("div")
div.onclick = function () {
document.getElementById("details").innerHTML = renderProtocolEventAsMessage(event)
var repl = replies.get(event.mindmachineUID)
var orderedReplies = []
if (repl !== undefined) {
repl.forEach(function (e) {
// var replyDiv = document.createElement("div")
// replyDiv.innerHTML = e.content
orderedReplies.push(e)
//document.getElementById("details").appendChild(renderReply(e))
})
orderedReplies.sort(function (a, b) {
return a.created_at > b.created_at
})
orderedReplies.forEach(function (e) {
document.getElementById("details").appendChild(renderReply(e))
})
}
document.getElementById("details").appendChild(replybox(event.mindmachineUID))
}
//div.innerHTML = `<div class="box">` + `<span class="tag is-primary">` + event.tags[0][1] + `</span>` + event.content + `</div>`;
div.innerHTML = renderProtocolEventAsMessage(event);
div.id = event.id
return div
}
function replybox(id) {
let div = document.createElement("div")
let textbox = document.createElement("textarea")
textbox.className = "textarea"
textbox.id = "reply"
let submitbtn = document.createElement("button")
submitbtn.textContent = "Comment"
submitbtn.className = "button is-primary"
submitbtn.onclick = function () {
if (hasPermanym(storedPubkey)) {
makeNote(textbox.value, id)
textbox.value = ""
} else {
alert("Go to the My Account page and create a username first")
}
}
div.appendChild(textbox)
div.appendChild(submitbtn)
return div
}
function print(t) {
console.log(t)
}
function renderReply(e) {
let article = document.createElement("article")
article.className = "message is-primary"
let div = document.createElement("div")
div.className = "message-body"
div.innerText = e.content
article.appendChild(div)
return article
}
function renderProtocolEventAsMessage(event) {
let objType = event.tags[0][1];
let article = `<article class="message `;
switch (objType) {
case objType = "Definition": {
article += `is-info`
break
}
case objType = "Goal": {
article += `is-link`
break
}
case objType = "Rule": {
article += `is-warning`
break
}
case objType = "Invariant": {
article += `is-danger`
break
}
case objType = "Protocol": {
article += `is-dark`
break
}
}
article += `">`
article += `<div class="message-header">`
article += `<p>`
article += `[` + event.tags[0][1] + `] `
article += event.content
article += `</p>`
article += `</div>`
article += `<div class="message-body">`
article += `SUID: ` + event.mindmachineUID + ` `
article += `</div>`
article += `</article>`
return article
}