1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2025-01-09 00:20:08 +00:00

Code format and removing unneeded templatelistener

This commit is contained in:
Tim Düsterhus 2012-01-21 17:45:53 +01:00
parent 569cab1f95
commit 331bcf3049
5 changed files with 34 additions and 32 deletions

View File

@ -23,8 +23,8 @@ TimWolla.WCF ?= {}
console.log('[TimWolla.WCF.Chat] Initializing'); console.log('[TimWolla.WCF.Chat] Initializing');
@bindEvents() @bindEvents()
@refreshRoomList() @refreshRoomList()
new WCF.PeriodicalExecuter $.proxy(@refreshRoomList, this), 60e3 new WCF.PeriodicalExecuter $.proxy(@refreshRoomList, @), 60e3
new WCF.PeriodicalExecuter $.proxy(@getMessages, this), @config.reloadTime * 1000 new WCF.PeriodicalExecuter $.proxy(@getMessages, @), @config.reloadTime * 1000
@getMessages() @getMessages()
console.log '[TimWolla.WCF.Chat] Finished initializing' console.log '[TimWolla.WCF.Chat] Finished initializing'
@ -38,26 +38,26 @@ TimWolla.WCF ?= {}
@newMessageCount = 0 @newMessageCount = 0
clearTimeout @timeout clearTimeout @timeout
@isActive = true @isActive = true
, this , @
$(window).blur $.proxy () -> $(window).blur $.proxy () ->
@title = document.title @title = document.title
@isActive = false @isActive = false
, this , @
$('.smiley').click $.proxy (event) -> $('.smiley').click $.proxy (event) ->
@insertText ' ' + $(event.target).attr('alt') + ' ' @insertText ' ' + $(event.target).attr('alt') + ' '
, this , @
$('.chatSidebarTabs li').click $.proxy (event) -> $('.chatSidebarTabs li').click $.proxy (event) ->
event.preventDefault() event.preventDefault()
@toggleSidebarContents $ event.target @toggleSidebarContents $ event.target
, this , @
$('#chatForm').submit $.proxy (event) -> $('#chatForm').submit $.proxy (event) ->
event.preventDefault() event.preventDefault()
@submit $ event.target @submit $ event.target
, this , @
$('#chatClear').click (event) -> $('#chatClear').click (event) ->
event.preventDefault() event.preventDefault()
@ -65,7 +65,7 @@ TimWolla.WCF ?= {}
$('#chatInput').focus() $('#chatInput').focus()
$('.chatToggle').click (event) -> $('.chatToggle').click (event) ->
element = $ this element = $ @
icon = element.find 'img' icon = element.find 'img'
if element.data('status') is 1 if element.data('status') is 1
element.data 'status', 0 element.data 'status', 0
@ -101,13 +101,14 @@ TimWolla.WCF ?= {}
return if $('#topic').text().trim() is '' return if $('#topic').text().trim() is ''
$('#topic').wcfBlindOut 'vertical', () -> $('#topic').wcfBlindOut 'vertical', () ->
$(this).text '' $(@).text ''
else else
$('#topic').text data.topic $('#topic').text data.topic
$('#topic').wcfBlindIn() if $('#topic').text().trim() isnt '' and $('#topic').is(':hidden') $('#topic').wcfBlindIn() if $('#topic').text().trim() isnt '' and $('#topic').is(':hidden')
$('title').text @titleTemplate.fetch(data) $('title').text @titleTemplate.fetch(data)
, this) @getMessages()
, @)
error: () -> error: () ->
# reload page to change the room the old fashion-way # reload page to change the room the old fashion-way
# inclusive the error-message :) # inclusive the error-message :)
@ -117,7 +118,7 @@ TimWolla.WCF ?= {}
@loading = true @loading = true
target.parent().addClass 'ajaxLoad' target.parent().addClass 'ajaxLoad'
, this) , @)
### ###
# Frees the fish # Frees the fish
### ###
@ -165,11 +166,11 @@ TimWolla.WCF ?= {}
document.title = @newMessageCount + WCF.Language.get('wcf.chat.newMessages') document.title = @newMessageCount + WCF.Language.get('wcf.chat.newMessages')
setTimeout $.proxy(() -> setTimeout $.proxy(() ->
document.title = @title document.title = @title
, this), 3000 , @), 3000
, this), 1000 , @), 1000
@handleMessages(data.messages) @handleMessages(data.messages)
@handleUsers(data.users) @handleUsers(data.users)
, this) , @)
### ###
# Inserts the new messages. # Inserts the new messages.
# #
@ -207,7 +208,7 @@ TimWolla.WCF ?= {}
a.click $.proxy (event) -> a.click $.proxy (event) ->
event.preventDefault() event.preventDefault()
@toggleUserMenu $ event.target @toggleUserMenu $ event.target
, this , @
li.append a li.append a
menu = $ '<ul></ul>' menu = $ '<ul></ul>'
menu.addClass 'chatUserMenu' menu.addClass 'chatUserMenu'
@ -222,8 +223,8 @@ TimWolla.WCF ?= {}
foundUsers[id] = true foundUsers[id] = true
$('.chatUser').each () -> $('.chatUser').each () ->
if typeof foundUsers[$(this).attr('id')] is 'undefined' if typeof foundUsers[$(@).attr('id')] is 'undefined'
$(this).remove() $(@).remove()
$('#toggleUsers .badge').text(users.length); $('#toggleUsers .badge').text(users.length);
### ###
@ -271,10 +272,10 @@ TimWolla.WCF ?= {}
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
, this , @
console.log '[TimWolla.WCF.Chat] Found ' + data.length + ' rooms' console.log '[TimWolla.WCF.Chat] Found ' + data.length + ' rooms'
, this) , @)
### ###
# Handles submitting of messages. # Handles submitting of messages.
# #
@ -297,7 +298,7 @@ TimWolla.WCF ?= {}
@getMessages() @getMessages()
$('#chatInput').val('').focus() $('#chatInput').val('').focus()
$('#chatInput').keyup() $('#chatInput').keyup()
, this) , @)
complete: () -> complete: () ->
$('#chatInput').removeClass 'ajaxLoad' $('#chatInput').removeClass 'ajaxLoad'
### ###
@ -334,4 +335,4 @@ TimWolla.WCF ?= {}
else else
li.addClass 'activeMenuItem' li.addClass 'activeMenuItem'
li.find('.chatUserMenu').wcfBlindIn 'vertical' li.find('.chatUserMenu').wcfBlindIn 'vertical'
)(jQuery, this) )(jQuery, @)

