this.canUpdateTitle = true;
this.titleText = document.title;
- var favIcons = $$("link[rel=icon]"), favIconParent = $$("head");
- if(favIcons && favIcons.length > 0 && favIconParent && favIconParent.length > 0) {
- this.favIcon = favIcons[0];
- this.favIconParent = favIconParent[0];
+ var favIcon = this._getFavIcon();
+ if($defined(favIcon)) {
+ this.favIcon = favIcon;
+ this.favIconParent = favIcon.parentNode;
this.favIconVisible = true;
this.emptyFavIcon = new Element("link");
this.emptyFavIcon.rel = "shortcut icon";
this.emptyFavIcon.href = qwebirc.global.staticBaseURL + "images/empty_favicon.ico";
-
+ this.emptyFavIcon.type = "image/x-icon";
this.flashing = false;
this.canFlash = true;
document.addEvent("keydown", this.cancelFlash.bind(this));
} else {
this.canFlash = false;
- }
+ }
+ },
+ _getFavIcon: function() {
+ var favIcons = $$("head link");
+ for(var i=0;i<favIcons.length;i++)
+ if(favIcons[i].getAttribute("rel") == "shortcut icon")
+ return favIcons[i];
},
flash: function() {
if(!this.uiOptions.FLASH_ON_MENTION || this.windowFocused || !this.canFlash || this.flashing)
},
hideFavIcon: function() {
if(this.favIconVisible) {
+ /* only seems to work in firefox */
this.favIconVisible = false;
this.favIconParent.removeChild(this.favIcon);
this.favIconParent.appendChild(this.emptyFavIcon);
this.cancelFlash();
}
});
+
+qwebirc.ui.Notifier = new Class({
+ initialize: function(uiOptions) {
+ this.uiOptions = uiOptions;
+
+ this.windowFocused = false;
+ this.previous = null;
+ this.setEnabled(this.uiOptions.NOTIFICATIONS);
+ },
+ focusChange: function(value) {
+ this.windowFocused = value;
+ },
+ setEnabled: function(value) {
+ this.enabled = value;
+ if(!value)
+ return;
+
+ if(this.isGranted())
+ return;
+
+ Notification.requestPermission(function (permission) {
+ if (!("permission" in Notification))
+ Notification.permission = permission;
+ });
+ },
+ isGranted: function() {
+ if(!("Notification" in window))
+ return false;
+
+ return Notification.permission === "granted";
+ },
+ notify: function(title, message, callback) {
+ if(this.windowFocused && !this.enabled || !this.isGranted())
+ return;
+
+ if(this.previous)
+ this.previous.close();
+
+ var n = new Notification(title, {body: message, icon: qwebirc.global.staticBaseURL + "images/qwebircsmall.png"});
+ var delay = function() {
+ n.close();
+ this.previous = null;
+ }.bind(this).delay(5000);
+
+ this.previous = n;
+ if(callback) {
+ n.addEventListener("click", function() {
+ this.previous = null;
+ window.focus();
+ callback();
+ });
+ n.addEventListener("close", function() {
+ this.previous = null;
+ }.bind(this));
+ }
+ }
+});