candy.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Summary
candy.js
CandyCandy base class for initalizing the view and the core
Variables
aboutAbout candy
Functions
initInit view & core
Files
core.js
Candy.CoreCandy Chat Core
Variables
autojoinIf set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).
Functions
initInitialize Core.
connectConnect to the jabber host.
attachAttach an already binded & connected session to the server
disconnectLeave all rooms and disconnect
addHandlerWrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
getUserGets current user
setUserSet current user.
getConnectionGets Strophe connection
getRoomsGets all joined rooms
isAnonymousConnectionReturns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
getOptionsGets options
getRoomGets a specific room
onWindowUnloadwindow.onbeforeunload event which disconnects the client from the Jabber server.
rawInput(Overridden from Strophe.Connection.rawInput)
logOverridden to do something useful if debug is set to true.
Files
view.js
Candy.ViewThe Candy View Class
Functions
initInitialize chat view (setup DOM, register handlers & observers)
getCurrentGet current container & roomJid in an object.
getOptionsGets options
Files
util.js
Candy.UtilCandy utils
Functions
jidToIdTranslates a jid to a MD5-Id
escapeJidEscapes a jid (node & resource get escaped)
unescapeJidUnescapes a jid (node & resource get unescaped)
cropCrop a string with the specified length
setCookieSets a new cookie
cookieExistsTests if a cookie with the given name exists
getCookieReturns the cookie value if there’s one with this name, otherwise returns undefined
deleteCookieDeletes a cookie with the given name
getPosLeftAccordingToWindowBoundsFetches the window width and element width and checks if specified position + element width is bigger than the window width.
getPosTopAccordingToWindowBoundsFetches the window height and element height and checks if specified position + element height is bigger than the window height.
localizedTimeLocalizes ISO-8610 Date with the time/dateformat specified in the translation.
iso8610toDateParses a ISO-8610 Date to a Date-Object.
isEmptyObjectIE7 doesn’t work with jQuery.isEmptyObject (<=1.5.1), workaround.
forceRedrawFix IE7 not redrawing under some circumstances.
Candy.Util.ParserParser for emoticons, links and also supports escaping.
Functions
setEmoticonPathSet emoticons location.
Variables
emoticonsArray containing emoticons to be replaced by their images.
Functions
emotifyReplaces text-emoticons with their image equivalent.
linkifyReplaces URLs with a HTML-link.
escapeEscapes a text using a jQuery function (like htmlspecialchars in PHP)
allDoes everything of the parser: escaping, linkifying and emotifying.
Candy.Util.ObservableA class can be extended with the observable to be able to notify observers
Functions
addObserverAdd an observer to the observer list
deleteObserverDelete observer from list
clearObserversDeletes all observers in list
notifyObserversNotify all of its observers of a certain event.
Files
action.js
Candy.Core.ActionChat Actions (basicly a abstraction of Jabber commands)
Candy.Core.Action.JabberJabber actions
Functions
VersionReplies to a version request
RosterSends a request for a roster
PresenceSends a request for presence
ServicesSends a request for disco items
AutojoinWhen Candy.Core.getOptions().autojoin is true, request autojoin bookmarks (OpenFire)
ResetIgnoreListCreate new ignore privacy list (and reset the old one, if it exists).
RemoveIgnoreListRemove an existing ignore list.
GetIgnoreListGet existing ignore privacy list when connecting.
SetIgnoreListActiveSet ignore privacy list active
GetJidIfAnonymousOn anonymous login, initially we don’t know the jid and as a result, Candy.Core._user doesn’t have a jid.
Candy.Core.Action.Jabber.RoomRoom-specific commands
Functions
JoinRequests disco of specified room and joins afterwards.
LeaveLeaves a room.
DiscoRequests disco info of a room.
MessageSend message
IgnoreUnignoreChecks if the user is already ignoring the target user, if yes: unignore him, if no: ignore him.
UpdatePrivacyListUpdates privacy list according to the privacylist in the currentUser
Candy.Core.Action.Jabber.Room.AdminRoom administration commands
Functions
UserActionKick or ban a user
SetSubjectSets subject (topic) of a room.
Files
chatRoom.js
Candy.Core.ChatRoomCandy Chat Room
Variables
roomObject containing roomJid and name.
userCurrent local user of this room.
RosterCandy.Core.ChatRoster instance
Functions
setUserSet user of this room.
getUserGet current local user
getJidGet room jid
setNameSet room name
getNameGet room name
setRosterSet roster of room
getRosterGet roster
Files
chatRoster.js
Candy.Core.ChatRosterChat Roster
Variables
itemsRoster items
Functions
addAdd user to roster
removeRemove user from roster
getGet user from roster
getAllGet all items
Files
chatUser.js
Candy.Core.ChatUserChat User
Constants
ROLE_MODERATORModerator role
AFFILIATION_OWNERAffiliation owner
Variables
data
Functions
getJidGets an unescaped user jid
getEscapedJidEscapes the user’s jid (node & resource get escaped)
getNickGets user nick
getRoleGets user role
getAffiliationGets user affiliation
isModeratorCheck if user is moderator.
addToOrRemoveFromPrivacyListConvenience function for adding/removing users from ignore list.
getPrivacyListReturns the privacy list of the listname of the param.
isInPrivacyListTests if this user ignores the user provided by jid.
setCustomDataStores custom data
getCustomDataRetrieve custom data
Files
event.js
Candy.Core.EventChat Events
Enumerations
KEYSObserver keys
Candy.Core.Event.StropheStrophe-related events
Functions
ConnectActs on strophe status events and notifies view.
LoginNotify view that the login window should be displayed
Candy.Core.Event.JabberJabber related events
Functions
VersionResponds to a version request
PresenceActs on a presence event
BookmarksActs on a bookmarks event.
PrivacyListActs on a privacy list event and sets up the current privacy list of this user.
PrivacyListErrorActs when a privacy list error has been received.
MessageActs on room, admin and server messages and notifies the view if required.
Candy.Core.Event.Jabber.RoomRoom specific events
Functions
LeaveLeaves a room and cleans up related data and notifies view.
DiscoSets informations to rooms according to the disco info received.
PresenceActs on various presence messages (room leaving, room joining, error presence) and notifies view.
PresenceErrorActs when a presence of type error has been retrieved.
MessageActs on various message events (subject changed, private chat message, multi-user chat message) and notifies view.
Files
event.js
Candy.View.EventEmpty hooks to capture events and inject custom code.
Candy.View.Event.ChatChat-related events
Functions
onAdminMessageCalled when receiving admin messages
onDisconnectCalled when client disconnects
onAuthfailCalled when authentication fails
Candy.View.Event.RoomRoom-related events
Functions
onAddCalled when a new room gets added
onShowCalled when a room gets shown
onHideCalled when a room gets hidden
onSubjectChangeCalled when a subject of a room gets changed
onCloseCalled after a room has been left/closed
onPresenceChangeCalled when presence of user changes (kick, ban)
Candy.View.Event.RosterRoster-related events
Functions
onUpdateCalled after a user have been added to the roster
onContextMenuCalled when a user clicks on the action menu arrow.
afterContextMenuCalled when after a the context menu is rendered
Candy.View.Event.MessageMessage-related events
Functions
beforeShowCalled before a new message will be shown.
onShowCalled after a new message has been shown
beforeSendCalled before a message get sent
Candy.View.ObserverObserves Candy core events
Candy.View.Observer.ChatChat events
Functions
updateThe update method gets called whenever an event to which “Chat” is subscribed.
Candy.View.Observer.PresencePresence update events
Functions
updateEvery presence update gets dispatched from this method.
notifyPrivateChatsNotify private user chats if existing
Candy.View.Observer.PresenceErrorPresence error events
Functions
updatePresence errors get handled in this method
Candy.View.Observer.MessageMessage related events
Functions
updateMessages received get dispatched from this method.
Candy.View.Observer.LoginHandles when display login window should appear
Functions
updateThe login event gets dispatched to this method
Candy.View.PaneCandy view pane handles everything regarding DOM updates etc.
Candy.View.Pane.WindowWindow related view updates
Variables
autoscrollBoolean whether autoscroll is enabled
Functions
hasFocusChecks if window has focus
increaseUnreadMessagesIncreases unread message count in window title by one.
reduceUnreadMessagesReduce unread message count in window title by `num`.
clearUnreadMessagesClear unread message count in window title.
renderUnreadMessagesUpdate window title to show message count.
onFocusWindow focus event handler.
onBlurWindow blur event handler.
Candy.View.Pane.ChatChat-View related view updates
Variables
roomsContains opened room elements
Functions
addTabAdd a tab to the chat pane.
getTabGet tab by JID.
removeTabRemove tab element.
setActiveTabSet the active tab.
increaseUnreadMessagesIncrease unread message count in a tab by one.
clearUnreadMessagesClear unread message count in a tab.
tabClickTab click event: show the room associated with the tab and stops the event from doing the default.
tabCloseTab close (click) event: Leave the room (groupchat) or simply close the tab (chat).
allTabsClosedAll tabs closed event: Disconnect from service.
fitTabsFit tab size according to window size
updateToolbarShow toolbar
adminMessageDisplay admin message
infoMessageDisplay info message.
onInfoMessageDisplay info message.
Candy.View.Pane.ToolbarChat toolbar for things like emoticons toolbar, room management etc.
Functions
showShow toolbar.
hideHide toolbar.
playSoundPlay sound (default method).
onPlaySoundSound play event handler.
onSoundControlClickSound control click event handler.
onAutoscrollControlClickAutoscroll control event handler.
onStatusMessageControlClickStatus message control event handler.
updateUserCountUpdate usercount element with count.
Candy.View.Pane.ModalModal window
Functions
showDisplay modal window
hideHide modal window
showSpinnerShow loading spinner
hideSpinnerHide loading spinner
showCloseControlShow a close button
hideCloseControlHide the close button
showLoginFormShow the login form modal
showEnterPasswordFormShows a form for entering room password
showNicknameConflictFormShows a form indicating that the nickname is already taken and for chosing a new nickname
showErrorShow modal containing error message
Candy.View.Pane.TooltipClass to display tooltips over specific elements
Functions
showShow a tooltip on event.currentTarget with content specified or content within the target’s attribute data-tooltip.
Candy.View.Pane.ContextContext menu for actions and settings
Functions
initInitialize context menu and setup mouseleave handler.
showShow context menu (positions it according to the window height/width)
getMenuLinksExtends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those.
initialMenuLinks
showEmoticonsMenuShows the special emoticons menu
Candy.View.Pane.RoomEverything which belongs to room view things belongs here.
Functions
initInitialize a new room and inserts the room html into the DOM
showShow a specific room and hides the other rooms (if there are any)
setSubjectCalled when someone changes the subject in the channel
closeClose a room and remove everything in the DOM belonging to this room.
appendToMessagePaneAppend a new message to the message pane.
sliceMessagePaneSlices the message pane after the max amount of messages specified in the Candy View options (limit setting).
scrollToBottomScroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function.
onScrollToBottomScrolls to the latest message received/sent.
onScrollToStoredPositionWhen autoscroll is off, the position where the scrollbar is has to be stored for each room, because it otherwise goes to the top in the message window.
setFocusToFormSet focus to the message input field within the message form.
setUserSets or updates the current user in the specified room (called by <Candy.View.Pane.Roster.update>) and set specific informations (roles and affiliations) on the room tab (chat-pane).
getUserGet the current user in the room specified with the jid
ignoreUserIgnore specified user and add the ignore icon to the roster item of the user
unignoreUserUnignore an ignored user and remove the ignore icon of the roster item.
addIgnoreIconAdd the ignore icon to the roster item of the specified user
removeIgnoreIconRemove the ignore icon to the roster item of the specified user
getPaneGet the chat room pane or a subPane of it (if subPane is specified)
Candy.View.Pane.PrivateRoomPrivate room handling
Functions
openOpens a new private room
setStatusSet offline or online status for private rooms (when one of the participants leaves the room)
updateCalled by Candy.View.Observer.Presence.update to update the roster if needed.
userClickClick handler for opening a private room
joinAnimationAnimates specified elementId on join
leaveAnimationLeave animation for specified element id and removes the DOM element on completion.
Candy.View.Pane.MessageMessage submit/show handling
Functions
submiton submit handler for message field sends the message to the server and if it’s a private chat, shows the message immediately because the server doesn’t send back those message.
showShow a message in the message pane
Files
template.js
Candy.View.TemplateContains mustache.js templates
Files
translation.js
Candy.View.TranslationContains translations

