]>
Commit | Line | Data |
---|---|---|
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 | this.lastNickHash = {}; | |
20 | this.lastSelected = null; | |
21 | }, | |
22 | updateNickList: function(nicks) { | |
23 | }, | |
24 | updateTopic: function(topic, element) { | |
25 | qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); | |
26 | }, | |
27 | close: function() { | |
28 | if($defined(this.scrolltimer)) { | |
29 | $clear(this.scrolltimer); | |
30 | this.scrolltimer = null; | |
31 | } | |
32 | ||
33 | this.parentObject.__closed(this); | |
34 | this.fireEvent("close", this); | |
35 | }, | |
36 | select: function() { | |
37 | this.active = true; | |
38 | this.parentObject.__setActiveWindow(this); | |
39 | if(this.hilighted) | |
40 | this.setHilighted(qwebirc.ui.HILIGHT_NONE); | |
41 | if(this.scrolleddown) | |
42 | this.scrollToBottom(); | |
43 | this.lastSelected = new Date(); | |
44 | }, | |
45 | deselect: function() { | |
46 | if(!this.parentObject.singleWindow) | |
47 | this.scrolleddown = this.scrolledDown(); | |
48 | if($defined(this.scrolltimer)) { | |
49 | $clear(this.scrolltimer); | |
50 | this.scrolltimer = null; | |
51 | } | |
52 | ||
53 | this.active = false; | |
54 | }, | |
55 | addLine: function(type, line, colour, element) { | |
56 | var hilight = qwebirc.ui.HILIGHT_NONE; | |
57 | var lhilight = false; | |
58 | ||
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) { | |
64 | hilight = qwebirc.ui.HILIGHT_US; | |
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) { | |
70 | hilight = qwebirc.ui.HILIGHT_SPEECH; | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE)) | |
76 | this.setHilighted(hilight); | |
77 | ||
78 | if(type) | |
79 | line = this.parentObject.theme.message(type, line, lhilight); | |
80 | ||
81 | qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); | |
82 | this.scrollAdd(element); | |
83 | }, | |
84 | errorMessage: function(message) { | |
85 | this.addLine("", message, "red"); | |
86 | }, | |
87 | setHilighted: function(state) { | |
88 | if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted) | |
89 | this.hilighted = state; | |
90 | }, | |
91 | scrolledDown: function() { | |
92 | if(this.scrolltimer) | |
93 | return true; | |
94 | ||
95 | var parent = this.lines; | |
96 | ||
97 | var prev = parent.getScroll(); | |
98 | var prevbottom = parent.getScrollSize().y; | |
99 | var prevsize = parent.getSize(); | |
100 | ||
101 | /* fixes an IE bug */ | |
102 | if(prevbottom < prevsize.y) | |
103 | prevbottom = prevsize.y; | |
104 | ||
105 | return prev.y + prevsize.y == prevbottom; | |
106 | }, | |
107 | scrollToBottom: function() { | |
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; | |
118 | ||
119 | /* scroll in bursts, else the browser gets really slow */ | |
120 | if($defined(element)) { | |
121 | var sd = this.scrolledDown(); | |
122 | parent.appendChild(element); | |
123 | if(sd) { | |
124 | if(this.scrolltimer) | |
125 | $clear(this.scrolltimer); | |
126 | this.scrolltimer = this.scrollAdd.delay(50, this, [null]); | |
127 | } | |
128 | } else { | |
129 | this.scrollToBottom(); | |
130 | this.scrolltimer = null; | |
131 | } | |
132 | }, | |
133 | updateNickList: function(nicks) { | |
134 | var nickHash = {}, present = {}; | |
135 | var added = []; | |
136 | var lnh = this.lastNickHash; | |
137 | ||
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 | ||
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 | ||
156 | this.lastNickHash = nickHash; | |
157 | }, | |
158 | nickListAdd: function(position, nick) { | |
159 | }, | |
160 | nickListRemove: function(nick, stored) { | |
161 | }, | |
162 | historyExec: function(line) { | |
163 | this.commandhistory.addLine(line); | |
164 | this.client.exec(line); | |
165 | } | |
166 | }); |