]>
Commit | Line | Data |
---|---|---|
96f28062 CP |
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 | ||
e20e5a6b | 6 | qwebirc.ui.Window = new Class({ |
94b18192 CP |
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; | |
96f28062 | 15 | this.hilighted = qwebirc.ui.HILIGHT_NONE; |
381fddfd | 16 | this.scrolltimer = null; |
9b63b053 | 17 | this.commandhistory = this.parentObject.commandhistory; |
25be5960 | 18 | this.scrolleddown = true; |
52090a1f | 19 | this.lastNickHash = {}; |
3236ca77 | 20 | this.lastSelected = null; |
94b18192 CP |
21 | }, |
22 | updateNickList: function(nicks) { | |
23 | }, | |
1f06a70a | 24 | updateTopic: function(topic, element) { |
2cd9e32d | 25 | qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); |
94b18192 CP |
26 | }, |
27 | close: function() { | |
381fddfd CP |
28 | if($defined(this.scrolltimer)) { |
29 | $clear(this.scrolltimer); | |
30 | this.scrolltimer = null; | |
31 | } | |
32 | ||
94b18192 CP |
33 | this.parentObject.__closed(this); |
34 | this.fireEvent("close", this); | |
35 | }, | |
36 | select: function() { | |
37 | this.active = true; | |
38 | this.parentObject.__setActiveWindow(this); | |
381fddfd | 39 | if(this.hilighted) |
96f28062 | 40 | this.setHilighted(qwebirc.ui.HILIGHT_NONE); |
7c633700 | 41 | if(this.scrolleddown) |
25be5960 | 42 | this.scrollToBottom(); |
3236ca77 | 43 | this.lastSelected = new Date(); |
94b18192 CP |
44 | }, |
45 | deselect: function() { | |
7c633700 | 46 | if(!this.parentObject.singleWindow) |
25be5960 | 47 | this.scrolleddown = this.scrolledDown(); |
7c633700 CP |
48 | if($defined(this.scrolltimer)) { |
49 | $clear(this.scrolltimer); | |
50 | this.scrolltimer = null; | |
51 | } | |
52 | ||
94b18192 CP |
53 | this.active = false; |
54 | }, | |
30bd2620 | 55 | addLine: function(type, line, colour, element) { |
96f28062 | 56 | var hilight = qwebirc.ui.HILIGHT_NONE; |
b2e77cf9 CP |
57 | var lhilight = false; |
58 | ||
96f28062 CP |
59 | if(type) { |
60 | hilight = qwebirc.ui.HILIGHT_ACTIVITY; | |
61 | ||
62 | if(type.match(/(NOTICE|ACTION|MSG)$/)) { | |
63 | if(this.type == qwebirc.ui.WINDOW_QUERY) { | |
96f28062 | 64 | hilight = qwebirc.ui.HILIGHT_US; |
b2e77cf9 CP |
65 | } |
66 | if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) { | |
67 | lhilight = true; | |
68 | hilight = qwebirc.ui.HILIGHT_US; | |
69 | } else if(hilight != qwebirc.ui.HILIGHT_US) { | |
96f28062 CP |
70 | hilight = qwebirc.ui.HILIGHT_SPEECH; |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE)) | |
76 | this.setHilighted(hilight); | |
77 | ||
381fddfd | 78 | if(type) |
b2e77cf9 | 79 | line = this.parentObject.theme.message(type, line, lhilight); |
381fddfd | 80 | |
2cd9e32d | 81 | qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); |
381fddfd | 82 | this.scrollAdd(element); |
94b18192 CP |
83 | }, |
84 | errorMessage: function(message) { | |
85 | this.addLine("", message, "red"); | |
381fddfd CP |
86 | }, |
87 | setHilighted: function(state) { | |
96f28062 CP |
88 | if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted) |
89 | this.hilighted = state; | |
381fddfd | 90 | }, |
25be5960 | 91 | scrolledDown: function() { |
7c633700 CP |
92 | if(this.scrolltimer) |
93 | return true; | |
94 | ||
381fddfd | 95 | var parent = this.lines; |
381fddfd | 96 | |
381fddfd CP |
97 | var prev = parent.getScroll(); |
98 | var prevbottom = parent.getScrollSize().y; | |
99 | var prevsize = parent.getSize(); | |
25be5960 | 100 | |
fccb1dac CP |
101 | /* fixes an IE bug */ |
102 | if(prevbottom < prevsize.y) | |
103 | prevbottom = prevsize.y; | |
104 | ||
7c633700 CP |
105 | return prev.y + prevsize.y == prevbottom; |
106 | }, | |
25be5960 | 107 | scrollToBottom: function() { |
7c633700 CP |
108 | var parent = this.lines; |
109 | var scrollparent = parent; | |
110 | ||
111 | if($defined(this.scroller)) | |
112 | scrollparent = this.scroller; | |
113 | ||
114 | scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y); | |
115 | }, | |
116 | scrollAdd: function(element) { | |
117 | var parent = this.lines; | |
381fddfd CP |
118 | |
119 | /* scroll in bursts, else the browser gets really slow */ | |
120 | if($defined(element)) { | |
25be5960 | 121 | var sd = this.scrolledDown(); |
381fddfd | 122 | parent.appendChild(element); |
7c633700 | 123 | if(sd) { |
381fddfd CP |
124 | if(this.scrolltimer) |
125 | $clear(this.scrolltimer); | |
7c633700 | 126 | this.scrolltimer = this.scrollAdd.delay(50, this, [null]); |
381fddfd CP |
127 | } |
128 | } else { | |
25be5960 | 129 | this.scrollToBottom(); |
381fddfd CP |
130 | this.scrolltimer = null; |
131 | } | |
9b63b053 | 132 | }, |
52090a1f | 133 | updateNickList: function(nicks) { |
833f14ce | 134 | var nickHash = {}, present = {}; |
52090a1f CP |
135 | var added = []; |
136 | var lnh = this.lastNickHash; | |
137 | ||
833f14ce CP |
138 | for(var i=0;i<nicks.length;i++) |
139 | present[nicks[i]] = 1; | |
140 | ||
141 | for(var k in lnh) | |
142 | if(!present[k]) | |
143 | this.nickListRemove(k, lnh[k]); | |
144 | ||
52090a1f CP |
145 | for(var i=0;i<nicks.length;i++) { |
146 | var n = nicks[i]; | |
147 | var l = lnh[n]; | |
148 | if(!l) { | |
149 | l = this.nickListAdd(n, i); | |
150 | if(!l) | |
151 | l = 1; | |
152 | } | |
153 | nickHash[n] = l; | |
154 | } | |
155 | ||
52090a1f CP |
156 | this.lastNickHash = nickHash; |
157 | }, | |
158 | nickListAdd: function(position, nick) { | |
159 | }, | |
160 | nickListRemove: function(nick, stored) { | |
161 | }, | |
9b63b053 CP |
162 | historyExec: function(line) { |
163 | this.commandhistory.addLine(line); | |
164 | this.client.exec(line); | |
94b18192 CP |
165 | } |
166 | }); |