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