-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnotebook.html
More file actions
160 lines (148 loc) · 4.35 KB
/
notebook.html
File metadata and controls
160 lines (148 loc) · 4.35 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
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
<html>
<head>
<style>
html, body {
margin: 0;
height: 100%;
}
body {
font: 85% helvetica;
background: #eee;
}
#flexContainer {
height: 100%;
display: flex;
justify-content: space-between;
align-items: stretch;
}
#docListContainer, #docContainer, #tagTableContainer {
flex-direction: column;
padding: 0 5px;
}
#docListContainer {
width: 150px;
}
#tagTableContainer {
max-width: 250px;
}
#docContainer {
flex-grow: 1;
}
#tagTable td:nth-child(1) {
padding-right: 10px;
}
#docList li, #tagTable td {
cursor: pointer;
color: #22a;
}
#docList li:hover, #tagTable tr:hover {
background: #fff;
}
#docIframe {
background: #fff;
width: 100%;
height: 100%;
border: 0;
}
#tagTableContainer td:nth-child(2) {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
float: left;
width: 220px;
}
#tagTable {
border-collapse: collapse;
}
</style>
<script type="text/javascript" charset="utf-8">
webstrate.on("loaded", function(webstrateId) {
var docNameInput = document.getElementById("docNameInput");
var docAddButton = document.getElementById("docAddButton");
var docList = document.getElementById("docList");
var docContainer = document.getElementById("docContainer");
var docIframe;
var tagTableContainer = document.getElementById("tagTableContainer");
var tagTable = document.createElement("table");
tagTable.setAttribute("id", "tagTable");
var tagTableTransient = document.createElement("transient");
tagTableTransient.appendChild(tagTable);
tagTableContainer.appendChild(tagTableTransient);
function showDocument(docName) {
docIframe = document.createElement("iframe");
docIframe.setAttribute("src", webstrateId + "-" + docName);
docIframe.setAttribute("id", "docIframe");
var docIframeTransient = document.createElement("transient");
docIframeTransient.appendChild(docIframe);
docContainer.innerHTML = "";
docContainer.appendChild(docIframeTransient);
docIframe.webstrate.on("transcluded", function(iframeWebstrateId) {
updateTags(docIframe.contentWindow.webstrate.tags());
docIframe.contentWindow.webstrate.on("tag", function() {
updateTags(docIframe.contentWindow.webstrate.tags());
});
});
if (!document.getElementById("tagNameInput")) {
var tagNameInput = document.createElement("input");
tagNameInput.setAttribute("type", "text");
tagNameInput.setAttribute("placeholder", "Tag...");
tagNameInput.setAttribute("id", "tagNameInput");
tagTableTransient.appendChild(tagNameInput);
var tagAddButton = document.createElement("button");
tagAddButton.innerHTML = "Add";
tagTableTransient.appendChild(tagAddButton);
tagAddButton.addEventListener("click", function() {
if (!tagNameInput.value) return;
docIframe.contentWindow.webstrate.tag(tagNameInput.value);
tagNameInput.value = "";
});
}
}
function updateTags(tags) {
tagTable.innerHTML = "";
Object.keys(tags).forEach(function(version) {
tagTable.insertAdjacentHTML("beforeend",
`<tr><td>${version}</td><td>${tags[version]}</td></tr>`);
})
}
docAddButton.addEventListener("click", function() {
if (!docNameInput.value) return;
var docName = docNameInput.value;
docList.insertAdjacentHTML("beforeend", `<li>${docName}</li>`);
showDocument(docName);
docIframe.webstrate.on("transcluded", function(iframeWebstrateId) {
if (!docIframe.contentDocument.body.getAttribute("contenteditable")) {
docIframe.contentDocument.body.innerHTML = `<h1>${docName}</h1>`;
docIframe.contentDocument.body.setAttribute("contenteditable", "");
}
});
docNameInput.value = "";
});
docList.addEventListener("click", function(ev) {
if (ev.target.tagName.toLowerCase() !== "li") return;
var docName = ev.target.innerText;
showDocument(docName);
});
tagTable.addEventListener("click", function(ev) {
if (!ev.target.closest("tr")) return;
var version = parseInt(ev.target.closest("tr").children[0].innerText);
docIframe.contentWindow.webstrate.restore(version);
});
});
</script>
</head>
<body>
<div id="flexContainer">
<div id="docListContainer">
<h2>Documents</h2>
<ol id="docList"></ol>
<input id="docNameInput" type="text" placeholder="Name..."/>
<button id="docAddButton">Add</button>
</div>
<div id="docContainer"></div>
<div id="tagTableContainer">
<h2>Tags</h2>
</div>
</div>
</body>
</html>