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