Candy

Candy base class for initalizing the view and the core

Parameters

(Candy) selfitself
(jQuery) $jQuery
Summary
Variables
aboutAbout candy
Functions
initInit view & core
Files
core.js

Variables

about

self.about

About candy

Contains

(String) nameCandy
(Float) versionCandy version

Functions

init

self.init = function(service,
options)

Init view & core

Parameters

(String) serviceURL to the BOSH interface
(Object) optionsOptions for candy

Options

(Boolean) debugDebug (Default: false)
(Array|Boolean) autojoinAutojoin these channels.  When boolean true, do not autojoin, wait if the server sends something.

Files

core.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.Core

Candy Chat Core

Parameters

(Candy.Core) selfitself
(Strophe) StropheStrophe JS
(jQuery) $jQuery
Summary
Variables
autojoinIf set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).
Functions
initInitialize Core.
connectConnect to the jabber host.
attachAttach an already binded & connected session to the server
disconnectLeave all rooms and disconnect
addHandlerWrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
getUserGets current user
setUserSet current user.
getConnectionGets Strophe connection
getRoomsGets all joined rooms
isAnonymousConnectionReturns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
getOptionsGets options
getRoomGets a specific room
onWindowUnloadwindow.onbeforeunload event which disconnects the client from the Jabber server.
rawInput(Overridden from Strophe.Connection.rawInput)
logOverridden to do something useful if debug is set to true.
Files
view.js

Variables

autojoin

autojoin: true

If set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).  You may want to define an array of rooms to autojoin: `[‘ro.nosp@m.om1@conferenc.nosp@m.e.host.tld’, ‘room2...]` (ejabberd, Openfire, ...)

Functions

init

self.init = function(service,
options)

Initialize Core.

Parameters

(String) serviceURL of BOSH service
(Object) optionsOptions for candy

connect

self.connect = function(jidOrHost,
password,
nick)

Connect to the jabber host.

There are four different procedures to login

connect(‘JID’, ‘password’)Connect a registered user
connect(‘domain’)Connect anonymously to the domain.  The user should receive a random JID.
connect(‘domain’, null, ‘nick’)Connect anonymously to the domain.  The user should receive a random JID but with a nick set.
connect(‘JID’)Show login form and prompt for password.  JID input is hidden.
connect()Show login form and prompt for JID and password.

See

Candy.Core.attach() for attaching an already established session.

Parameters

(String) jidOrHostJID or Host
(String) passwordPassword of the user
(String) nickNick of the user.  Set one if you want to anonymously connect but preset a nick.  If jidOrHost is a domain and this param is not set, Candy will prompt for a nick.

attach

self.attach = function(jid,
sid,
rid)

Attach an already binded & connected session to the server

See Strophe.Connection.attach

Parameters

(String) jidJabber ID
(Integer) sidSession ID
(Integer) ridrid

disconnect

self.disconnect = function()

Leave all rooms and disconnect

addHandler

self.addHandler = function(handler,
ns,
name,
type,
id,
from,
options)

Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.

Parameters

(Function) handlerThe user callback.
(String) nsThe namespace to match.
(String) nameThe stanza name to match.
(String) typeThe stanza type attribute to match.
(String) idThe stanza id attribute to match.
(String) fromThe stanza from attribute to match.
(String) optionsThe handler options

Returns

A reference to the handler that can be used to remove it.

getUser

self.getUser = function()

Gets current user

Returns

Instance of Candy.Core.ChatUser

setUser

self.setUser = function(user)

Set current user.  Needed when anonymous login is used, as jid gets retrieved later.

Parameters

(Candy.Core.ChatUser) userUser instance

getConnection

self.getConnection = function()

Gets Strophe connection

Returns

Instance of Strophe.Connection

getRooms

self.getRooms = function()

Gets all joined rooms

Returns

Object containing instances of Candy.Core.ChatRoom

isAnonymousConnection

self.isAnonymousConnection = function()

Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.

Returns

(Boolean)

getOptions

self.getOptions = function()

Gets options

Returns

Object

getRoom

self.getRoom = function(roomJid)

Gets a specific room

Parameters

(String) roomJidJID of the room

Returns

If the room is joined, instance of Candy.Core.ChatRoom, otherwise null.

onWindowUnload

self.onWindowUnload = function()

window.onbeforeunload event which disconnects the client from the Jabber server.

rawInput

self.rawInput = function(data)

(Overridden from Strophe.Connection.rawInput)

Logs all raw input if debug is set to true.

log

self.log = function()

Overridden to do something useful if debug is set to true.

See: Candy.Core#init

Files

view.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.View

The Candy View Class

Parameters

(Candy.View) selfitself
(jQuery) $jQuery
Summary
Functions
initInitialize chat view (setup DOM, register handlers & observers)
getCurrentGet current container & roomJid in an object.
getOptionsGets options
Files
util.js

Functions

init

self.init = function(container,
options)

Initialize chat view (setup DOM, register handlers & observers)

Parameters

(jQuery.element) containerContainer element of the whole chat view
(Object) optionsOptions: see _options field (value passed here gets extended by the default value in _options field)

getCurrent

self.getCurrent = function()

Get current container & roomJid in an object.

Returns

Object containing container & roomJid

getOptions

self.getOptions = function()

Gets options

Returns

Object

Files

util.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.Util

Candy utils

Parameters

