From: Chris Porter Date: Thu, 16 Oct 2008 11:51:14 +0000 (+0100) Subject: Clickable channels! X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/commitdiff_plain/dbd616675bc500a59609534d917dab632bf9d7b4 Clickable channels! --- diff --git a/js/ui/baseuiwindow.js b/js/ui/baseuiwindow.js index 2f5877f..2d40f5d 100644 --- a/js/ui/baseuiwindow.js +++ b/js/ui/baseuiwindow.js @@ -50,7 +50,7 @@ var UIWindow = new Class({ if(type) line = this.parentObject.theme.message(type, line); - Colourise(IRCTimestamp(new Date()) + " " + line, element); + Colourise(IRCTimestamp(new Date()) + " " + line, element, this.client.exec); this.scrollAdd(element); }, diff --git a/js/ui/colour.js b/js/ui/colour.js index 6a15bd6..2ac5751 100644 --- a/js/ui/colour.js +++ b/js/ui/colour.js @@ -1,4 +1,4 @@ -function Colourise(line, entity) { +function Colourise(line, entity, execfn) { var fg; var bg; var underline = false; @@ -44,7 +44,7 @@ function Colourise(line, entity) { function emitEndToken() { if(out.length > 0) { - urlificate(element, out.join("")); + urlificate(element, out.join(""), execfn); entity.appendChild(element); out = []; } diff --git a/js/ui/url.js b/js/ui/url.js index 3245ec3..16ee8c9 100644 --- a/js/ui/url.js +++ b/js/ui/url.js @@ -1,8 +1,28 @@ var url_re = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/; +var chan_re = /\B#[^ ,]+/; -function urlificate(element, text) { +function txtprocess(text, regex, appendfn, matchfn) { + for(;;) { + var index = text.search(regex); + if(index == -1) { + appendfn(text); + break; + } + var match = text.match(regex); + + var before = text.substring(0, index); + var matched = match[0]; + var after = text.substring(index + matched.length); + + text = after; + appendfn(before); + matchfn(matched); + } +} + +function urlificate(element, text, execfn) { function appendText(text) { - element.appendChild(document.createTextNode(text)); + chanficate(element, text, execfn); } function appendA(text) { var a = document.createElement("a"); @@ -12,20 +32,23 @@ function urlificate(element, text) { element.appendChild(a); } - - for(;;) { - var index = text.search(url_re); - if(index == -1) { - appendText(text); - break; - } - var match = text.match(url_re); - - before = text.substring(0, index); - matched = match[0]; - after = text.substring(index + matched.length); - text = after; - appendText(before); - appendA(matched, before); + txtprocess(text, url_re, appendText, appendA); +} + +function chanficate(element, text, execfn) { + function appendText(text) { + element.appendChild(document.createTextNode(text)); + } + function appendA(text) { + var a = document.createElement("a"); + a.href = "#"; + a.addEvent("click", function(e) { + new Event(e).stop(); + execfn("/JOIN " + text); + }); + a.appendChild(document.createTextNode(text)); + + element.appendChild(a); } + txtprocess(text, chan_re, appendText, appendA); }