mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Make use of CoffeeScripts fat arrow
This commit is contained in:
parent
e24ab52691
commit
c9cdde0ad5
@ -99,45 +99,45 @@ window.console ?=
|
|||||||
###
|
###
|
||||||
# Binds all the events needed for Tims Chat.
|
# Binds all the events needed for Tims Chat.
|
||||||
###
|
###
|
||||||
bindEvents: () ->
|
bindEvents: ->
|
||||||
# Mark window as focused
|
# Mark window as focused
|
||||||
$(window).focus $.proxy () ->
|
$(window).focus =>
|
||||||
document.title = @titleTemplate.fetch
|
document.title = @titleTemplate.fetch
|
||||||
title: $('#timsChatRoomList .activeMenuItem a').text()
|
title: $('#timsChatRoomList .activeMenuItem a').text()
|
||||||
@newMessageCount = 0
|
@newMessageCount = 0
|
||||||
@isActive = true
|
@isActive = true
|
||||||
, @
|
|
||||||
|
|
||||||
# Mark window as blurred
|
# Mark window as blurred
|
||||||
$(window).blur $.proxy () ->
|
$(window).blur =>
|
||||||
@isActive = false
|
@isActive = false
|
||||||
, @
|
|
||||||
|
|
||||||
# Unload the chat
|
# Unload the chat
|
||||||
$(window).on 'beforeunload', $.proxy () ->
|
$(window).on 'beforeunload', =>
|
||||||
@unload()
|
@unload()
|
||||||
return undefined
|
undefined
|
||||||
, @
|
|
||||||
|
|
||||||
# Insert a smiley
|
# Insert a smiley
|
||||||
$('#smilies').on 'click', 'img', $.proxy (event) ->
|
$('#smilies').on 'click', 'img', (event) =>
|
||||||
@insertText ' ' + $(event.target).attr('alt') + ' '
|
@insertText ' ' + $(event.target).attr('alt') + ' '
|
||||||
, @
|
|
||||||
|
|
||||||
# Switch sidebar tab
|
# Switch sidebar tab
|
||||||
$('.timsChatSidebarTabs li').click $.proxy (event) ->
|
$('.timsChatSidebarTabs li').click (event) =>
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@toggleSidebarContents $ event.target
|
@toggleSidebarContents $ event.target
|
||||||
, @
|
|
||||||
|
|
||||||
# Submit Handler
|
# Submit Handler
|
||||||
$('#timsChatForm').submit $.proxy (event) ->
|
$('#timsChatForm').submit (event) =>
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@submit $ event.target
|
@submit $ event.target
|
||||||
, @
|
|
||||||
|
|
||||||
# Autocompleter
|
# Autocompleter
|
||||||
$('#timsChatInput').keydown $.proxy (event) ->
|
$('#timsChatInput').keydown (event) =>
|
||||||
# tab key
|
# tab key
|
||||||
if event.keyCode is 9
|
if event.keyCode is 9
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@ -168,13 +168,13 @@ window.console ?=
|
|||||||
@autocompleteOffset = 0
|
@autocompleteOffset = 0
|
||||||
@autocompleteValue = null
|
@autocompleteValue = null
|
||||||
@autocompleteCaret = null
|
@autocompleteCaret = null
|
||||||
, @
|
|
||||||
|
|
||||||
$('#timsChatInput').click $.proxy (event) ->
|
|
||||||
|
$('#timsChatInput').click =>
|
||||||
@autocompleteOffset = 0
|
@autocompleteOffset = 0
|
||||||
@autocompleteValue = null
|
@autocompleteValue = null
|
||||||
@autocompleteCaret = null
|
@autocompleteCaret = null
|
||||||
, @
|
|
||||||
|
|
||||||
# Refreshes the roomlist
|
# Refreshes the roomlist
|
||||||
$('#timsChatRoomList button').click $.proxy @refreshRoomList, @
|
$('#timsChatRoomList button').click $.proxy @refreshRoomList, @
|
||||||
@ -234,7 +234,7 @@ window.console ?=
|
|||||||
data:
|
data:
|
||||||
ajax: 1
|
ajax: 1
|
||||||
type: 'POST'
|
type: 'POST'
|
||||||
success: $.proxy (data, textStatus, jqXHR) ->
|
success: (data, textStatus, jqXHR) =>
|
||||||
@loading = false
|
@loading = false
|
||||||
target.parent().removeClass 'loading'
|
target.parent().removeClass 'loading'
|
||||||
|
|
||||||
@ -258,21 +258,20 @@ window.console ?=
|
|||||||
anchor = $(value)
|
anchor = $(value)
|
||||||
anchor.attr 'href', anchor.attr('href').replace /.*#/, "#{target.attr('href')}#"
|
anchor.attr 'href', anchor.attr('href').replace /.*#/, "#{target.attr('href')}#"
|
||||||
|
|
||||||
, @
|
|
||||||
error: () ->
|
error: ->
|
||||||
# Reload the page to change the room the old fashion-way
|
# Reload the page to change the room the old fashion-way
|
||||||
# inclusive the error-message :)
|
# inclusive the error-message :)
|
||||||
window.location.reload true
|
window.location.reload true
|
||||||
beforeSend: $.proxy(() ->
|
beforeSend: =>
|
||||||
return false if target.parent().hasClass('loading') or target.parent().hasClass 'activeMenuItem'
|
return false if target.parent().hasClass('loading') or target.parent().hasClass 'activeMenuItem'
|
||||||
|
|
||||||
@loading = true
|
@loading = true
|
||||||
target.parent().addClass 'loading'
|
target.parent().addClass 'loading'
|
||||||
, @)
|
|
||||||
###
|
###
|
||||||
# Frees the fish
|
# Frees the fish
|
||||||
###
|
###
|
||||||
freeTheFish: () ->
|
freeTheFish: ->
|
||||||
return if $.wcfIsset 'fish'
|
return if $.wcfIsset 'fish'
|
||||||
console.warn 'Freeing the fish'
|
console.warn 'Freeing the fish'
|
||||||
fish = $ """<div id="fish">#{WCF.String.escapeHTML('><((((\u00B0>')}</div>"""
|
fish = $ """<div id="fish">#{WCF.String.escapeHTML('><((((\u00B0>')}</div>"""
|
||||||
@ -285,7 +284,7 @@ window.console ?=
|
|||||||
zIndex: 9999
|
zIndex: 9999
|
||||||
|
|
||||||
fish.appendTo $ 'body'
|
fish.appendTo $ 'body'
|
||||||
@pe.fish = new WCF.PeriodicalExecuter(() ->
|
@pe.fish = 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'
|
||||||
@ -297,24 +296,24 @@ window.console ?=
|
|||||||
fish.text '<\u00B0))))><' if left < 0
|
fish.text '<\u00B0))))><' if left < 0
|
||||||
|
|
||||||
fish.animate
|
fish.animate
|
||||||
top: '+=' + top
|
top: "+=#{top}"
|
||||||
left: '+=' + left
|
left: "+=#{left}"
|
||||||
, 1e3
|
, 1e3
|
||||||
, 1.5e3)
|
, 1.5e3
|
||||||
###
|
###
|
||||||
# Loads new messages.
|
# Loads new messages.
|
||||||
###
|
###
|
||||||
getMessages: () ->
|
getMessages: ->
|
||||||
$.ajax @config.messageURL,
|
$.ajax @config.messageURL,
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
type: 'POST'
|
type: 'POST'
|
||||||
success: $.proxy (data, textStatus, jqXHR) ->
|
success: (data, textStatus, jqXHR) =>
|
||||||
WCF.DOMNodeInsertedHandler.enable()
|
WCF.DOMNodeInsertedHandler.enable()
|
||||||
@handleMessages(data.messages)
|
@handleMessages(data.messages)
|
||||||
@handleUsers(data.users)
|
@handleUsers(data.users)
|
||||||
WCF.DOMNodeInsertedHandler.disable()
|
WCF.DOMNodeInsertedHandler.disable()
|
||||||
, @
|
|
||||||
error: $.proxy (jqXHR, textStatus, errorThrown) ->
|
error: (jqXHR, textStatus, errorThrown) =>
|
||||||
console.error 'Battle Station hit - shields at ' + (--@shields / 3 * 104) + ' percent'
|
console.error 'Battle Station hit - shields at ' + (--@shields / 3 * 104) + ' percent'
|
||||||
if @shields is 0
|
if @shields is 0
|
||||||
@pe.refreshRoomList.stop()
|
@pe.refreshRoomList.stop()
|
||||||
@ -322,15 +321,12 @@ window.console ?=
|
|||||||
@freeTheFish()
|
@freeTheFish()
|
||||||
console.error 'We got destroyed, but could free our friend the fish before he was killed as well. Have a nice life in freedom!'
|
console.error 'We got destroyed, but could free our friend the fish before he was killed as well. Have a nice life in freedom!'
|
||||||
alert 'herp i cannot load messages'
|
alert 'herp i cannot load messages'
|
||||||
, @
|
complete: =>
|
||||||
complete: $.proxy () ->
|
|
||||||
@loading = false
|
@loading = false
|
||||||
, @
|
beforeSend: =>
|
||||||
beforeSend: $.proxy () ->
|
|
||||||
return false if @loading
|
return false if @loading
|
||||||
|
|
||||||
@loading = true
|
@loading = true
|
||||||
, @
|
|
||||||
###
|
###
|
||||||
# Inserts the new messages.
|
# Inserts the new messages.
|
||||||
#
|
#
|
||||||
@ -416,11 +412,11 @@ window.console ?=
|
|||||||
menu = $ '<ul></ul>'
|
menu = $ '<ul></ul>'
|
||||||
#menu.addClass 'timsChatUserMenu'
|
#menu.addClass 'timsChatUserMenu'
|
||||||
menu.addClass 'dropdownMenu'
|
menu.addClass 'dropdownMenu'
|
||||||
menu.append $ '<li><a>' + WCF.Language.get('chat.general.query') + '</a></li>'
|
menu.append $ "<li><a>#{WCF.Language.get('chat.general.query')}</a></li>"
|
||||||
menu.append $ '<li><a>' + WCF.Language.get('chat.general.kick') + '</a></li>'
|
menu.append $ "<li><a>#{ WCF.Language.get('chat.general.kick')}</a></li>"
|
||||||
menu.append $ '<li><a>' + WCF.Language.get('chat.general.ban') + '</a></li>'
|
menu.append $ "<li><a>#{ WCF.Language.get('chat.general.ban')}</a></li>"
|
||||||
# TODO: SID and co
|
# TODO: SID and co
|
||||||
menu.append $ '<li><a href="index.php/User/' + user.userID + '-' + encodeURI(user.username) + '/">' + WCF.Language.get('chat.general.profile') + '</a></li>'
|
menu.append $ """<li><a href="index.php/User/#{user.userID}-#{encodeURI(user.username)}/">#{WCF.Language.get('chat.general.profile')}</a></li>"""
|
||||||
@events.userMenu.fire user, menu
|
@events.userMenu.fire user, menu
|
||||||
li.append menu
|
li.append menu
|
||||||
|
|
||||||
@ -443,17 +439,14 @@ window.console ?=
|
|||||||
unless typeof window.io is 'undefined'
|
unless typeof window.io is 'undefined'
|
||||||
console.log 'Initializing nodePush'
|
console.log 'Initializing nodePush'
|
||||||
@socket = io.connect @config.socketIOPath
|
@socket = io.connect @config.socketIOPath
|
||||||
@socket.on 'connect', $.proxy((data) ->
|
@socket.on 'connect', =>
|
||||||
console.log 'Connected to nodePush'
|
console.log 'Connected to nodePush'
|
||||||
@pe.getMessages.stop()
|
@pe.getMessages.stop()
|
||||||
, @)
|
@socket.on 'disconnect', =>
|
||||||
@socket.on 'disconnect', $.proxy (data) ->
|
|
||||||
console.log 'Lost connection to nodePush'
|
console.log 'Lost connection to nodePush'
|
||||||
@pe.getMessages = new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3
|
@pe.getMessages = new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1e3
|
||||||
, @
|
@socket.on 'newMessage', =>
|
||||||
@socket.on 'newMessage', $.proxy (data) ->
|
|
||||||
@getMessages()
|
@getMessages()
|
||||||
, @
|
|
||||||
###
|
###
|
||||||
# Inserts text into our input.
|
# Inserts text into our input.
|
||||||
#
|
#
|
||||||
@ -509,7 +502,7 @@ window.console ?=
|
|||||||
$.ajax $('#toggleRooms a').data('refreshUrl'),
|
$.ajax $('#toggleRooms a').data('refreshUrl'),
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
type: 'POST'
|
type: 'POST'
|
||||||
success: $.proxy (data, textStatus, jqXHR) ->
|
success: (data, textStatus, jqXHR) =>
|
||||||
$('#timsChatRoomList li').remove()
|
$('#timsChatRoomList li').remove()
|
||||||
$('#toggleRooms .ajaxLoad').hide()
|
$('#toggleRooms .ajaxLoad').hide()
|
||||||
$('#toggleRooms .badge').text data.length
|
$('#toggleRooms .badge').text data.length
|
||||||
@ -520,14 +513,13 @@ window.console ?=
|
|||||||
$("""<a href="#{room.link}">#{room.title}</a>""").addClass('timsChatRoom').appendTo li
|
$("""<a href="#{room.link}">#{room.title}</a>""").addClass('timsChatRoom').appendTo li
|
||||||
$('#timsChatRoomList ul').append li
|
$('#timsChatRoomList ul').append li
|
||||||
|
|
||||||
$('.timsChatRoom').click $.proxy (event) ->
|
$('.timsChatRoom').click (event) =>
|
||||||
return if typeof window.history.replaceState is 'undefined'
|
return if typeof window.history.replaceState is 'undefined'
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@changeRoom $ event.target
|
@changeRoom $ event.target
|
||||||
, @
|
|
||||||
|
|
||||||
console.log "Found #{data.length} rooms"
|
console.log "Found #{data.length} rooms"
|
||||||
, @
|
|
||||||
###
|
###
|
||||||
# Handles submitting of messages.
|
# Handles submitting of messages.
|
||||||
#
|
#
|
||||||
@ -553,9 +545,8 @@ window.console ?=
|
|||||||
smilies: $('#timsChatSmilies').data 'status'
|
smilies: $('#timsChatSmilies').data 'status'
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
beforeSend: (jqXHR) ->
|
beforeSend: (jqXHR) ->
|
||||||
success: $.proxy (data, textStatus, jqXHR) ->
|
success: =>
|
||||||
@getMessages()
|
@getMessages()
|
||||||
, @
|
|
||||||
complete: () ->
|
complete: () ->
|
||||||
###
|
###
|
||||||
# Toggles between user- and room-list.
|
# Toggles between user- and room-list.
|
||||||
|
Loading…
Reference in New Issue
Block a user