mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Some optimizations for readability
This commit is contained in:
parent
a0ea7bce95
commit
dfdfedc7fa
@ -12,13 +12,22 @@ TimWolla.WCF ?= {}
|
|||||||
|
|
||||||
(($, window) ->
|
(($, window) ->
|
||||||
TimWolla.WCF.Chat =
|
TimWolla.WCF.Chat =
|
||||||
|
# Templates
|
||||||
titleTemplate: null
|
titleTemplate: null
|
||||||
messageTemplate: null
|
messageTemplate: null
|
||||||
|
|
||||||
|
# Notifications
|
||||||
newMessageCount: null
|
newMessageCount: null
|
||||||
isActive: true
|
isActive: true
|
||||||
|
|
||||||
|
# Autocompleter
|
||||||
autocompleteOffset: 0
|
autocompleteOffset: 0
|
||||||
autocompleteValue: null
|
autocompleteValue: null
|
||||||
|
|
||||||
|
# Autoscroll
|
||||||
scrollHeightTopDiff: null
|
scrollHeightTopDiff: null
|
||||||
|
|
||||||
|
# Events
|
||||||
events:
|
events:
|
||||||
newMessage: $.Callbacks()
|
newMessage: $.Callbacks()
|
||||||
userMenu: $.Callbacks()
|
userMenu: $.Callbacks()
|
||||||
@ -28,7 +37,7 @@ TimWolla.WCF ?= {}
|
|||||||
@events.newMessage.add $.proxy @notify, @
|
@events.newMessage.add $.proxy @notify, @
|
||||||
|
|
||||||
new WCF.PeriodicalExecuter $.proxy(@refreshRoomList, @), 60e3
|
new WCF.PeriodicalExecuter $.proxy(@refreshRoomList, @), 60e3
|
||||||
new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1000
|
new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3
|
||||||
@refreshRoomList()
|
@refreshRoomList()
|
||||||
@getMessages()
|
@getMessages()
|
||||||
|
|
||||||
@ -126,7 +135,7 @@ TimWolla.WCF ?= {}
|
|||||||
$('.chatMessageContainer').scrollTop $('.chatMessageContainer ul').height()
|
$('.chatMessageContainer').scrollTop $('.chatMessageContainer ul').height()
|
||||||
|
|
||||||
# Desktop Notifications
|
# Desktop Notifications
|
||||||
if typeof window.webkitNotifications isnt 'undefined'
|
unless typeof window.webkitNotifications is 'undefined'
|
||||||
$('#chatNotify').click (event) ->
|
$('#chatNotify').click (event) ->
|
||||||
window.webkitNotifications.requestPermission() if $(this).data 'status'
|
window.webkitNotifications.requestPermission() if $(this).data 'status'
|
||||||
|
|
||||||
@ -191,15 +200,15 @@ TimWolla.WCF ?= {}
|
|||||||
|
|
||||||
fish.appendTo $ 'body'
|
fish.appendTo $ 'body'
|
||||||
new WCF.PeriodicalExecuter(() ->
|
new WCF.PeriodicalExecuter(() ->
|
||||||
left = (Math.random() * 100 - 50)
|
left = Math.random() * 100 - 50
|
||||||
top = (Math.random() * 100 - 50)
|
top = Math.random() * 100 - 50
|
||||||
fish = $('#fish')
|
fish = $('#fish')
|
||||||
|
|
||||||
left *= -1 if ((fish.position().left + left) < (0 + fish.width()) or (fish.position().left + left) > ($(document).width() - fish.width()))
|
left *= -1 unless fish.width() < (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()))
|
top *= -1 unless fish.height() < (fish.position().top + top) < ($(document).height() - fish.height()))
|
||||||
|
|
||||||
fish.text('><((((\u00B0>') if (left > 0)
|
fish.text('><((((\u00B0>') if left > 0
|
||||||
fish.text('<\u00B0))))><') if (left < 0)
|
fish.text('<\u00B0))))><') if left < 0
|
||||||
|
|
||||||
fish.animate
|
fish.animate
|
||||||
top: '+=' + top
|
top: '+=' + top
|
||||||
@ -224,8 +233,8 @@ TimWolla.WCF ?= {}
|
|||||||
###
|
###
|
||||||
handleMessages: (messages) ->
|
handleMessages: (messages) ->
|
||||||
# Disable scrolling automagically when user manually scrolled
|
# Disable scrolling automagically when user manually scrolled
|
||||||
if @scrollHeightTopDiff isnt null
|
unless @scrollHeightTopDiff is null
|
||||||
if @scrollHeightTopDiff isnt $('.chatMessageContainer ul').height() - $('.chatMessageContainer').scrollTop()
|
if $('.chatMessageContainer ul').height() - $('.chatMessageContainer').scrollTop() isnt @scrollHeighTopDiff
|
||||||
if $('#chatAutoscroll').data('status') is 1
|
if $('#chatAutoscroll').data('status') is 1
|
||||||
$('#chatAutoscroll').click()
|
$('#chatAutoscroll').click()
|
||||||
$('#chatAutoscroll').addClass('hot').fadeOut('slow').fadeIn('slow')
|
$('#chatAutoscroll').addClass('hot').fadeOut('slow').fadeIn('slow')
|
||||||
@ -318,7 +327,7 @@ TimWolla.WCF ?= {}
|
|||||||
# @param object message
|
# @param object message
|
||||||
###
|
###
|
||||||
notify: (message) ->
|
notify: (message) ->
|
||||||
return if (@isActive or $('#chatNotify').data('status') is 0)
|
return if @isActive or $('#chatNotify').data('status') is 0
|
||||||
@newMessageCount++
|
@newMessageCount++
|
||||||
|
|
||||||
document.title = '(' + @newMessageCount + ') ' + @titleTemplate.fetch({ title: $('#chatRoomList .activeMenuItem a').text() })
|
document.title = '(' + @newMessageCount + ') ' + @titleTemplate.fetch({ title: $('#chatRoomList .activeMenuItem a').text() })
|
||||||
|
Loading…
Reference in New Issue
Block a user