]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/theme.js
Better hilighting.
[irc/quakenet/qwebirc.git] / js / ui / theme.js
1 qwebirc.ui.themes.ThemeControlCodeMap = {
2 "C": "\x03",
3 "B": "\x02",
4 "U": "\x1F",
5 "O": "\x0F",
6 "$": "$"
7 };
8
9 qwebirc.ui.themes.Default = {
10 "PREFIX": ["$C4==$O "],
11 "SIGNON": ["Signed on!", true],
12 "CONNECT": ["Connected to server.", true],
13 "RAW": ["$m", true],
14 "DISCONNECT": ["Disconnected from server: $m", true],
15 "ERROR": ["ERROR: $m", true],
16 "SERVERNOTICE": ["$m", true],
17 "JOIN": ["$n [$h] has joined $c", true],
18 "OURJOIN": ["$n [$h] has joined $c", true],
19 "PART": ["$n [$h] has left $c [$m]", true],
20 "KICK": ["$v was kicked from $c by $n [$m]", true],
21 "MODE": ["mode/$c [$m] by $n", true],
22 "QUIT": ["$n [$h] has quit [$m]", true],
23 "NICK": ["$n has changed nick to $w", true],
24 "TOPIC": ["$n changed the topic of $c to: $m", true],
25 "UMODE": ["MODE $n $m", true],
26 "INVITE": ["$n invites you to join $c", true],
27 "HILIGHT": ["$C4"],
28 "HILIGHTEND": ["$O"],
29 "CHANMSG": ["<$z$n$Z> $m"],
30 "PRIVMSG": ["<$z$n$Z> $m"],
31 "CHANNOTICE": ["-$z$n$Z:$c- $m"],
32 "PRIVNOTICE": ["-$z$n$Z- $m"],
33 "OURCHANMSG": ["<$z$n$Z> $m"],
34 "OURPRIVMSG": ["<$z$n$Z> $m"],
35 "OURTARGETEDMSG": ["*$z$t$Z* $m"],
36 "OURTARGETEDNOTICE": ["[notice($z$t$Z)] $m"],
37 "OURCHANNOTICE": ["-$z$n$Z:$t- $m"],
38 "OURPRIVNOTICE": ["-$z$n$Z- $m"],
39 "OURCHANACTION": [" * $z$n$Z $m"],
40 "OURPRIVACTION": [" * $z$n$Z $m"],
41 "CHANACTION": [" * $z$n$Z $m"],
42 "PRIVACTION": [" * $z$n$Z $m"],
43 "CHANCTCP": ["$n [$h] requested CTCP $x from $c: $m"],
44 "PRIVCTCP": ["$n [$h] requested CTCP $x from $-: $m"],
45 "CTCPREPLY": ["CTCP $x reply from $n: $m"],
46 "OURCHANCTCP": ["[ctcp($t)] $x $m"],
47 "OURPRIVCTCP": ["[ctcp($t)] $x $m"],
48 "OURTARGETEDCTCP": ["[ctcp($t)] $x $m"],
49 "WHOISUSER": ["$B$n$B [$h]", true],
50 "WHOISREALNAME": [" realname : $m", true],
51 "WHOISCHANNELS": [" channels : $m", true],
52 "WHOISSERVER": [" server : $x [$m]", true],
53 "WHOISACCOUNT": [" account : qwebirc://qwhois/$m", true],
54 "WHOISIDLE": [" idle : $x [connected: $m]", true],
55 "WHOISAWAY": [" away : $m", true],
56 "WHOISOPER": [" : $BIRC Operator$B", true],
57 "WHOISOPERNAME": [" operedas : $m", true],
58 "WHOISACTUALLY": [" realhost : $m [ip: $x]", true],
59 "WHOISEND": ["End of WHOIS", true],
60 "AWAY": ["$n is away: $m", true],
61 "GENERICERROR": ["$m: $t", true],
62 "GENERICMESSAGE": ["$m", true]
63 };
64
65 qwebirc.ui.Theme = new Class({
66 initialize: function(themeDict) {
67 this.__theme = qwebirc.util.dictCopy(qwebirc.ui.themes.Default);
68
69 if(themeDict)
70 for(var k in themeDict)
71 this.__theme[k] = themeDict[k];
72
73 for(var k in this.__theme) {
74 if(k == "PREFIX")
75 continue;
76
77 var data = this.__theme[k];
78 if(data[1]) {
79 this.__theme[k] = this.__theme["PREFIX"] + data[0];
80 } else {
81 this.__theme[k] = data[0];
82 }
83 }
84
85 this.__ccmap = qwebirc.util.dictCopy(qwebirc.ui.themes.ThemeControlCodeMap);
86 this.__ccmaph = qwebirc.util.dictCopy(this.__ccmap);
87
88 this.__ccmap["z"] = "";
89 this.__ccmap["Z"] = "";
90
91 this.__ccmaph["z"] = this.message("HILIGHT", {}, this.__ccmap);
92 this.__ccmaph["Z"] = this.message("HILIGHTEND", {}, this.__ccmap);
93 },
94 __dollarSubstitute: function(x, h, mapper) {
95 var msg = [];
96
97 var n = x.split("");
98 for(var i=0;i<n.length;i++) {
99 var c = n[i];
100 if(c == "$" && (i <= n.length - 1)) {
101 var c2 = n[++i];
102
103 var o = mapper[c2];
104 if(!o)
105 o = h[c2];
106 if(o)
107 msg.push(o);
108 } else {
109 msg.push(c);
110 }
111 }
112
113 return msg.join("");
114 },
115 message: function(type, data, hilight) {
116 var map;
117 if(hilight) {
118 map = this.__ccmaph;
119 } else {
120 map = this.__ccmap;
121 }
122 return this.__dollarSubstitute(this.__theme[type], data, map);
123 }
124 });