]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/notifications.js
Merge.
[irc/quakenet/qwebirc.git] / js / ui / notifications.js
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 this.regex = new RegExp('\\b' + RegExp.escape(nick) + '\\b', "i");
11
12 if(text.match(this.regex))
13 return true;
14 return false;
15 }
16 });
17
18 qwebirc.ui.Beeper = new Class({
19 initialize: function(uiOptions) {
20 this.uiOptions = uiOptions;
21
22 this.soundInited = false;
23 this.soundReady = false;
24
25 if(this.uiOptions.BEEP_ON_MENTION)
26 this.soundInit();
27 },
28 soundInit: function() {
29 if(this.soundInited)
30 return;
31 if(!$defined(Browser.Plugins.Flash) || Browser.Plugins.Flash.version < 8)
32 return;
33 this.soundInited = true;
34
35 this.soundPlayer = new qwebirc.sound.SoundPlayer();
36 this.soundPlayer.addEvent("ready", function() {
37 this.soundReady = true;
38 }.bind(this));
39
40 this.soundPlayer.go();
41 },
42 beep: function() {
43 if(!this.soundReady || !this.uiOptions.BEEP_ON_MENTION)
44 return;
45
46 this.soundPlayer.beep();
47 }
48 });
49
50 qwebirc.ui.Flasher = new Class({
51 initialize: function(uiOptions) {
52 this.uiOptions = uiOptions;
53
54 this.windowFocused = false;
55 this.canUpdateTitle = true;
56 this.titleText = document.title;
57
58 var favIcons = $$("link[rel=icon]"), favIconParent = $$("head");
59 if(favIcons && favIcons.length > 0 && favIconParent && favIconParent.length > 0) {
60 this.favIcon = favIcons[0];
61 this.favIconParent = favIconParent[0];
62 this.favIconVisible = true;
63 this.emptyFavIcon = new Element("link");
64 this.emptyFavIcon.rel = "shortcut icon";
65 this.emptyFavIcon.href = "/images/empty_favicon.ico";
66
67 this.flashing = false;
68
69 this.canFlash = true;
70 } else {
71 this.canFlash = false;
72 }
73 },
74 flash: function() {
75 if(!this.uiOptions.FLASH_ON_MENTION || this.windowFocused || !this.canFlash || this.flashing)
76 return;
77
78 this.titleText = document.title; /* just in case */
79 var flashA = function() {
80 this.hideFavIcon();
81 this.canUpdateTitle = false;
82 document.title = "Activity!";
83
84 this.flasher = flashB.delay(500);
85 }.bind(this);
86
87 var flashB = function() {
88 this.showFavIcon();
89 this.canUpdateTitle = true;
90 document.title = this.titleText;
91
92 this.flasher = flashA.delay(500);
93 }.bind(this);
94
95 this.flashing = true;
96 flashA();
97 },
98 cancelFlash: function() {
99 if(!this.canFlash || !$defined(this.flasher))
100 return;
101
102 this.flashing = false;
103
104 $clear(this.flasher);
105 this.flasher = null;
106
107 this.showFavIcon();
108 document.title = this.titleText;
109 this.canUpdateTitle = true;
110 },
111 hideFavIcon: function() {
112 if(this.favIconVisible) {
113 this.favIconVisible = false;
114 this.favIconParent.removeChild(this.favIcon);
115 this.favIconParent.appendChild(this.emptyFavIcon);
116 }
117 },
118 showFavIcon: function() {
119 if(!this.favIconVisible) {
120 this.favIconVisible = true;
121 this.favIconParent.removeChild(this.emptyFavIcon);
122 this.favIconParent.appendChild(this.favIcon);
123 }
124 },
125 updateTitle: function(text) {
126 this.titleText = text;
127 return this.canUpdateTitle;
128 },
129 focusChange: function(value) {
130 if(value)
131 this.cancelFlash();
132 }
133 });