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