]>
Commit | Line | Data |
---|---|---|
1 | qwebirc.ui.HilightController = new Class({ | |
2 | initialize: function(parent) { | |
3 | this.parent = parent; | |
4 | this.regex = null; | |
5 | this.prevnick = null; | |
6 | }, | |
7 | match: function(text) { | |
8 | var nick = this.parent.nickname; | |
9 | if(nick != this.prevnick) { | |
10 | var classes = '[\\s\\.,;:]'; | |
11 | this.regex = new RegExp('(^|' + classes + ')' + RegExp.escape(nick) + '(' + classes + '|$)', "i"); | |
12 | } | |
13 | if(text.match(this.regex)) | |
14 | return true; | |
15 | return false; | |
16 | } | |
17 | }); | |
18 | ||
19 | qwebirc.ui.Beeper = new Class({ | |
20 | initialize: function(uiOptions) { | |
21 | this.uiOptions = uiOptions; | |
22 | ||
23 | this.soundInited = false; | |
24 | this.soundReady = false; | |
25 | ||
26 | if(this.uiOptions.BEEP_ON_MENTION) | |
27 | this.soundInit(); | |
28 | }, | |
29 | soundInit: function() { | |
30 | if(this.soundInited) | |
31 | return; | |
32 | if(!$defined(Browser.Plugins.Flash) || Browser.Plugins.Flash.version < 8) | |
33 | return; | |
34 | this.soundInited = true; | |
35 | ||
36 | this.soundPlayer = new qwebirc.sound.SoundPlayer(); | |
37 | this.soundPlayer.addEvent("ready", function() { | |
38 | this.soundReady = true; | |
39 | }.bind(this)); | |
40 | ||
41 | this.soundPlayer.go(); | |
42 | }, | |
43 | beep: function() { | |
44 | if(!this.soundReady || !this.uiOptions.BEEP_ON_MENTION) | |
45 | return; | |
46 | ||
47 | this.soundPlayer.beep(); | |
48 | } | |
49 | }); | |
50 | ||
51 | qwebirc.ui.Flasher = new Class({ | |
52 | initialize: function(uiOptions) { | |
53 | this.uiOptions = uiOptions; | |
54 | ||
55 | this.windowFocused = false; | |
56 | this.canUpdateTitle = true; | |
57 | this.titleText = document.title; | |
58 | ||
59 | var favIcon = this._getFavIcon(); | |
60 | if($defined(favIcon)) { | |
61 | this.favIcon = favIcon; | |
62 | this.favIconParent = favIcon.parentNode; | |
63 | this.favIconVisible = true; | |
64 | this.emptyFavIcon = new Element("link"); | |
65 | this.emptyFavIcon.rel = "shortcut icon"; | |
66 | this.emptyFavIcon.href = qwebirc.global.staticBaseURL + "images/empty_favicon.ico"; | |
67 | this.emptyFavIcon.type = "image/x-icon"; | |
68 | this.flashing = false; | |
69 | ||
70 | this.canFlash = true; | |
71 | document.addEvent("mousedown", this.cancelFlash.bind(this)); | |
72 | document.addEvent("keydown", this.cancelFlash.bind(this)); | |
73 | } else { | |
74 | this.canFlash = false; | |
75 | } | |
76 | }, | |
77 | _getFavIcon: function() { | |
78 | var favIcons = $$("head link"); | |
79 | for(var i=0;i<favIcons.length;i++) | |
80 | if(favIcons[i].getAttribute("rel") == "shortcut icon") | |
81 | return favIcons[i]; | |
82 | }, | |
83 | flash: function() { | |
84 | if(!this.uiOptions.FLASH_ON_MENTION || this.windowFocused || !this.canFlash || this.flashing) | |
85 | return; | |
86 | ||
87 | this.titleText = document.title; /* just in case */ | |
88 | var flashA = function() { | |
89 | this.hideFavIcon(); | |
90 | this.canUpdateTitle = false; | |
91 | document.title = "Activity!"; | |
92 | ||
93 | this.flasher = flashB.delay(500); | |
94 | }.bind(this); | |
95 | ||
96 | var flashB = function() { | |
97 | this.showFavIcon(); | |
98 | this.canUpdateTitle = true; | |
99 | document.title = this.titleText; | |
100 | ||
101 | this.flasher = flashA.delay(500); | |
102 | }.bind(this); | |
103 | ||
104 | this.flashing = true; | |
105 | flashA(); | |
106 | }, | |
107 | cancelFlash: function() { | |
108 | if(!this.canFlash || !$defined(this.flasher)) | |
109 | return; | |
110 | ||
111 | this.flashing = false; | |
112 | ||
113 | $clear(this.flasher); | |
114 | this.flasher = null; | |
115 | ||
116 | this.showFavIcon(); | |
117 | document.title = this.titleText; | |
118 | this.canUpdateTitle = true; | |
119 | }, | |
120 | hideFavIcon: function() { | |
121 | if(this.favIconVisible) { | |
122 | /* only seems to work in firefox */ | |
123 | this.favIconVisible = false; | |
124 | this.favIconParent.removeChild(this.favIcon); | |
125 | this.favIconParent.appendChild(this.emptyFavIcon); | |
126 | } | |
127 | }, | |
128 | showFavIcon: function() { | |
129 | if(!this.favIconVisible) { | |
130 | this.favIconVisible = true; | |
131 | this.favIconParent.removeChild(this.emptyFavIcon); | |
132 | this.favIconParent.appendChild(this.favIcon); | |
133 | } | |
134 | }, | |
135 | updateTitle: function(text) { | |
136 | this.titleText = text; | |
137 | return this.canUpdateTitle; | |
138 | }, | |
139 | focusChange: function(value) { | |
140 | this.windowFocused = value; | |
141 | ||
142 | if(value) | |
143 | this.cancelFlash(); | |
144 | } | |
145 | }); | |
146 | ||
147 | qwebirc.ui.Notifier = new Class({ | |
148 | initialize: function(uiOptions) { | |
149 | this.uiOptions = uiOptions; | |
150 | ||
151 | this.windowFocused = false; | |
152 | this.previous = null; | |
153 | this.setEnabled(this.uiOptions.NOTIFICATIONS); | |
154 | }, | |
155 | focusChange: function(value) { | |
156 | this.windowFocused = value; | |
157 | }, | |
158 | setEnabled: function(value) { | |
159 | this.enabled = value; | |
160 | if(!value) | |
161 | return; | |
162 | ||
163 | if(this.isGranted()) | |
164 | return; | |
165 | ||
166 | Notification.requestPermission(function (permission) { | |
167 | if (!("permission" in Notification)) | |
168 | Notification.permission = permission; | |
169 | }); | |
170 | }, | |
171 | isGranted: function() { | |
172 | if(!("Notification" in window)) | |
173 | return false; | |
174 | ||
175 | return Notification.permission === "granted"; | |
176 | }, | |
177 | notify: function(title, message, callback) { | |
178 | if(this.windowFocused && !this.enabled || !this.isGranted()) | |
179 | return; | |
180 | ||
181 | if(this.previous) | |
182 | this.previous.close(); | |
183 | ||
184 | var n = new Notification(title, {body: message, icon: qwebirc.global.staticBaseURL + "images/qwebircsmall.png"}); | |
185 | var delay = function() { | |
186 | n.close(); | |
187 | this.previous = null; | |
188 | }.bind(this).delay(5000); | |
189 | ||
190 | this.previous = n; | |
191 | if(callback) { | |
192 | n.addEventListener("click", function() { | |
193 | this.previous = null; | |
194 | window.focus(); | |
195 | callback(); | |
196 | }); | |
197 | n.addEventListener("close", function() { | |
198 | this.previous = null; | |
199 | }.bind(this)); | |
200 | } | |
201 | } | |
202 | }); |