(Candy.Util) selfitself
(jQuery) $jQuery
Summary
Functions
jidToIdTranslates a jid to a MD5-Id
escapeJidEscapes a jid (node & resource get escaped)
unescapeJidUnescapes a jid (node & resource get unescaped)
cropCrop a string with the specified length
setCookieSets a new cookie
cookieExistsTests if a cookie with the given name exists
getCookieReturns the cookie value if there’s one with this name, otherwise returns undefined
deleteCookieDeletes a cookie with the given name
getPosLeftAccordingToWindowBoundsFetches the window width and element width and checks if specified position + element width is bigger than the window width.
getPosTopAccordingToWindowBoundsFetches the window height and element height and checks if specified position + element height is bigger than the window height.
localizedTimeLocalizes ISO-8610 Date with the time/dateformat specified in the translation.
iso8610toDateParses a ISO-8610 Date to a Date-Object.
isEmptyObjectIE7 doesn’t work with jQuery.isEmptyObject (<=1.5.1), workaround.
forceRedrawFix IE7 not redrawing under some circumstances.

Functions

jidToId

self.jidToId = function(jid)

Translates a jid to a MD5-Id

Parameters

(String) jidJid

Returns

MD5-ified jid

escapeJid

self.escapeJid = function(jid)

Escapes a jid (node & resource get escaped)

See

XEP-0106

Parameters

(String) jidJid

Returns

(String)escaped jid

unescapeJid

self.unescapeJid = function(jid)

Unescapes a jid (node & resource get unescaped)

See

XEP-0106

Parameters

(String) jidJid

Returns

(String)unescaped Jid

crop

self.crop = function(str,
len)

Crop a string with the specified length

Parameters

(String) strString to crop
(Integer) lenMax length

setCookie

self.setCookie = function(name,
value,
lifetime_days)

Sets a new cookie

Parameters

(String) namecookie name
(String) valueValue
(Integer) lifetime_daysLifetime in days

cookieExists

self.cookieExists = function(name)

Tests if a cookie with the given name exists

Parameters

(String) nameCookie name

Returns

(Boolean)true/false

getCookie

self.getCookie = function(name)

Returns the cookie value if there’s one with this name, otherwise returns undefined

Parameters

(String) nameCookie name

Returns

Cookie value or undefined

deleteCookie

self.deleteCookie = function(name)

Deletes a cookie with the given name

Parameters

(String) namecookie name

getPosLeftAccordingToWindowBounds

self.getPosLeftAccordingToWindowBounds = function(elem,
pos)

Fetches the window width and element width and checks if specified position + element width is bigger than the window width.

If this evaluates to true, the position gets substracted by the element width.

Parameters

(jQuery.Element) elemElement to position
(Integer) posPosition left

Returns

Object containing `px` (calculated position in pixel) and `alignment` (alignment of the element in relation to pos, either ‘left’ or ‘right’)

getPosTopAccordingToWindowBounds

self.getPosTopAccordingToWindowBounds = function(elem,
pos)

Fetches the window height and element height and checks if specified position + element height is bigger than the window height.

If this evaluates to true, the position gets substracted by the element height.

Parameters

(jQuery.Element) elemElement to position
(Integer) posPosition top

Returns

Object containing `px` (calculated position in pixel) and `alignment` (alignment of the element in relation to pos, either ‘top’ or ‘bottom’)

localizedTime

self.localizedTime = function(dateTime)

Localizes ISO-8610 Date with the time/dateformat specified in the translation.

See: libs/dateformat/dateFormat.js See: src/view/translation.js See: jquery-i18n/jquery.i18n.js

Parameters

(String) dateTimeISO-8610 Datetime

Returns

If current date is equal to the date supplied, format with timeFormat, otherwise with dateFormat

iso8610toDate

Parses a ISO-8610 Date to a Date-Object.

Uses a fallback if the client’s browser doesn’t support it.

Quote

ECMAScript revision 5 adds native support for ISO-8601 dates in the Date.parse method, but many browsers currently on the market (Safari 4, Chrome 4, IE 6-8) do not support it.

Credits

Colin Snover

Parameters

(String) dateISO-8610 Date

Returns

Date-Object

isEmptyObject

self.isEmptyObject = function(obj)

IE7 doesn’t work with jQuery.isEmptyObject (<=1.5.1), workaround.

Parameters

(Object) objthe object to test for

Returns

Boolean true or false.

forceRedraw

self.forceRedraw = function(elem)

Fix IE7 not redrawing under some circumstances.

Parameters

(jQuery.element) elemjQuery element to redraw

Candy.Util.Parser

Parser for emoticons, links and also supports escaping.

Summary
Functions
setEmoticonPathSet emoticons location.
Variables
emoticonsArray containing emoticons to be replaced by their images.
Functions
emotifyReplaces text-emoticons with their image equivalent.
linkifyReplaces URLs with a HTML-link.
escapeEscapes a text using a jQuery function (like htmlspecialchars in PHP)
allDoes everything of the parser: escaping, linkifying and emotifying.

Functions

setEmoticonPath

setEmoticonPath: function(path)

Set emoticons location.

Parameters

(String) pathlocation of emoticons with trailing slash

Variables

emoticons

Array containing emoticons to be replaced by their images.

Can be overridden/extended.

Functions

emotify

emotify: function(text)

Replaces text-emoticons with their image equivalent.

Parameters

(String) textText to emotify

Returns

Emotified text

linkify

linkify: function(text)

Replaces URLs with a HTML-link.

Parameters

(String) textText to linkify

Returns

Linkified text

escape

escape: function(text)

Escapes a text using a jQuery function (like htmlspecialchars in PHP)

Parameters

(String) textText to escape

Returns

Escaped text

all

all: function(text)

Does everything of the parser: escaping, linkifying and emotifying.

Parameters

(String) textText to parse

Returns

Parsed text

Candy.Util.Observable

A class can be extended with the observable to be able to notify observers

Summary
Functions
addObserverAdd an observer to the observer list
deleteObserverDelete observer from list
clearObserversDeletes all observers in list
notifyObserversNotify all of its observers of a certain event.
Files
action.js

Functions

addObserver

self.addObserver = function(key,
obj)

Add an observer to the observer list

Parameters

(String) keyThe key the observer listens to
(Callback) objThe observer callback

deleteObserver

self.deleteObserver = function(key,
obj)

Delete observer from list

Parameters

(String) keyKey in which the observer lies
(Callback) objThe observer callback to be deleted

clearObservers

self.clearObservers = function(key)

Deletes all observers in list

Parameters

(String) keyIf defined, remove observers of this key, otherwise remove all including all keys.

notifyObservers

self.notifyObservers = function(key,
arg)

Notify all of its observers of a certain event.

Parameters

(String) keyKey to notify
(Object) argAn argument passed to the update-method of the observers

Files

action.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.Core.Action

Chat Actions (basicly a abstraction of Jabber commands)

Parameters

(Candy.Core.Action) selfitself
(Strophe) StropheStrophe
(jQuery) $jQuery

Candy.Core.Action.Jabber

Jabber actions

Summary
Functions
VersionReplies to a version request
RosterSends a request for a roster
PresenceSends a request for presence
ServicesSends a request for disco items
AutojoinWhen Candy.Core.getOptions().autojoin is true, request autojoin bookmarks (OpenFire)
ResetIgnoreListCreate new ignore privacy list (and reset the old one, if it exists).
RemoveIgnoreListRemove an existing ignore list.
GetIgnoreListGet existing ignore privacy list when connecting.
SetIgnoreListActiveSet ignore privacy list active
GetJidIfAnonymousOn anonymous login, initially we don’t know the jid and as a result, Candy.Core._user doesn’t have a jid.

Functions

Version

Version: function(msg)

Replies to a version request

Parameters

(jQuery.element) msgjQuery element

Roster

Roster: function()

Sends a request for a roster

Presence

Presence: function(attr)

Sends a request for presence

Parameters

(Object) attrOptional attributes

Services

Services: function()

Sends a request for disco items

Autojoin

Autojoin: function()

When Candy.Core.getOptions().autojoin is true, request autojoin bookmarks (OpenFire)

Otherwise, if Candy.Core.getOptions().autojoin is an array, join each channel specified.

ResetIgnoreList

ResetIgnoreList: function()

Create new ignore privacy list (and reset the old one, if it exists).

RemoveIgnoreList

RemoveIgnoreList: function()

Remove an existing ignore list.

GetIgnoreList

GetIgnoreList: function()

Get existing ignore privacy list when connecting.

SetIgnoreListActive

SetIgnoreListActive: function()

Set ignore privacy list active

GetJidIfAnonymous

GetJidIfAnonymous: function()

On anonymous login, initially we don’t know the jid and as a result, Candy.Core._user doesn’t have a jid.  Check if user doesn’t have a jid and get it if necessary from the connection.

Candy.Core.Action.Jabber.Room

Room-specific commands

Summary
Functions
JoinRequests disco of specified room and joins afterwards.
LeaveLeaves a room.
DiscoRequests disco info of a room.
MessageSend message
IgnoreUnignoreChecks if the user is already ignoring the target user, if yes: unignore him, if no: ignore him.
UpdatePrivacyListUpdates privacy list according to the privacylist in the currentUser

Functions

Join

Join: function(roomJid,
password)

Requests disco of specified room and joins afterwards.

TODO

maybe we should wait for disco and later join the room? but what if we send disco but don’t want/can join the room

Parameters

(String) roomJidRoom to join
(String) password[optional] Password for the room

