]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/notifications.js
Add configuration of dynamic and static base URLs.
[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 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 favIcons = $$("link[rel=icon]"), favIconParent = $$("head");
60 if(favIcons && favIcons.length > 0 && favIconParent && favIconParent.length > 0) {
61 this.favIcon = favIcons[0];
62 this.favIconParent = favIconParent[0];
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
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 flash: function() {
78 if(!this.uiOptions.FLASH_ON_MENTION || this.windowFocused || !this.canFlash || this.flashing)
79 return;
80
81 this.titleText = document.title; /* just in case */
82 var flashA = function() {
83 this.hideFavIcon();
84 this.canUpdateTitle = false;
85 document.title = "Activity!";
86
87 this.flasher = flashB.delay(500);
88 }.bind(this);
89
90 var flashB = function() {
91 this.showFavIcon();
92 this.canUpdateTitle = true;
93 document.title = this.titleText;
94
95 this.flasher = flashA.delay(500);
96 }.bind(this);
97
98 this.flashing = true;
99 flashA();
100 },
101 cancelFlash: function() {
102 if(!this.canFlash || !$defined(this.flasher))
103 return;
104
105 this.flashing = false;
106
107 $clear(this.flasher);
108 this.flasher = null;
109
110 this.showFavIcon();
111 document.title = this.titleText;
112 this.canUpdateTitle = true;
113 },
114 hideFavIcon: function() {
115 if(this.favIconVisible) {
116 this.favIconVisible = false;
117 this.favIconParent.removeChild(this.favIcon);
118 this.favIconParent.appendChild(this.emptyFavIcon);
119 }
120 },
121 showFavIcon: function() {
122 if(!this.favIconVisible) {
123 this.favIconVisible = true;
124 this.favIconParent.removeChild(this.emptyFavIcon);
125 this.favIconParent.appendChild(this.favIcon);
126 }
127 },
128 updateTitle: function(text) {
129 this.titleText = text;
130 return this.canUpdateTitle;
131 },
132 focusChange: function(value) {
133 this.windowFocused = value;
134
135 if(value)
136 this.cancelFlash();
137 }
138 });