X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/3c506b009e2d2a9669342a1e17fd3109f743c67c..015ab79ac65cca3c99282e6c735412131f92e4f9:/js/ui/notifications.js diff --git a/js/ui/notifications.js b/js/ui/notifications.js index 09b21b8..796da14 100644 --- a/js/ui/notifications.js +++ b/js/ui/notifications.js @@ -1,132 +1,202 @@ -qwebirc.ui.HilightController = new Class({ - initialize: function(parent) { - this.parent = parent; - this.regex = null; - this.prevnick = null; - }, - match: function(text) { - var nick = this.parent.nickname; - if(nick != this.prevnick) - this.regex = new RegExp('\\b' + RegExp.escape(nick) + '\\b', "i"); - - if(text.match(this.regex)) - return true; - return false; - } -}); - -qwebirc.ui.Beeper = new Class({ - initialize: function(uiOptions) { - this.uiOptions = uiOptions; - - this.soundInited = false; - this.soundReady = false; - - if(this.uiOptions.BEEP_ON_MENTION) - this.soundInit(); - }, - soundInit: function() { - if(this.soundInited) - return; - if(!$defined(Browser.Plugins.Flash) || Browser.Plugins.Flash.version < 8) - return; - this.soundInited = true; - - this.soundPlayer = new qwebirc.sound.SoundPlayer(); - this.soundPlayer.addEvent("ready", function() { - this.soundReady = true; - }.bind(this)); - - this.soundPlayer.go(); - }, - beep: function() { - if(!this.soundReady || !this.uiOptions.BEEP_ON_MENTION) - return; - - this.soundPlayer.beep(); - } -}); - -qwebirc.ui.Flasher = new Class({ - initialize: function(uiOptions) { - this.uiOptions = uiOptions; - - this.windowFocused = false; - 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]; - this.favIconVisible = true; - this.emptyFavIcon = new Element("link"); - this.emptyFavIcon.rel = "shortcut icon"; - this.emptyFavIcon.href = "/images/empty_favicon.ico"; - - this.flashing = false; - - window.addEvent("focus", function() { this.windowFocused = true; this.cancelFlash(); }.bind(this)); - window.addEvent("blur", function() { this.windowFocused = false; }.bind(this)); - - this.canFlash = true; - } else { - this.canFlash = false; - } - }, - flash: function() { - if(!this.uiOptions.FLASH_ON_MENTION || this.windowFocused || !this.canFlash || this.flashing) - return; - - this.titleText = document.title; /* just in case */ - var flashA = function() { - this.hideFavIcon(); - this.canUpdateTitle = false; - document.title = "Activity!"; - - this.flasher = flashB.delay(500); - }.bind(this); - - var flashB = function() { - this.showFavIcon(); - this.canUpdateTitle = true; - document.title = this.titleText; - - this.flasher = flashA.delay(500); - }.bind(this); - - this.flashing = true; - flashA(); - }, - cancelFlash: function() { - if(!this.canFlash || !$defined(this.flasher)) - return; - - this.flashing = false; - - $clear(this.flasher); - this.flasher = null; - - this.showFavIcon(); - document.title = this.titleText; - this.canUpdateTitle = true; - }, - hideFavIcon: function() { - if(this.favIconVisible) { - this.favIconVisible = false; - this.favIconParent.removeChild(this.favIcon); - this.favIconParent.appendChild(this.emptyFavIcon); - } - }, - showFavIcon: function() { - if(!this.favIconVisible) { - this.favIconVisible = true; - this.favIconParent.removeChild(this.emptyFavIcon); - this.favIconParent.appendChild(this.favIcon); - } - }, - updateTitle: function(text) { - this.titleText = text; - return this.canUpdateTitle; - } -}); +qwebirc.ui.HilightController = new Class({ + initialize: function(parent) { + this.parent = parent; + this.regex = null; + this.prevnick = null; + }, + match: function(text) { + var nick = this.parent.nickname; + if(nick != this.prevnick) { + var classes = '[\\s\\.,;:]'; + this.regex = new RegExp('(^|' + classes + ')' + RegExp.escape(nick) + '(' + classes + '|$)', "i"); + } + if(text.match(this.regex)) + return true; + return false; + } +}); + +qwebirc.ui.Beeper = new Class({ + initialize: function(uiOptions) { + this.uiOptions = uiOptions; + + this.soundInited = false; + this.soundReady = false; + + if(this.uiOptions.BEEP_ON_MENTION) + this.soundInit(); + }, + soundInit: function() { + if(this.soundInited) + return; + if(!$defined(Browser.Plugins.Flash) || Browser.Plugins.Flash.version < 8) + return; + this.soundInited = true; + + this.soundPlayer = new qwebirc.sound.SoundPlayer(); + this.soundPlayer.addEvent("ready", function() { + this.soundReady = true; + }.bind(this)); + + this.soundPlayer.go(); + }, + beep: function() { + if(!this.soundReady || !this.uiOptions.BEEP_ON_MENTION) + return; + + this.soundPlayer.beep(); + } +}); + +qwebirc.ui.Flasher = new Class({ + initialize: function(uiOptions) { + this.uiOptions = uiOptions; + + this.windowFocused = false; + this.canUpdateTitle = true; + this.titleText = document.title; + + 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("mousedown", this.cancelFlash.bind(this)); + document.addEvent("keydown", this.cancelFlash.bind(this)); + } else { + this.canFlash = false; + } + }, + _getFavIcon: function() { + var favIcons = $$("head link"); + for(var i=0;i