]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Clickable channels!
authorChris Porter <redacted>
Thu, 16 Oct 2008 11:51:14 +0000 (12:51 +0100)
committerChris Porter <redacted>
Thu, 16 Oct 2008 11:51:14 +0000 (12:51 +0100)
js/ui/baseuiwindow.js
js/ui/colour.js
js/ui/url.js

index 2f5877fbaa0c53162268fabb71df75364a365257..2d40f5d7b4ee40aac74ef59968ee3f259d4f9be1 100644 (file)
@@ -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);
   },
index 6a15bd698898e57f3b962152d794f4a3c44543f0..2ac575158dca7de005847a5cbec4bb307f6d0be4 100644 (file)
@@ -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 = [];
     }
index 3245ec3cae5fc1e446ac7ff61fa7b5f8d06b66a0..16ee8c9a9dbe1d421ffd81540892791811d20e07 100644 (file)
@@ -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);
 }