]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseuiwindow.js
Better hilighting.
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
1 qwebirc.ui.HILIGHT_NONE = 0;
2 qwebirc.ui.HILIGHT_ACTIVITY = 1;
3 qwebirc.ui.HILIGHT_SPEECH = 2;
4 qwebirc.ui.HILIGHT_US = 3;
5
6 qwebirc.ui.Window = new Class({
7 Implements: [Events],
8 initialize: function(parentObject, client, type, name, identifier) {
9 this.parentObject = parentObject;
10 this.type = type;
11 this.name = name;
12 this.active = false;
13 this.client = client;
14 this.identifier = identifier;
15 this.hilighted = qwebirc.ui.HILIGHT_NONE;
16 this.scrolltimer = null;
17 this.commandhistory = this.parentObject.commandhistory;
18 this.scrolleddown = true;
19 //new CommandHistory();
20 },
21 updateNickList: function(nicks) {
22 },
23 updateTopic: function(topic, element) {
24 qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
25 },
26 close: function() {
27 if($defined(this.scrolltimer)) {
28 $clear(this.scrolltimer);
29 this.scrolltimer = null;
30 }
31
32 this.parentObject.__closed(this);
33 this.fireEvent("close", this);
34 },
35 select: function() {
36 this.active = true;
37 this.parentObject.__setActiveWindow(this);
38 if(this.hilighted)
39 this.setHilighted(qwebirc.ui.HILIGHT_NONE);
40 if(this.scrolleddown)
41 this.scrollToBottom();
42 },
43 deselect: function() {
44 if(!this.parentObject.singleWindow)
45 this.scrolleddown = this.scrolledDown();
46 if($defined(this.scrolltimer)) {
47 $clear(this.scrolltimer);
48 this.scrolltimer = null;
49 }
50
51 this.active = false;
52 },
53 addLine: function(type, line, colour, element) {
54 var hilight = qwebirc.ui.HILIGHT_NONE;
55 if(type) {
56 hilight = qwebirc.ui.HILIGHT_ACTIVITY;
57
58 if(type.match(/(NOTICE|ACTION|MSG)$/)) {
59 if(this.type == qwebirc.ui.WINDOW_QUERY) {
60 hilight = qwebirc.ui.HILIGHT_US
61 } else if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
62 hilight = qwebirc.ui.HILIGHT_US;
63 } else {
64 hilight = qwebirc.ui.HILIGHT_SPEECH;
65 }
66 }
67 }
68
69 if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE))
70 this.setHilighted(hilight);
71
72 if(type)
73 line = this.parentObject.theme.message(type, line, hilight == qwebirc.ui.HILIGHT_US);
74
75 qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
76 this.scrollAdd(element);
77 },
78 errorMessage: function(message) {
79 this.addLine("", message, "red");
80 },
81 setHilighted: function(state) {
82 if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted)
83 this.hilighted = state;
84 },
85 scrolledDown: function() {
86 if(this.scrolltimer)
87 return true;
88
89 var parent = this.lines;
90
91 var prev = parent.getScroll();
92 var prevbottom = parent.getScrollSize().y;
93 var prevsize = parent.getSize();
94
95 /* fixes an IE bug */
96 if(prevbottom < prevsize.y)
97 prevbottom = prevsize.y;
98
99 return prev.y + prevsize.y == prevbottom;
100 },
101 scrollToBottom: function() {
102 var parent = this.lines;
103 var scrollparent = parent;
104
105 if($defined(this.scroller))
106 scrollparent = this.scroller;
107
108 scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
109 },
110 scrollAdd: function(element) {
111 var parent = this.lines;
112
113 /* scroll in bursts, else the browser gets really slow */
114 if($defined(element)) {
115 var sd = this.scrolledDown();
116 parent.appendChild(element);
117 if(sd) {
118 if(this.scrolltimer)
119 $clear(this.scrolltimer);
120 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
121 }
122 } else {
123 this.scrollToBottom();
124 this.scrolltimer = null;
125 }
126 },
127 historyExec: function(line) {
128 this.commandhistory.addLine(line);
129 this.client.exec(line);
130 }
131 });