]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/notifications.js
Merge default into stable.
[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 document.addEvent("mousedown", this.cancelFlash.bind(this));
71 document.addEvent("keydown", this.cancelFlash.bind(this));
72 } else {
73 this.canFlash = false;
74 }
75 },
76 flash: function() {
77 if(!this.uiOptions.FLASH_ON_MENTION || this.windowFocused || !this.canFlash || this.flashing)
78 return;
79
80 this.titleText = document.title; /* just in case */
81 var flashA = function() {
82 this.hideFavIcon();
83 this.canUpdateTitle = false;
84 document.title = "Activity!";
85
86 this.flasher = flashB.delay(500);
87 }.bind(this);
88
89 var flashB = function() {
90 this.showFavIcon();
91 this.canUpdateTitle = true;
92 document.title = this.titleText;
93
94 this.flasher = flashA.delay(500);
95 }.bind(this);
96
97 this.flashing = true;
98 flashA();
99 },
100 cancelFlash: function() {
101 if(!this.canFlash || !$defined(this.flasher))
102 return;
103
104 this.flashing = false;
105
106 $clear(this.flasher);
107 this.flasher = null;
108
109 this.showFavIcon();
110 document.title = this.titleText;
111 this.canUpdateTitle = true;
112 },
113 hideFavIcon: function() {
114 if(this.favIconVisible) {
115 this.favIconVisible = false;
116 this.favIconParent.removeChild(this.favIcon);
117 this.favIconParent.appendChild(this.emptyFavIcon);
118 }
119 },
120 showFavIcon: function() {
121 if(!this.favIconVisible) {
122 this.favIconVisible = true;
123 this.favIconParent.removeChild(this.emptyFavIcon);
124 this.favIconParent.appendChild(this.favIcon);
125 }
126 },
127 updateTitle: function(text) {
128 this.titleText = text;
129 return this.canUpdateTitle;
130 },
131 focusChange: function(value) {
132 this.windowFocused = value;
133
134 if(value)
135 this.cancelFlash();
136 }
137 });