Leave

Leave: function(roomJid)

Leaves a room.

Parameters

(String) roomJidRoom to leave

Disco

Disco: function(roomJid)

Requests disco info of a room.

Parameters

(String) roomJidRoom to get info for

Message

Message: function(roomJid,
msg,
type)

Send message

Parameters

(String) roomJidRoom to which send the message into
(String) msgMessage
(String) type”groupchat” or “chat” (“chat” is for private messages)

Returns

(Boolean)true if message is not empty after trimming, false otherwise.

IgnoreUnignore

IgnoreUnignore: function(userJid)

Checks if the user is already ignoring the target user, if yes: unignore him, if no: ignore him.

Uses the ignore privacy list set on connecting.

Parameters

(String) userJidTarget user jid

UpdatePrivacyList

UpdatePrivacyList: function()

Updates privacy list according to the privacylist in the currentUser

Candy.Core.Action.Jabber.Room.Admin

Room administration commands

Summary
Functions
UserActionKick or ban a user
SetSubjectSets subject (topic) of a room.
Files
chatRoom.js

Functions

UserAction

UserAction: function(roomJid,
userJid,
type,
reason)

Kick or ban a user

Parameters

(String) roomJidRoom in which the kick/ban should be done
(String) userJidVictim
(String) type”kick” or “ban”
(String) msgReason

Returns

(Boolean)true if sent successfully, false if type is not one of “kick” or “ban”.

SetSubject

SetSubject: function(roomJid,
subject)

Sets subject (topic) of a room.

Parameters

(String) roomJidRoom
(String) subjectSubject to set

Files

chatRoom.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.Core.ChatRoom

Candy Chat Room

Parameters

(String) roomJidRoom jid
Summary
Variables
roomObject containing roomJid and name.
userCurrent local user of this room.
RosterCandy.Core.ChatRoster instance
Functions
setUserSet user of this room.
getUserGet current local user
getJidGet room jid
setNameSet room name
getNameGet room name
setRosterSet roster of room
getRosterGet roster
Files
chatRoster.js

Variables

room

this.room

Object containing roomJid and name.

user

this.user

Current local user of this room.

Roster

Candy.Core.ChatRoster instance

Functions

setUser

this.setUser = function(user)

Set user of this room.

Parameters

(Candy.Core.ChatUser) userChat user

getUser

this.getUser = function()

Get current local user

Returns

(Object)Candy.Core.ChatUser instance or null

getJid

this.getJid = function()

Get room jid

Returns

(String)Room jid

setName

this.setName = function(name)

Set room name

Parameters

(String) nameRoom name

getName

this.getName = function()

Get room name

Returns

(String)Room name

setRoster

this.setRoster = function(roster)

Set roster of room

Parameters

(Candy.Core.ChatRoster) rosterChat roster

getRoster

this.getRoster = function()

Get roster

Returns (Candy.Core.ChatRoster) - instance

Files

chatRoster.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.Core.ChatRoster

Chat Roster

Summary
Variables
itemsRoster items
Functions
addAdd user to roster
removeRemove user from roster
getGet user from roster
getAllGet all items
Files
chatUser.js

Variables

items

this.items

Roster items

Functions

add

this.add = function(user)

Add user to roster

Parameters

(Candy.Core.ChatUser) userUser to add

remove

this.remove = function(jid)

Remove user from roster

Parameters

(String) jidUser jid

get

this.get = function(jid)

Get user from roster

Parameters

(String) jidUser jid

Returns

(Candy.Core.ChatUser)User

getAll

this.getAll = function()

Get all items

Returns

(Object)all roster items

Files

chatUser.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.Core.ChatUser

Chat User

Summary
Constants
ROLE_MODERATORModerator role
AFFILIATION_OWNERAffiliation owner
Variables
data
Functions
getJidGets an unescaped user jid
getEscapedJidEscapes the user’s jid (node & resource get escaped)
getNickGets user nick
getRoleGets user role
getAffiliationGets user affiliation
isModeratorCheck if user is moderator.
addToOrRemoveFromPrivacyListConvenience function for adding/removing users from ignore list.
getPrivacyListReturns the privacy list of the listname of the param.
isInPrivacyListTests if this user ignores the user provided by jid.
setCustomDataStores custom data
getCustomDataRetrieve custom data
Files
event.js

Constants

ROLE_MODERATOR

Moderator role

AFFILIATION_OWNER

Affiliation owner

Variables

data

this.data

User data containing

  • jid
  • nick
  • affiliation
  • role
  • privacyLists
  • customData to be used by e.g. plugins

Functions

getJid

this.getJid = function()

Gets an unescaped user jid

See

Candy.Util.unescapeJid

Returns

(String)jid

getEscapedJid

this.getEscapedJid = function()

Escapes the user’s jid (node & resource get escaped)

See

Candy.Util.escapeJid

Returns

(String)escaped jid

getNick

this.getNick = function()

Gets user nick

Returns

(String)nick

getRole

this.getRole = function()

Gets user role

Returns

(String)role

getAffiliation

this.getAffiliation = function()

Gets user affiliation

Returns

(String)affiliation

isModerator

this.isModerator = function()

Check if user is moderator.  Depends on the room.

Returns

(Boolean)true if user has role moderator or affiliation owner

addToOrRemoveFromPrivacyList

this.addToOrRemoveFromPrivacyList = function(list,
jid)

Convenience function for adding/removing users from ignore list.

Check if user is already in privacy list.  If yes, remove it.  If no, add it.

Parameters

(String) listTo which privacy list the user should be added / removed from.  Candy supports curently only the “ignore” list.
(String) jidUser jid to add/remove

Returns

(Array)Current privacy list.

getPrivacyList

this.getPrivacyList = function(list)

Returns the privacy list of the listname of the param.

Parameters

(String) listTo which privacy list the user should be added / removed from.  Candy supports curently only the “ignore” list.

Returns

(Array)Privacy List

isInPrivacyList

this.isInPrivacyList = function(list,
jid)

Tests if this user ignores the user provided by jid.

Parameters

(String) listPrivacy list
(String) jidJid to test for

Returns

(Boolean)

setCustomData

this.setCustomData = function(data)

Stores custom data

Parameter

(Object) dataObject containing custom data

getCustomData

this.getCustomData = function()

Retrieve custom data

Returns

(Object)Object containing custom data

Files

event.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.Core.Event

Chat Events

Parameters

(Candy.Core.Event) selfitself
(Strophe) StropheStrophe
(jQuery) $jQuery
(Candy.Util.Observable) observableObservable to mixin
Summary
Enumerations
KEYSObserver keys

Enumerations

KEYS

Observer keys

CHATChat events
PRESENCEPresence events
MESSAGEMessage events
LOGINLogin event

Candy.Core.Event.Strophe

Strophe-related events

Summary
Functions
ConnectActs on strophe status events and notifies view.
LoginNotify view that the login window should be displayed

Functions

Connect

Connect: function(status)

Acts on strophe status events and notifies view.

Parameters

(Strophe.Status) statusStrophe statuses

Login

self.Login = function(presetJid)

Notify view that the login window should be displayed

Parameters

(String) presetJidPreset user JID

Candy.Core.Event.Jabber

Jabber related events

Summary
Functions
VersionResponds to a version request
PresenceActs on a presence event
BookmarksActs on a bookmarks event.
PrivacyListActs on a privacy list event and sets up the current privacy list of this user.
PrivacyListErrorActs when a privacy list error has been received.
MessageActs on room, admin and server messages and notifies the view if required.

Functions

Version

Version: function(msg)

Responds to a version request

Parameters

(String) msgRaw XML Message

Returns

(Boolean)true

Presence

Presence: function(msg)

Acts on a presence event

Parameters

(String) msgRaw XML Message

Returns

(Boolean)true

Bookmarks

Bookmarks: function(msg)

Acts on a bookmarks event.  When a bookmark has the attribute autojoin set, joins this room.

Parameters

(String) msgRaw XML Message

Returns

(Boolean)true

PrivacyList

PrivacyList: function(msg)

Acts on a privacy list event and sets up the current privacy list of this user.

If no privacy list has been added yet, create the privacy list and listen again to this event.

Parameters

(String) msgRaw XML Message

Returns

(Boolean)false to disable the handler after first call.

PrivacyListError

PrivacyListError: function(msg)

Acts when a privacy list error has been received.

Currently only handles the case, when a privacy list doesn’t exist yet and creates one.

Parameters

(String) msgRaw XML Message

Returns

(Boolean)false to disable the handler after first call.

Message

Message: function(msg)

Acts on room, admin and server messages and notifies the view if required.

Parameters

(String) msgRaw XML Message

Returns

(Boolean)true

Candy.Core.Event.Jabber.Room

Room specific events

Summary
Functions
LeaveLeaves a room and cleans up related data and notifies view.
DiscoSets informations to rooms according to the disco info received.
PresenceActs on various presence messages (room leaving, room joining, error presence) and notifies view.
PresenceErrorActs when a presence of type error has been retrieved.
MessageActs on various message events (subject changed, private chat message, multi-user chat message) and notifies view.
Files
event.js

