]>
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 | }); |