From cded6e79a3ada43a4d55ddfd8dba14fe8f29e45a Mon Sep 17 00:00:00 2001 From: max-m Date: Mon, 26 Dec 2011 22:16:37 +0100 Subject: [PATCH 1/2] Added title notifications --- file/js/TimWolla.WCF.Chat.coffee | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/file/js/TimWolla.WCF.Chat.coffee b/file/js/TimWolla.WCF.Chat.coffee index 47858e9..b9c9a38 100644 --- a/file/js/TimWolla.WCF.Chat.coffee +++ b/file/js/TimWolla.WCF.Chat.coffee @@ -13,7 +13,9 @@ TimWolla.WCF ?= {} (($) -> TimWolla.WCF.Chat = titleTemplate: null + title: document.title messageTemplate: null + newMessageCount: null init: () -> @bindEvents() @refreshRoomList() @@ -25,6 +27,19 @@ TimWolla.WCF ?= {} # Binds all the events needed for Tims Chat. ### bindEvents: () -> + @isActive = true + $(window).focus $.proxy () -> + document.title = @title + @newMessageCount = 0 + clearTimeout @timeout + @isActive = true + , this + + $(window).blur $.proxy () -> + @title = document.title + @isActive = false + , this + $('.smiley').click $.proxy (event) -> @insertText ' ' + $(event.target).attr('alt') + ' ' , this @@ -137,6 +152,15 @@ TimWolla.WCF ?= {} dataType: 'json' type: 'POST' success: $.proxy((data, textStatus, jqXHR) -> + if (!@isActive) + @newMessageCount += data.length + if (@newMessageCount > 0) + @timeout = setTimeout $.proxy(() -> + document.title = @newMessageCount + WCF.Language.get('wcf.chat.newMessages') + setTimeout $.proxy(() -> + document.title = @title + , this), 3000 + , this), 1000 @handleMessages(data) , this) ### From cfae043ba4a2f25af1e01a6c2eef33c296cc7b69 Mon Sep 17 00:00:00 2001 From: max-m Date: Mon, 26 Dec 2011 22:46:29 +0100 Subject: [PATCH 2/2] Now the fish won't swim out of the window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ________ / Blubb \ \___ __/ v ><((((°> --- file/js/TimWolla.WCF.Chat.coffee | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/file/js/TimWolla.WCF.Chat.coffee b/file/js/TimWolla.WCF.Chat.coffee index b9c9a38..0c39354 100644 --- a/file/js/TimWolla.WCF.Chat.coffee +++ b/file/js/TimWolla.WCF.Chat.coffee @@ -135,15 +135,20 @@ TimWolla.WCF ?= {} fish.appendTo $ 'body' new WCF.PeriodicalExecuter(() -> left = (Math.random() * 100 - 50) + top = (Math.random() * 100 - 50) + fish = $('#fish') - $('#fish').text('><((((°>') if (left > 0) - $('#fish').text('<°))))><') if (left < 0) + left *= -1 if((fish.position().left + left) < (0 + fish.width()) or (fish.position().left + left) > ($(document).width() - fish.width())) + top *= -1 if((fish.position().top + top) < (0 + fish.height()) or (fish.position().top + top) > ($(document).height() - fish.height())) - $('#fish').animate - top: '+=' + (Math.random() * 100 - 50) + fish.text('><((((°>') if (left > 0) + fish.text('<°))))><') if (left < 0) + + fish.animate + top: '+=' + top left: '+=' + left , 1000 - , 3e3); + , 1.5e3); ### # Loads new messages. ###