Functions

Leave

Leave: function(msg)

Leaves a room and cleans up related data and notifies view.

Parameters

(String) msgRaw XML Message

Returns

(Boolean)true

Disco

Disco: function(msg)

Sets informations to rooms according to the disco info received.

Parameters

(String) msgRaw XML Message

Returns

(Boolean)true

Presence

Presence: function(msg)

Acts on various presence messages (room leaving, room joining, error presence) and notifies view.

Parameters

(Object) msgjQuery object of XML message

Returns

(Boolean)true

PresenceError

PresenceError: function(msg)

Acts when a presence of type error has been retrieved.

Parameters

(Object) msgjQuery object of XML message

Returns

(Boolean)true

Message

Message: function(msg)

Acts on various message events (subject changed, private chat message, multi-user chat message) and notifies view.

Parameters

(String) msgjQuery object of XML message

Returns

(Boolean)true

Files

event.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.View.Event

Empty hooks to capture events and inject custom code.

Parameters

(Candy.View.Event) selfitself
(jQuery) $jQuery

Candy.View.Event.Chat

Chat-related events

Summary
Functions
onAdminMessageCalled when receiving admin messages
onDisconnectCalled when client disconnects
onAuthfailCalled when authentication fails

Functions

onAdminMessage

onAdminMessage: function(args)

Called when receiving admin messages

Parameters

(Object) args{subject, message}

onDisconnect

onDisconnect: function()

Called when client disconnects

onAuthfail

onAuthfail: function()

Called when authentication fails

Candy.View.Event.Room

Room-related events

Summary
Functions
onAddCalled when a new room gets added
onShowCalled when a room gets shown
onHideCalled when a room gets hidden
onSubjectChangeCalled when a subject of a room gets changed
onCloseCalled after a room has been left/closed
onPresenceChangeCalled when presence of user changes (kick, ban)

Functions

onAdd

onAdd: function(args)

Called when a new room gets added

Parameters

(Object) args{roomJid, type=chat|groupchat, element}

onShow

onShow: function(args)

Called when a room gets shown

Parameters

(Object) args{roomJid, element}

onHide

onHide: function(args)

Called when a room gets hidden

Parameters

(Object) args{roomJid, element}

onSubjectChange

onSubjectChange: function(args)

Called when a subject of a room gets changed

Parameters

(Object) args{roomJid, element, subject}

onClose

onClose: function(args)

Called after a room has been left/closed

Parameters

(Object) args{roomJid}

onPresenceChange

onPresenceChange: function(args)

Called when presence of user changes (kick, ban)

Parameters

(Object) args{roomJid, user, reason, type}

Candy.View.Event.Roster

Roster-related events

Summary
Functions
onUpdateCalled after a user have been added to the roster
onContextMenuCalled when a user clicks on the action menu arrow.
afterContextMenuCalled when after a the context menu is rendered

Functions

onUpdate

onUpdate: function(args)

Called after a user have been added to the roster

Parameters

(Object) args{roomJid, user, action, element}

onContextMenu

onContextMenu: function(args)

Called when a user clicks on the action menu arrow.  The return value is getting appended to the menulinks.

Parameters

(Object) args{roomJid, user}

Returns

(Object)containing menulinks

afterContextMenu

afterContextMenu: function(args)

Called when after a the context menu is rendered

Parameters

(Object) args{roomJid, element, user}

Candy.View.Event.Message

Message-related events

Summary
Functions
beforeShowCalled before a new message will be shown.
onShowCalled after a new message has been shown
beforeSendCalled before a message get sent

Functions

beforeShow

beforeShow: function(args)

Called before a new message will be shown.

Parameters

(Object) args{roomJid, nick, message}

Returns

(String) message

onShow

onShow: function(args)

Called after a new message has been shown

Parameters

(Object) args{roomJid, element, nick, message}

beforeSend

beforeSend: function(message)

Called before a message get sent

Parameters

(String) message

Returns

(String) message

Candy.View.Observer

Observes Candy core events

Parameters

(Candy.View.Observer) selfitself
(jQuery) $jQuery

Candy.View.Observer.Chat

Chat events

Summary
Functions
updateThe update method gets called whenever an event to which “Chat” is subscribed.

Functions

update

update: function(obj,
args)

The update method gets called whenever an event to which “Chat” is subscribed.

Currently listens for connection status updates & admin messages / motd

Parameters

(Candy.Core.Event) objCandy core event object
(Object) args{type, connection or message & subject}

Candy.View.Observer.Presence

Presence update events

Summary
Functions
updateEvery presence update gets dispatched from this method.
notifyPrivateChatsNotify private user chats if existing

Functions

update

update: function(obj,
args)

Every presence update gets dispatched from this method.

Parameters

(Candy.Core.Event) objCandy core event object
(Object) argsArguments differ on each type

Uses

notifyPrivateChats

notifyPrivateChats: function(user,
type)

Notify private user chats if existing

Parameters

(Candy.Core.chatUser) userUser which has done the event
(String) typeEvent type (leave, join, kick/ban)

Candy.View.Observer.PresenceError

Presence error events

Summary
Functions
updatePresence errors get handled in this method

Functions

update

update: function(obj,
args)

Presence errors get handled in this method

Parameters

(Candy.Core.Event) objCandy core event object
(Object) args{msg, type, roomJid, roomName}

Candy.View.Observer.Message

Message related events

Summary
Functions
updateMessages received get dispatched from this method.

Functions

update

update: function(obj,
args)

Messages received get dispatched from this method.

Parameters

(Candy.Core.Event) objCandy core event object
(Object) args{message, roomJid}

Candy.View.Observer.Login

Handles when display login window should appear

Summary
Functions
updateThe login event gets dispatched to this method

Functions

update

update: function(obj,
args)

The login event gets dispatched to this method

Parameters

(Candy.Core.Event) objCandy core event object
(Object) args{presetJid}

Candy.View.Pane

Candy view pane handles everything regarding DOM updates etc.

Parameters

(Candy.View.Pane) selfitself
(jQuery) $jQuery

Candy.View.Pane.Window

Window related view updates

Summary
Variables
autoscrollBoolean whether autoscroll is enabled
Functions
hasFocusChecks if window has focus
increaseUnreadMessagesIncreases unread message count in window title by one.
reduceUnreadMessagesReduce unread message count in window title by `num`.
clearUnreadMessagesClear unread message count in window title.
renderUnreadMessagesUpdate window title to show message count.
onFocusWindow focus event handler.
onBlurWindow blur event handler.

Variables

autoscroll

autoscroll: true

Boolean whether autoscroll is enabled

Functions

hasFocus

hasFocus: function()

Checks if window has focus

Returns

(Boolean)

increaseUnreadMessages

increaseUnreadMessages: function()

Increases unread message count in window title by one.

reduceUnreadMessages

reduceUnreadMessages: function(num)

Reduce unread message count in window title by `num`.

Parameters

(Integer) numUnread message count will be reduced by this value

clearUnreadMessages

clearUnreadMessages: function()

Clear unread message count in window title.

renderUnreadMessages

renderUnreadMessages: function(count)

Update window title to show message count.

Parameters

(Integer) countNumber of unread messages to show in window title

onFocus

onFocus: function()

Window focus event handler.

onBlur

onBlur: function()

Window blur event handler.

Candy.View.Pane.Chat

Chat-View related view updates

Summary
Variables
roomsContains opened room elements
Functions
addTabAdd a tab to the chat pane.
getTabGet tab by JID.
removeTabRemove tab element.
setActiveTabSet the active tab.
increaseUnreadMessagesIncrease unread message count in a tab by one.
clearUnreadMessagesClear unread message count in a tab.
tabClickTab click event: show the room associated with the tab and stops the event from doing the default.
tabCloseTab close (click) event: Leave the room (groupchat) or simply close the tab (chat).
allTabsClosedAll tabs closed event: Disconnect from service.
fitTabsFit tab size according to window size
updateToolbarShow toolbar
adminMessageDisplay admin message
infoMessageDisplay info message.
onInfoMessageDisplay info message.

Variables

rooms

rooms: []

Contains opened room elements

Functions

addTab

addTab: function(roomJid,
roomName,
roomType)

Add a tab to the chat pane.

Parameters

(String) roomJidJID of room
(String) roomNameTab label
(String) roomTypeType of room: `groupchat` or `chat`

getTab

getTab: function(roomJid)

Get tab by JID.

Parameters

(String) roomJidJID of room

Returns

(jQuery object)Tab element

removeTab

removeTab: function(roomJid)

Remove tab element.

Parameters

(String) roomJidJID of room

setActiveTab

setActiveTab: function(roomJid)

Set the active tab.

Add CSS classname `active` to the choosen tab and remove `active` from all other.

Parameters

(String) roomJidJID of room

increaseUnreadMessages

increaseUnreadMessages: function(roomJid)

Increase unread message count in a tab by one.

Parameters

(String) roomJidJID of room

Uses

clearUnreadMessages

clearUnreadMessages: function(roomJid)

Clear unread message count in a tab.

Parameters

(String) roomJidJID of room

Uses

tabClick

tabClick: function(e)

