Okay, works. Huh.

This commit is contained in:
Neale Pickett 2014-10-27 22:57:07 -06:00
parent 576a2c975a
commit 256733ce81
2 changed files with 22 additions and 12 deletions

View File

@ -6,16 +6,17 @@ var networks = {};
function networkConnect(network, baseURL, authtok) { function networkConnect(network, baseURL, authtok) {
var eventSource; var eventSource;
var element = getTemplate("server-channels"); var element = getTemplate("server-channels");
var channels = element.getElementByClassName("channels")[0]; var channels = element.getElementsByClassName("channels")[0];
var roomElement = element.getElementsByClassName("server")[0]; var roomElement = element.getElementsByClassName("server")[0];
var rooms = {".": room}; var rooms = {".": roomElement};
newRoom(roomElement, element, network, maxScrollback); newRoom(roomElement, element, network, maxScrollback);
function newRoom(name) { function makeRoom(name) {
var rElement = getTemplate("channel"); var rElement = getTemplate("channel");
newRoom(rElement, element, name, maxScrollback); newRoom(rElement, element, name, maxScrollback);
channels.appendChild(rElement); channels.appendChild(rElement);
rooms[name] = rElement; rooms[name] = rElement;
return rElement;
} }
function handleEventSourceLine(line) { function handleEventSourceLine(line) {
@ -31,7 +32,7 @@ function networkConnect(network, baseURL, authtok) {
var room = rooms[forum]; var room = rooms[forum];
if (! room) { if (! room) {
room = newRoom(forum); room = makeRoom(forum);
} }
// XXX: Handle differently based on command // XXX: Handle differently based on command
@ -63,7 +64,6 @@ function networkConnect(network, baseURL, authtok) {
form.append("network", network); form.append("network", network);
form.append("target", target); form.append("target", target);
form.append("text", text); form.append("text", text);
console.log(form);
var oReq = new XMLHttpRequest(); var oReq = new XMLHttpRequest();
oReq.addEventListener("error", handleError); oReq.addEventListener("error", handleError);
@ -86,4 +86,6 @@ function networkConnect(network, baseURL, authtok) {
eventSource = new EventSource(pullURL); eventSource = new EventSource(pullURL);
eventSource.addEventListener("message", handleEventSourceMessage); eventSource.addEventListener("message", handleEventSourceMessage);
eventSource.addEventListener("error", handleEventSourceError); eventSource.addEventListener("error", handleEventSourceError);
document.getElementsByClassName("rooms")[0].appendChild(element);
} }

View File

@ -50,10 +50,12 @@ var visibleRoom;
function newRoom(element, network, name, maxSize) { function newRoom(element, network, name, maxSize) {
var messages = getTemplate("messages"); var messages = getTemplate("messages");
if (! maxsize) { var lastmsg;
if (! maxSize) {
maxSize = 500; maxSize = 500;
} }
element.addMessage = function(timestamp, command, source, content) { element.addMessage = function(timestamp, command, source, content) {
var message = getTemplate("message"); var message = getTemplate("message");
@ -61,9 +63,10 @@ function newRoom(element, network, name, maxSize) {
var eSource = message.getElementsByClassName("source")[0]; var eSource = message.getElementsByClassName("source")[0];
var eContent = message.getElementsByClassName("content")[0]; var eContent = message.getElementsByClassName("content")[0];
message.nodeList.add(command); message.classList.add("update");
if (source = ".") { message.classList.add(command);
message.nodeList.add("self"); if (source == ".") {
message.classList.add("self");
} }
eTimestamp.textContent = timestamp.toLocaleTimeString(); eTimestamp.textContent = timestamp.toLocaleTimeString();
@ -77,14 +80,16 @@ function newRoom(element, network, name, maxSize) {
messages.removeChild(element.firstChild); messages.removeChild(element.firstChild);
} }
lastmsg = message;
if (visibleRoom == element) { if (visibleRoom == element) {
message.scrollIntoView(false); lastmsg.scrollIntoView(false);
} }
} }
element.hide = function() { element.hide = function() {
element.classList.remove("selected"); element.classList.remove("selected");
messages.classList.add("hidden"); messages.style.display = "none";
} }
element.show = function() { element.show = function() {
@ -92,7 +97,8 @@ function newRoom(element, network, name, maxSize) {
visibleRoom.hide() visibleRoom.hide()
} }
element.classList.add("selected"); element.classList.add("selected");
messages.classList.remove("hidden"); messages.style.display = null;
lastmsg.scrollIntoView(false);
visibleRoom = element; visibleRoom = element;
} }
@ -109,5 +115,7 @@ function newRoom(element, network, name, maxSize) {
element.addEventListener("click", clicked); element.addEventListener("click", clicked);
element.getElementsByClassName("content-item")[0].textContent = name; element.getElementsByClassName("content-item")[0].textContent = name;
document.getElementById("messages-container").appendChild(messages);
return element; return element;
} }