View File

@ -63,7 +63,7 @@ public function readChatVersion() {
public function readData() { public function readData() {
parent::readData(); parent::readData();
$this->readRoom(); $this->readRoom();
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color'); $this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
\wcf\util\ChatUtil::writeUserData(array('roomID' => $this->room->roomID)); \wcf\util\ChatUtil::writeUserData(array('roomID' => $this->room->roomID));
$this->newestMessages = chat\message\ChatMessageList::getNewestMessages($this->room, CHAT_LASTMESSAGES); $this->newestMessages = chat\message\ChatMessageList::getNewestMessages($this->room, CHAT_LASTMESSAGES);

View File

@ -183,13 +183,17 @@
</div> </div>
</div> </div>
{include file='chatJavascriptInclude'}
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
(function ($, window) { (function ($, window) {
// populate templates
TimWolla.WCF.Chat.titleTemplate = new WCF.Template('{ldelim}$title} - {'wcf.chat.title'|language|encodeJS} - {PAGE_TITLE|language|encodeJS}'); TimWolla.WCF.Chat.titleTemplate = new WCF.Template('{ldelim}$title} - {'wcf.chat.title'|language|encodeJS} - {PAGE_TITLE|language|encodeJS}');
{capture assign='chatMessageTemplate'}{include file='chatMessage'}{/capture} {capture assign='chatMessageTemplate'}{include file='chatMessage'}{/capture}
TimWolla.WCF.Chat.messageTemplate = new WCF.Template('{@$chatMessageTemplate|encodeJS}'); TimWolla.WCF.Chat.messageTemplate = new WCF.Template('{@$chatMessageTemplate|encodeJS}');
TimWolla.WCF.Chat.config = {
// populate config
TimWolla.WCF.Chat.config = {
reloadTime: {CHAT_RELOADTIME}, reloadTime: {CHAT_RELOADTIME},
animations: {CHAT_ANIMATIONS}, animations: {CHAT_ANIMATIONS},
maxTextLength: {CHAT_LENGTH} maxTextLength: {CHAT_LENGTH}
@ -199,13 +203,18 @@
WCF.Language.add('wcf.chat.ban', '{lang}wcf.chat.ban{/lang}'); WCF.Language.add('wcf.chat.ban', '{lang}wcf.chat.ban{/lang}');
WCF.Language.add('wcf.chat.profile', '{lang}wcf.chat.profile{/lang}'); WCF.Language.add('wcf.chat.profile', '{lang}wcf.chat.profile{/lang}');
{event name='shouldInit'} {event name='shouldInit'}
// Boot the that
TimWolla.WCF.Chat.init(); TimWolla.WCF.Chat.init();
{event name='didInit'} {event name='didInit'}
// show the last X messages
TimWolla.WCF.Chat.handleMessages([ TimWolla.WCF.Chat.handleMessages([
{implode from=$newestMessages item='message'} {implode from=$newestMessages item='message'}
{@$message->jsonify()} {@$message->jsonify()}
{/implode} {/implode}
]); ]);
// enable user-interface
$('#chatInput').enable().jCounter().focus(); $('#chatInput').enable().jCounter().focus();
$('#chatControls .copyright').click(function (event) { $('#chatControls .copyright').click(function (event) {
event.preventDefault(); event.preventDefault();

View File

@ -1,4 +1,2 @@
{if $templateName == 'chat'}
<script type="text/javascript" src="{@RELATIVE_WCF_DIR}js/TimWolla.WCF.Chat.js{if $chatVersion|isset}?version={$chatVersion|urlencode}{/if}"></script> <script type="text/javascript" src="{@RELATIVE_WCF_DIR}js/TimWolla.WCF.Chat.js{if $chatVersion|isset}?version={$chatVersion|urlencode}{/if}"></script>
<script type="text/javascript" src="{@RELATIVE_WCF_DIR}js/jCounter.jQuery.js"></script> <script type="text/javascript" src="{@RELATIVE_WCF_DIR}js/jCounter.jQuery.js"></script>
{/if}

View File

@ -1,12 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/templatelistener.xsd"> <data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/templatelistener.xsd">
<import> <import>
<templatelistener name="chatJavascriptInclude">
<environment>user</environment>
<templatename>headInclude</templatename>
<eventname>javascriptInclude</eventname>
<templatecode><![CDATA[{include file='chatJavascriptInclude'}]]></templatecode>
</templatelistener>
<templatelistener name="chatHeaderNavigation"> <templatelistener name="chatHeaderNavigation">
<environment>user</environment> <environment>user</environment>
<templatename>header</templatename> <templatename>header</templatename>