Tab click event: show the room associated with the tab and stops the event from doing the default.

tabClose

tabClose: function(e)

Tab close (click) event: Leave the room (groupchat) or simply close the tab (chat).

Parameters

(DOMEvent) eEvent triggered

Returns

(Boolean)false, this will stop the event from bubbling

allTabsClosed

allTabsClosed: function()

All tabs closed event: Disconnect from service.  Hide sound control.

TODO: Handle window close

Returns

(Boolean)false, this will stop the event from bubbling

fitTabs

fitTabs: function()

Fit tab size according to window size

updateToolbar

updateToolbar: function(roomJid)

Show toolbar

adminMessage

adminMessage: function(subject,
message)

Display admin message

Parameters

(String) subjectAdmin message subject
(String) messageMessage to be displayed

infoMessage

infoMessage: function(roomJid,
subject,
message)

Display info message.  This is a wrapper for onInfoMessage to be able to disable certain info messages.

Parameters

(String) roomJidRoom JID
(String) subjectSubject
(String) messageMessage

onInfoMessage

onInfoMessage: function(roomJid,
subject,
message)

Display info message.  Used by infoMessage and several other functions which do not wish that their info message can be disabled (such as kick/ban message or leave/join message in private chats).

Parameters

(String) roomJidRoom JID
(String) subjectSubject
(String) messageMessage

Candy.View.Pane.Toolbar

Chat toolbar for things like emoticons toolbar, room management etc.

Summary
Functions
showShow toolbar.
hideHide toolbar.
playSoundPlay sound (default method).
onPlaySoundSound play event handler.
onSoundControlClickSound control click event handler.
onAutoscrollControlClickAutoscroll control event handler.
onStatusMessageControlClickStatus message control event handler.
updateUserCountUpdate usercount element with count.

Functions

show

show: function()

Show toolbar.

hide

hide: function()

Hide toolbar.

playSound

playSound: function()

Play sound (default method).

onPlaySound

onPlaySound: function()

Sound play event handler.

Don’t call this method directly.  Call `playSound()` instead.  `playSound()` will only call this method if sound is enabled.

onSoundControlClick

onSoundControlClick: function()

Sound control click event handler.

Toggle sound (overwrite `playSound()`) and handle cookies.

onAutoscrollControlClick

onAutoscrollControlClick: function()

Autoscroll control event handler.

Toggle autoscroll

onStatusMessageControlClick

onStatusMessageControlClick: function()

Status message control event handler.

Toggle status message

updateUserCount

Update usercount element with count.

Parameters

(Integer) countCurrent usercount

Candy.View.Pane.Modal

Modal window

Summary
Functions
showDisplay modal window
hideHide modal window
showSpinnerShow loading spinner
hideSpinnerHide loading spinner
showCloseControlShow a close button
hideCloseControlHide the close button
showLoginFormShow the login form modal
showEnterPasswordFormShows a form for entering room password
showNicknameConflictFormShows a form indicating that the nickname is already taken and for chosing a new nickname
showErrorShow modal containing error message

Functions

show

show: function(html,
showCloseControl,
showSpinner)

Display modal window

Parameters

(String) htmlHTML code to put into the modal window
(Boolean) showCloseControlset to true if a close button should be displayed [default false]
(Boolean) showSpinnerset to true if a loading spinner should be shown [default false]

hide

hide: function(callback)

Hide modal window

Parameters

(Function) callbackCalls the specified function after modal window has been hidden.

showSpinner

showSpinner: function()

Show loading spinner

hideSpinner

hideSpinner: function()

Hide loading spinner

showCloseControl

showCloseControl: function()

Show a close button

hideCloseControl

hideCloseControl: function()

Hide the close button

showLoginForm

showLoginForm: function(message,
presetJid)

Show the login form modal

Parameters

(String) messageoptional message to display above the form
(String) presetJidoptional user jid. if set, the user will only be prompted for password.

showEnterPasswordForm

showEnterPasswordForm: function(roomJid,
roomName,
message)

Shows a form for entering room password

Parameters

(String) roomJidRoom jid to join
(String) roomNameRoom name
(String) message[optional] Message to show as the label

showNicknameConflictForm

showNicknameConflictForm: function(roomJid)

Shows a form indicating that the nickname is already taken and for chosing a new nickname

Parameters

(String) roomJidRoom jid to join

showError

showError: function(message,
replacements)

Show modal containing error message

Parameters

(String) messagekey of translation to display
(Array) replacementsarray containing replacements for translation (%s)

Candy.View.Pane.Tooltip

Class to display tooltips over specific elements

Summary
Functions
showShow a tooltip on event.currentTarget with content specified or content within the target’s attribute data-tooltip.

Functions

show

show: function(event,
content)

Show a tooltip on event.currentTarget with content specified or content within the target’s attribute data-tooltip.

On mouseleave on the target, hide the tooltip.

Parameters

(Event) eventTriggered event
(String) contentContent to display [optional]

Candy.View.Pane.Context

Context menu for actions and settings

Summary
Functions
initInitialize context menu and setup mouseleave handler.
showShow context menu (positions it according to the window height/width)
getMenuLinksExtends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those.
initialMenuLinks
showEmoticonsMenuShows the special emoticons menu

Functions

init

init: function()

Initialize context menu and setup mouseleave handler.

show

show: function(elem,
roomJid,
user)

Show context menu (positions it according to the window height/width)

Uses

getMenuLinks for getting menulinks the user has access to Candy.Util.getPosLeftAccordingToWindowBounds for positioning Candy.Util.getPosTopAccordingToWindowBounds for positioning

Calls

Candy.View.Event.Roster.afterContextMenu after showing the context menu

Parameters

(Element) elemOn which element it should be shown
(String) roomJidRoom Jid of the room it should be shown
(Candy.Core.chatUser) userUser

getMenuLinks

getMenuLinks: function(roomJid,
user,
elem)

Extends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those.

Returns

(Object)object containing the extended menulinks.

initialMenuLinks

initialMenuLinks: function()

Returns initial menulinks.  The following are initial

  • Private Chat
  • Ignore
  • Unignore
  • Kick
  • Ban
  • Change Subject

Returns

(Object)object containing those menulinks

showEmoticonsMenu

showEmoticonsMenu: function(elem)

Shows the special emoticons menu

Parameters

(Element) elemElement on which it should be positioned to.

Returns

(Boolean)true

Candy.View.Pane.Room

Everything which belongs to room view things belongs here.

Summary
Functions
initInitialize a new room and inserts the room html into the DOM
showShow a specific room and hides the other rooms (if there are any)
setSubjectCalled when someone changes the subject in the channel
closeClose a room and remove everything in the DOM belonging to this room.
appendToMessagePaneAppend a new message to the message pane.
sliceMessagePaneSlices the message pane after the max amount of messages specified in the Candy View options (limit setting).
scrollToBottomScroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function.
onScrollToBottomScrolls to the latest message received/sent.
onScrollToStoredPositionWhen autoscroll is off, the position where the scrollbar is has to be stored for each room, because it otherwise goes to the top in the message window.
setFocusToFormSet focus to the message input field within the message form.
setUserSets or updates the current user in the specified room (called by <Candy.View.Pane.Roster.update>) and set specific informations (roles and affiliations) on the room tab (chat-pane).
getUserGet the current user in the room specified with the jid
ignoreUserIgnore specified user and add the ignore icon to the roster item of the user
unignoreUserUnignore an ignored user and remove the ignore icon of the roster item.
addIgnoreIconAdd the ignore icon to the roster item of the specified user
removeIgnoreIconRemove the ignore icon to the roster item of the specified user
getPaneGet the chat room pane or a subPane of it (if subPane is specified)

Functions

init

init: function(roomJid,
roomName,
roomType)

Initialize a new room and inserts the room html into the DOM

Parameters

(String) roomJidRoom JID
(String) roomNameRoom name
(String) roomTypeType: either “groupchat” or “chat” (private chat)

Uses

Calls

Returns

(String)the room id of the element created.

show

show: function(roomJid)

Show a specific room and hides the other rooms (if there are any)

Parameters

(String) roomJidroom jid to show

setSubject

setSubject: function(roomJid,
subject)

Called when someone changes the subject in the channel

Parameters

(String) roomJidRoom Jid
(String) subjectThe new subject

close

close: function(roomJid)

Close a room and remove everything in the DOM belonging to this room.

NOTICE: There’s a rendering bug in Opera when all rooms have been closed.  (Take a look in the source for a more detailed description)

Parameters

(String) roomJidRoom to close

appendToMessagePane

appendToMessagePane: function(roomJid,
html)

Append a new message to the message pane.

Parameters

(String) roomJidRoom JID
(String) htmlrendered message html

sliceMessagePane

sliceMessagePane: function(roomJid)

Slices the message pane after the max amount of messages specified in the Candy View options (limit setting).

This is done to hopefully prevent browsers from getting slow after a certain amount of messages in the DOM.

The slice is only done when autoscroll is on, because otherwise someone might lose exactly the message he want to look for.

Parameters

(String) roomJidRoom JID

scrollToBottom

scrollToBottom: function(roomJid)

Scroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function.

Parameters

(String) roomJidRoom JID

Uses

onScrollToBottom

onScrollToBottom: function(roomJid)

Scrolls to the latest message received/sent.

Parameters

(String) roomJidRoom JID

onScrollToStoredPosition

onScrollToStoredPosition: function(roomJid)

When autoscroll is off, the position where the scrollbar is has to be stored for each room, because it otherwise goes to the top in the message window.

Parameters

(String) roomJidRoom JID

setFocusToForm

setFocusToForm: function(roomJid)

Set focus to the message input field within the message form.

Parameters

(String) roomJidRoom JID

setUser

setUser: function(roomJid,
user)

Sets or updates the current user in the specified room (called by <Candy.View.Pane.Roster.update>) and set specific informations (roles and affiliations) on the room tab (chat-pane).

Parameters

(String) roomJidRoom in which the user is set to.
(Candy.Core.ChatUser) userThe user

getUser

getUser: function(roomJid)

Get the current user in the room specified with the jid

Parameters

(String) roomJidRoom of which the user should be returned from

Returns

(Candy.Core.ChatUser)user

ignoreUser

ignoreUser: function(roomJid,
userJid)

Ignore specified user and add the ignore icon to the roster item of the user

Parameters

(String) roomJidRoom in which the user should be ignored
(String) userJidUser which should be ignored

unignoreUser

unignoreUser: function(roomJid,
userJid)

Unignore an ignored user and remove the ignore icon of the roster item.

Parameters

(String) roomJidRoom in which the user should be unignored
(String) userJidUser which should be unignored

addIgnoreIcon

addIgnoreIcon: function(roomJid,
userJid)

Add the ignore icon to the roster item of the specified user

Parameters

(String) roomJidRoom in which the roster item should be updated
(String) userJidUser of which the roster item should be updated

removeIgnoreIcon

removeIgnoreIcon: function(roomJid,
userJid)

Remove the ignore icon to the roster item of the specified user

Parameters

(String) roomJidRoom in which the roster item should be updated
(String) userJidUser of which the roster item should be updated

getPane

getPane: function(roomJid,
subPane)

Get the chat room pane or a subPane of it (if subPane is specified)

Parameters

(String) roomJidRoom in which the pane lies
(String) subPaneSub pane of the chat room pane if needed [optional]

Candy.View.Pane.PrivateRoom

Private room handling

Summary
Functions
openOpens a new private room
setStatusSet offline or online status for private rooms (when one of the participants leaves the room)
updateCalled by Candy.View.Observer.Presence.update to update the roster if needed.
userClickClick handler for opening a private room
joinAnimationAnimates specified elementId on join
leaveAnimationLeave animation for specified element id and removes the DOM element on completion.

Functions

open

open: function(roomJid,
roomName,
switchToRoom,
isNoConferenceRoomJid)

Opens a new private room

Parameters

(String) roomJidRoom jid to open
(String) roomNameRoom name
(Boolean) switchToRoomIf true, displayed room switches automatically to this room (e.g. when user clicks itself on another user to open a private chat)
(Boolean) isNoConferenceRoomJidtrue if a 3rd-party client sends a direct message to this user (not via the room) then the username is the node and not the resource.  This param addresses this case.

Calls

setStatus

setStatus: function(roomJid,
status)

Set offline or online status for private rooms (when one of the participants leaves the room)

Parameters

(String) roomJidPrivate room jid
(String) status”leave”/”join”

update

update: function(roomJid,
user,
action,
currentUser)

Called by Candy.View.Observer.Presence.update to update the roster if needed.  Adds/removes users from the roster list or updates informations on their items (roles, affiliations etc.)

TODO: Refactoring, this method has too much LOC.

Parameters

(String) roomJidRoom JID in which the update happens
(Candy.Core.ChatUser) userUser on which the update happens
(String) actionone of “join”, “leave”, “kick” and “ban”
(Candy.Core.ChatUser) currentUserCurrent user

userClick

userClick: function()

Click handler for opening a private room

joinAnimation

joinAnimation: function(elementId)

Animates specified elementId on join

Parameters

(String) elementIdSpecific element to do the animation on

leaveAnimation

leaveAnimation: function(elementId)

Leave animation for specified element id and removes the DOM element on completion.

Parameters

(String) elementIdSpecific element to do the animation on

Candy.View.Pane.Message

Message submit/show handling

Summary
Functions
submiton submit handler for message field sends the message to the server and if it’s a private chat, shows the message immediately because the server doesn’t send back those message.
showShow a message in the message pane
Files
template.js

Functions

submit

submit: function(event)

on submit handler for message field sends the message to the server and if it’s a private chat, shows the message immediately because the server doesn’t send back those message.

Parameters

(Event) eventTriggered event

show

show: function(roomJid,
name,
message,
timestamp)

Show a message in the message pane

Parameters

(String) roomJidroom in which the message has been sent to
(String) nameName of the user which sent the message
(String) messageMessage
(String) timestamp[optional] Timestamp of the message, if not present, current date.

Files

template.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.View.Template

Contains mustache.js templates

Files

translation.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Candy.View.Translation

Contains translations

