summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthewsotoudeh <matthewsot@outlook.com>2016-01-24 01:15:59 -0800
committermatthewsotoudeh <matthewsot@outlook.com>2016-01-24 01:15:59 -0800
commit70bb1dc9bc519996ca77674709fbcf449510b32d (patch)
treeb52141f9584c19e862b4db2f314b6ac64c06c8da
parent3d9bbd6d6838655ce08db07efa2d2f7c84a54c93 (diff)
basic version of ecrit-presentation
-rw-r--r--ecrit-presentation.js30
-rw-r--r--index.html2
2 files changed, 28 insertions, 4 deletions
diff --git a/ecrit-presentation.js b/ecrit-presentation.js
index 66a2743..27e8289 100644
--- a/ecrit-presentation.js
+++ b/ecrit-presentation.js
@@ -1,13 +1,37 @@
ecrit.presentation = {};
-ecrit.presentation.Watcher = function (document) {
+ecrit.presentation.Watcher = function (document, presentationDiv) {
document.on("nodeInserted", this.nodeInsertionHandler);
document.on("nodeRemoved", this.nodeRemovalHandler);
};
ecrit.presentation.Watcher.prototype.nodeInsertionHander = function (data) {
data.node.on("nodeInserted", this.nodeInsertionHandler);
- if (data.node.type === "TestSpan") {
- data.node.on("textModified", this.textModifiedHandler);
+ var parentEl = document.querySelector("[data-ecrit-id=\"" + data.node.parent.id + "\"]");
+ switch (data.node.type) {
+ case "Paragraph":
+ var newEl = document.createElement("p");
+ newEl.setAttribute("data-ecrit-id", data.node.id);
+
+ if (data.index === parentEl.childNodes.length) {
+ parentEl.appendChild(newEl);
+ }
+ else {
+ parentEl.insertBefore(newEl, parentEl.childNodes[data.index]);
+ }
+ break;
+ case "TextSpan":
+ data.node.on("textModified", this.textModifiedHandler);
+ var newEl = document.createElement("span");
+ newEl.setAttribute("data-ecrit-id", data.node.id);
+ newEl.textContent = data.node.text;
+
+ if (data.index === parentEl.childNodes.length) {
+ parentEl.appendChild(newEl);
+ }
+ else {
+ parentEl.insertBefore(newEl, parentEl.childNodes[data.index]);
+ }
+ break;
}
};
diff --git a/index.html b/index.html
index cf4bbed..6ffcafb 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,7 @@
<head>
</head>
<body>
- <div id="presentation"></div>
+ <div id="presentation" data-ecrit-id="root"></div>
<script type="text/javascript" src="ecrit-core.js" />
<script type="text/javascript" src="ecrit-presentation.js" />
<script type="text/javascript" src="ecrit-test.js" />
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback