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

View File

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