]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/notifications.js
1 qwebirc
.ui
.HilightController
= new Class({
2 initialize: function(parent
) {
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");
13 if(text
.match(this.regex
))
19 qwebirc
.ui
.Beeper
= new Class({
20 initialize: function(uiOptions
) {
21 this.uiOptions
= uiOptions
;
23 this.soundPlayer
= new qwebirc
.sound
.SoundPlayer();
25 beep: function(notification
) {
26 if(notification
&& !this.uiOptions
.BEEP_ON_MENTION
)
29 this.soundPlayer
.play("beep3.mp3");
33 qwebirc
.ui
.Flasher
= new Class({
34 initialize: function(uiOptions
) {
35 this.uiOptions
= uiOptions
;
37 this.windowFocused
= false;
38 this.canUpdateTitle
= true;
39 this.titleText
= document
.title
;
41 var favIcon
= this._getFavIcon();
42 if($defined(favIcon
)) {
43 this.favIcon
= favIcon
;
44 this.favIconParent
= favIcon
.parentNode
;
45 this.favIconVisible
= true;
46 this.emptyFavIcon
= new Element("link");
47 this.emptyFavIcon
.rel
= "shortcut icon";
48 this.emptyFavIcon
.href
= qwebirc
.global
.staticBaseURL
+ "images/empty_favicon.ico";
49 this.emptyFavIcon
.type
= "image/x-icon";
50 this.flashing
= false;
53 document
.addEvent("mousedown", this.cancelFlash
.bind(this));
54 document
.addEvent("keydown", this.cancelFlash
.bind(this));
56 this.canFlash
= false;
59 _getFavIcon: function() {
60 var favIcons
= $$("head link");
61 for(var i
=0;i
<favIcons
.length
;i
++)
62 if(favIcons
[i
].getAttribute("rel") == "shortcut icon")
66 if(!this.uiOptions
.FLASH_ON_MENTION
|| this.windowFocused
|| !this.canFlash
|| this.flashing
)
69 this.titleText
= document
.title
; /* just in case */
70 var flashA = function() {
72 this.canUpdateTitle
= false;
73 document
.title
= "Activity!";
75 this.flasher
= flashB
.delay(500);
78 var flashB = function() {
80 this.canUpdateTitle
= true;
81 document
.title
= this.titleText
;
83 this.flasher
= flashA
.delay(500);
89 cancelFlash: function() {
90 if(!this.canFlash
|| !$defined(this.flasher
))
93 this.flashing
= false;
99 document
.title
= this.titleText
;
100 this.canUpdateTitle
= true;
102 hideFavIcon: function() {
103 if(this.favIconVisible
) {
104 /* only seems to work in firefox */
105 this.favIconVisible
= false;
106 this.favIconParent
.removeChild(this.favIcon
);
107 this.favIconParent
.appendChild(this.emptyFavIcon
);
110 showFavIcon: function() {
111 if(!this.favIconVisible
) {
112 this.favIconVisible
= true;
113 this.favIconParent
.removeChild(this.emptyFavIcon
);
114 this.favIconParent
.appendChild(this.favIcon
);
117 updateTitle: function(text
) {
118 this.titleText
= text
;
119 return this.canUpdateTitle
;
121 focusChange: function(value
) {
122 this.windowFocused
= value
;
129 qwebirc
.ui
.Notifier
= new Class({
130 initialize: function(uiOptions
) {
131 this.uiOptions
= uiOptions
;
133 this.windowFocused
= false;
134 this.previous
= null;
135 this.setEnabled(this.uiOptions
.NOTIFICATIONS
);
137 focusChange: function(value
) {
138 this.windowFocused
= value
;
140 setEnabled: function(value
) {
141 this.enabled
= value
;
148 Notification
.requestPermission(function (permission
) {
149 if (!("permission" in Notification
))
150 Notification
.permission
= permission
;
153 isGranted: function() {
154 if(!("Notification" in window
))
157 return Notification
.permission
=== "granted";
159 notify: function(title
, message
, callback
) {
160 if(this.windowFocused
&& !this.enabled
|| !this.isGranted())
164 this.previous
.close();
166 var n
= new Notification(title
, {body: message
, icon: qwebirc
.global
.staticBaseURL
+ "images/qwebircsmall.png"});
167 var delay = function() {
169 this.previous
= null;
170 }.bind(this).delay(5000);
174 n
.addEventListener("click", function() {
175 this.previous
= null;
179 n
.addEventListener("close", function() {
180 this.previous
= null;