From 7b112c537663b89d2769d40f1e712f4fee38d3f1 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 3 Apr 2016 15:01:21 +0000 Subject: [PATCH] Adding a work-in-progress wiki using Markdeep. Plus a pile of unrelated small changes I've accrued. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3186 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/index.html | 2 +- core/terminal.js | 2 +- packages/cory/index/index.js | 4 +- packages/cory/wiki/wiki.js | 152 +++++++++++++++++++++++++++++++++++ packages/cory/xmpp/xmpp.js | 6 +- 5 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 packages/cory/wiki/wiki.js diff --git a/core/index.html b/core/index.html index 9c7e7cfa..fac5c3ce 100644 --- a/core/index.html +++ b/core/index.html @@ -18,7 +18,7 @@ update available! refresh to update -
+
> diff --git a/core/terminal.js b/core/terminal.js index 044a582a..8514659d 100644 --- a/core/terminal.js +++ b/core/terminal.js @@ -110,7 +110,7 @@ Terminal.prototype.clear = function() { } Terminal.prototype.ping = function() { - this.dispatch({index: this._index - 1, lines: [{action: "ping"}]}); + this.dispatch({action: "ping"}); } Terminal.prototype.getOutput = function(haveIndex) { diff --git a/packages/cory/index/index.js b/packages/cory/index/index.js index 00efdb24..1e54a237 100644 --- a/packages/cory/index/index.js +++ b/packages/cory/index/index.js @@ -16,6 +16,7 @@ function index() { usersByApp["/~" + user.packageOwner + "/" + user.packageName].push(user.name); } + terminal.cork(); terminal.clear(); terminal.print("Available applications [active users]:"); packages.sort(function(x, y) { @@ -47,7 +48,8 @@ function index() { {href: "/~" + app.owner + "/" + app.name}, message); }); + terminal.uncork(); }); } -index(); +index(); \ No newline at end of file diff --git a/packages/cory/wiki/wiki.js b/packages/cory/wiki/wiki.js new file mode 100644 index 00000000..c4df8319 --- /dev/null +++ b/packages/cory/wiki/wiki.js @@ -0,0 +1,152 @@ +"use strict"; + +terminal.setEcho(false); + +core.register("onInput", function(input) { + if (input == "new page") { + editPage("new", ""); + } else if (input == "submit") { + submitNewPost().then(renderBlog); + } else if (input == "home") { + renderIndex(); + } else if (input.substring(0, 5) == "open:") { + var title = input.substring(5); + database.get(title).then(function(contents) { + editPage(title, contents); + }); + } else if (input.substring(0, 7) == "delete:") { + terminal.clear(); + var title = input.substring(7); + terminal.print("Are you sure you want to delete page '", title, "'?"); + terminal.print({command: "confirmDelete:" + title, value: "delete it"}); + terminal.print({command: "home", value: "cancel"}); + } else if (input.substring(0, 14) == "confirmDelete:") { + var title = input.substring(14); + database.remove(title).then(renderIndex); + } +}); + +function renderIndex() { + terminal.clear(); + terminal.print("Editor Test"); + if (core.user.credentials.permissions.authenticated) { + terminal.print({command: "new page"}); + } + + database.getAll().then(function(entries) { + for (var i = 0; i < entries.length; i++) { + if (core.user.credentials.permissions.authenticated) { + terminal.print( + "* ", + {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}, + " (", + {command: "delete:" + entries[i], value: "x"}, + ")"); + } else { + terminal.print( + "* ", + {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}); + } + } + }); +} + +var gPage = null; + +core.register("onWindowMessage", function(event) { + if (event.message.ready) { + terminal.postMessageToIframe("iframe", {title: gPage.title, contents: gPage.contents}); + } else if (event.message.index) { + renderIndex(); + } else { + database.set(event.message.title, event.message.contents).then(function() { + renderIndex(); + }); + } +}); + +function editPage(title, contents) { + gPage = {title: title, contents: contents}; + terminal.clear(); + terminal.print({iframe: ` + + + + + + + + + + + + +
+ +
+
+ + `, name: "iframe", style: "width: 100%; border: 0; height: 600px"}); +} + +renderIndex(); \ No newline at end of file diff --git a/packages/cory/xmpp/xmpp.js b/packages/cory/xmpp/xmpp.js index 248680e7..a4e990f7 100644 --- a/packages/cory/xmpp/xmpp.js +++ b/packages/cory/xmpp/xmpp.js @@ -665,7 +665,7 @@ XmlStanzaParser.prototype.parseNode = function(node) { // end xmpp.js -var gFocus = false; +var gFocus = true; var gUnread = 0; function updateTitle() { @@ -792,10 +792,12 @@ var gPresence = {}; function refreshUsers() { terminal.select("users"); + terminal.cork(); terminal.clear(); for (var i in gPresence) { terminal.print(i); } + terminal.uncork(); terminal.select("terminal"); } @@ -937,7 +939,7 @@ function connect(socket, userName, password) { } refreshUsers(); } else { - terminal.print(data); + terminal.print(JSON.stringify(data)); } }); } catch (error) {