self.about
About candy
self.init = function(service,
options)
Init view & core
autojoin: true
If set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).
self.init = function(service,
options)
Initialize Core.
self.connect = function(jidOrHost,
password,
nick)
Connect to the jabber host.
self.attach = function(jid,
sid,
rid)
Attach an already binded & connected session to the server
self.disconnect = function()
Leave all rooms and disconnect
self.addHandler = function(handler,
ns,
name,
type,
id,
from,
options)
Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
self.getUser = function()
Gets current user
self.setUser = function(user)
Set current user.
self.getConnection = function()
Gets Strophe connection
self.getRooms = function()
Gets all joined rooms
self.isAnonymousConnection = function()
Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
self.getOptions = function()
Gets options
self.getRoom = function(roomJid)
Gets a specific room
self.onWindowUnload = function()
window.onbeforeunload event which disconnects the client from the Jabber server.
self.rawInput = function(data)
(Overridden from Strophe.Connection.rawInput)
self.log = function()
Overridden to do something useful if debug is set to true.
self.init = function(container,
options)
Initialize chat view (setup DOM, register handlers & observers)
self.getCurrent = function()
Get current container & roomJid in an object.
self.getOptions = function()
Gets options
self.jidToId = function(jid)
Translates a jid to a MD5-Id
self.escapeJid = function(jid)
Escapes a jid (node & resource get escaped)
self.unescapeJid = function(jid)
Unescapes a jid (node & resource get unescaped)
self.crop = function(str,
len)
Crop a string with the specified length
self.setCookie = function(name,
value,
lifetime_days)
Sets a new cookie
self.cookieExists = function(name)
Tests if a cookie with the given name exists
self.getCookie = function(name)
Returns the cookie value if there’s one with this name, otherwise returns undefined
self.deleteCookie = function(name)
Deletes a cookie with the given name
self.getPosLeftAccordingToWindowBounds = function(elem,
pos)
Fetches the window width and element width and checks if specified position + element width is bigger than the window width.
self.getPosTopAccordingToWindowBounds = function(elem,
pos)
Fetches the window height and element height and checks if specified position + element height is bigger than the window height.
self.localizedTime = function(dateTime)
Localizes ISO-8610 Date with the time/dateformat specified in the translation.
self.isEmptyObject = function(obj)
IE7 doesn’t work with jQuery.isEmptyObject (<=1.5.1), workaround.
self.forceRedraw = function(elem)
Fix IE7 not redrawing under some circumstances.
setEmoticonPath: function(path)
Set emoticons location.
emotify: function(text)
Replaces text-emoticons with their image equivalent.
linkify: function(text)
Replaces URLs with a HTML-link.
escape: function(text)
Escapes a text using a jQuery function (like htmlspecialchars in PHP)
all: function(text)
Does everything of the parser: escaping, linkifying and emotifying.
self.addObserver = function(key,
obj)
Add an observer to the observer list
self.deleteObserver = function(key,
obj)
Delete observer from list
self.clearObservers = function(key)
Deletes all observers in list
self.notifyObservers = function(key,
arg)
Notify all of its observers of a certain event.
Version: function(msg)
Replies to a version request
Roster: function()
Sends a request for a roster
Presence: function(attr)
Sends a request for presence
Services: function()
Sends a request for disco items
Autojoin: function()
When Candy.Core.getOptions().autojoin is true, request autojoin bookmarks (OpenFire)
ResetIgnoreList: function()
Create new ignore privacy list (and reset the old one, if it exists).
RemoveIgnoreList: function()
Remove an existing ignore list.
GetIgnoreList: function()
Get existing ignore privacy list when connecting.
SetIgnoreListActive: function()
Set ignore privacy list active
GetJidIfAnonymous: function()
On anonymous login, initially we don’t know the jid and as a result, Candy.Core._user doesn’t have a jid.
Join: function(roomJid,
password)
Requests disco of specified room and joins afterwards.
Leave: function(roomJid)
Leaves a room.
Disco: function(roomJid)
Requests disco info of a room.
Message: function(roomJid,
msg,
type)
Send message
IgnoreUnignore: function(userJid)
Checks if the user is already ignoring the target user, if yes: unignore him, if no: ignore him.
UpdatePrivacyList: function()
Updates privacy list according to the privacylist in the currentUser
UserAction: function(roomJid,
userJid,
type,
reason)
Kick or ban a user
SetSubject: function(roomJid,
subject)
Sets subject (topic) of a room.
this.room
Object containing roomJid and name.
this.user
Current local user of this room.
this.setUser = function(user)
Set user of this room.
this.getUser = function()
Get current local user
this.getJid = function()
Get room jid
this.setName = function(name)
Set room name
this.getName = function()
Get room name
this.setRoster = function(roster)
Set roster of room
this.getRoster = function()
Get roster
this.items
Roster items
this.add = function(user)
Add user to roster
this.remove = function(jid)
Remove user from roster
this.get = function(jid)
Get user from roster
this.getAll = function()
Get all items
this.data
this.getJid = function()
Gets an unescaped user jid
this.getEscapedJid = function()
Escapes the user’s jid (node & resource get escaped)
this.getNick = function()
Gets user nick
this.getRole = function()
Gets user role
this.getAffiliation = function()
Gets user affiliation
this.isModerator = function()
Check if user is moderator.
this.addToOrRemoveFromPrivacyList = function(list,
jid)
Convenience function for adding/removing users from ignore list.
this.getPrivacyList = function(list)
Returns the privacy list of the listname of the param.
this.isInPrivacyList = function(list,
jid)
Tests if this user ignores the user provided by jid.
this.setCustomData = function(data)
Stores custom data
this.getCustomData = function()
Retrieve custom data
Connect: function(status)
Acts on strophe status events and notifies view.
self.Login = function(presetJid)
Notify view that the login window should be displayed
Version: function(msg)
Responds to a version request
Presence: function(msg)
Acts on a presence event
Bookmarks: function(msg)
Acts on a bookmarks event.
PrivacyList: function(msg)
Acts on a privacy list event and sets up the current privacy list of this user.
PrivacyListError: function(msg)
Acts when a privacy list error has been received.
Message: function(msg)
Acts on room, admin and server messages and notifies the view if required.
Leave: function(msg)
Leaves a room and cleans up related data and notifies view.
Disco: function(msg)
Sets informations to rooms according to the disco info received.
Presence: function(msg)
Acts on various presence messages (room leaving, room joining, error presence) and notifies view.
PresenceError: function(msg)
Acts when a presence of type error has been retrieved.
Message: function(msg)
Acts on various message events (subject changed, private chat message, multi-user chat message) and notifies view.
onAdminMessage: function(args)
Called when receiving admin messages
onDisconnect: function()
Called when client disconnects
onAuthfail: function()
Called when authentication fails
onAdd: function(args)
Called when a new room gets added
onShow: function(args)
Called when a room gets shown
onHide: function(args)
Called when a room gets hidden
onSubjectChange: function(args)
Called when a subject of a room gets changed
onClose: function(args)
Called after a room has been left/closed
onPresenceChange: function(args)
Called when presence of user changes (kick, ban)
onUpdate: function(args)
Called after a user have been added to the roster
onContextMenu: function(args)
Called when a user clicks on the action menu arrow.
afterContextMenu: function(args)
Called when after a the context menu is rendered
beforeShow: function(args)
Called before a new message will be shown.
onShow: function(args)
Called after a new message has been shown
beforeSend: function(message)
Called before a message get sent
update: function(obj,
args)
The update method gets called whenever an event to which “Chat” is subscribed.
update: function(obj,
args)
Every presence update gets dispatched from this method.
notifyPrivateChats: function(user,
type)
Notify private user chats if existing
update: function(obj,
args)
Presence errors get handled in this method
update: function(obj,
args)
Messages received get dispatched from this method.
update: function(obj,
args)
The login event gets dispatched to this method
autoscroll: true
Boolean whether autoscroll is enabled
hasFocus: function()
Checks if window has focus
increaseUnreadMessages: function()
Increases unread message count in window title by one.
reduceUnreadMessages: function(num)
Reduce unread message count in window title by `num`.
clearUnreadMessages: function()
Clear unread message count in window title.
renderUnreadMessages: function(count)
Update window title to show message count.
onFocus: function()
Window focus event handler.
onBlur: function()
Window blur event handler.
rooms: []
Contains opened room elements
addTab: function(roomJid,
roomName,
roomType)
Add a tab to the chat pane.
getTab: function(roomJid)
Get tab by JID.
removeTab: function(roomJid)
Remove tab element.
setActiveTab: function(roomJid)
Set the active tab.
increaseUnreadMessages: function(roomJid)
Increase unread message count in a tab by one.
clearUnreadMessages: function(roomJid)
Clear unread message count in a tab.
tabClick: function(e)
Tab click event: show the room associated with the tab and stops the event from doing the default.
tabClose: function(e)
Tab close (click) event: Leave the room (groupchat) or simply close the tab (chat).
allTabsClosed: function()
All tabs closed event: Disconnect from service.
fitTabs: function()
Fit tab size according to window size
updateToolbar: function(roomJid)
Show toolbar
adminMessage: function(subject,
message)
Display admin message
infoMessage: function(roomJid,
subject,
message)
Display info message.
onInfoMessage: function(roomJid,
subject,
message)
Display info message.
show: function()
Show toolbar.
hide: function()
Hide toolbar.
playSound: function()
Play sound (default method).
onPlaySound: function()
Sound play event handler.
onSoundControlClick: function()
Sound control click event handler.
onAutoscrollControlClick: function()
Autoscroll control event handler.
onStatusMessageControlClick: function()
Status message control event handler.
show: function(html,
showCloseControl,
showSpinner)
Display modal window
hide: function(callback)
Hide modal window
showSpinner: function()
Show loading spinner
hideSpinner: function()
Hide loading spinner
showCloseControl: function()
Show a close button
hideCloseControl: function()
Hide the close button
showLoginForm: function(message,
presetJid)
Show the login form modal
showEnterPasswordForm: function(roomJid,
roomName,
message)
Shows a form for entering room password
showNicknameConflictForm: function(roomJid)
Shows a form indicating that the nickname is already taken and for chosing a new nickname
showError: function(message,
replacements)
Show modal containing error message
show: function(event,
content)
Show a tooltip on event.currentTarget with content specified or content within the target’s attribute data-tooltip.
init: function()
Initialize context menu and setup mouseleave handler.
show: function(elem,
roomJid,
user)
Show context menu (positions it according to the window height/width)
getMenuLinks: function(roomJid,
user,
elem)
Extends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those.
initialMenuLinks: function()
showEmoticonsMenu: function(elem)
Shows the special emoticons menu
init: function(roomJid,
roomName,
roomType)
Initialize a new room and inserts the room html into the DOM
show: function(roomJid)
Show a specific room and hides the other rooms (if there are any)
setSubject: function(roomJid,
subject)
Called when someone changes the subject in the channel
close: function(roomJid)
Close a room and remove everything in the DOM belonging to this room.
appendToMessagePane: function(roomJid,
html)
Append a new message to the message pane.
sliceMessagePane: function(roomJid)
Slices the message pane after the max amount of messages specified in the Candy View options (limit setting).
scrollToBottom: function(roomJid)
Scroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function.
onScrollToBottom: function(roomJid)
Scrolls to the latest message received/sent.
onScrollToStoredPosition: function(roomJid)
When autoscroll is off, the position where the scrollbar is has to be stored for each room, because it otherwise goes to the top in the message window.
setFocusToForm: function(roomJid)
Set focus to the message input field within the message form.
setUser: function(roomJid,
user)
Sets or updates the current user in the specified room (called by Candy.View.Pane.Roster.update) and set specific informations (roles and affiliations) on the room tab (chat-pane).
getUser: function(roomJid)
Get the current user in the room specified with the jid
ignoreUser: function(roomJid,
userJid)
Ignore specified user and add the ignore icon to the roster item of the user
unignoreUser: function(roomJid,
userJid)
Unignore an ignored user and remove the ignore icon of the roster item.
addIgnoreIcon: function(roomJid,
userJid)
Add the ignore icon to the roster item of the specified user
removeIgnoreIcon: function(roomJid,
userJid)
Remove the ignore icon to the roster item of the specified user
getPane: function(roomJid,
subPane)
Get the chat room pane or a subPane of it (if subPane is specified)
open: function(roomJid,
roomName,
switchToRoom,
isNoConferenceRoomJid)
Opens a new private room
setStatus: function(roomJid,
status)
Set offline or online status for private rooms (when one of the participants leaves the room)
update: function(roomJid,
user,
action,
currentUser)
Called by Candy.View.Observer.Presence.update to update the roster if needed.
userClick: function()
Click handler for opening a private room
joinAnimation: function(elementId)
Animates specified elementId on join
leaveAnimation: function(elementId)
Leave animation for specified element id and removes the DOM element on completion.
submit: function(event)
on submit handler for message field sends the message to the server and if it’s a private chat, shows the message immediately because the server doesn’t send back those message.
show: function(roomJid,
name,
message,
timestamp)
Show a message in the message pane
Close