| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
| candy.js | |
| Candy | Candy base class for initalizing the view and the core |
| Variables | |
| about | About candy |
| Functions | |
| init | Init view & core |
| Files | |
| core.js | |
| Candy.Core | Candy Chat Core |
| Variables | |
| autojoin | If set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire). |
| Functions | |
| init | Initialize Core. |
| connect | Connect to the jabber host. |
| attach | Attach an already binded & connected session to the server |
| disconnect | Leave all rooms and disconnect |
| addHandler | Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection. |
| getUser | Gets current user |
| setUser | Set current user. |
| getConnection | Gets Strophe connection |
| getRooms | Gets all joined rooms |
| isAnonymousConnection | Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param. |
| getOptions | Gets options |
| getRoom | Gets a specific room |
| onWindowUnload | window.onbeforeunload event which disconnects the client from the Jabber server. |
| rawInput | (Overridden from Strophe.Connection.rawInput) |
| log | Overridden to do something useful if debug is set to true. |
| Files | |
| view.js | |
| Candy.View | The Candy View Class |
| Functions | |
| init | Initialize chat view (setup DOM, register handlers & observers) |
| getCurrent | Get current container & roomJid in an object. |
| getOptions | Gets options |
| Files | |
| util.js | |
| Candy.Util | Candy utils |
| Functions | |
| jidToId | Translates a jid to a MD5-Id |
| escapeJid | Escapes a jid (node & resource get escaped) |
| unescapeJid | Unescapes a jid (node & resource get unescaped) |
| crop | Crop a string with the specified length |
| setCookie | Sets a new cookie |
| cookieExists | Tests if a cookie with the given name exists |
| getCookie | Returns the cookie value if there’s one with this name, otherwise returns undefined |
| deleteCookie | Deletes a cookie with the given name |
| getPosLeftAccordingToWindowBounds | Fetches the window width and element width and checks if specified position + element width is bigger than the window width. |
| getPosTopAccordingToWindowBounds | Fetches the window height and element height and checks if specified position + element height is bigger than the window height. |
| localizedTime | Localizes ISO-8610 Date with the time/dateformat specified in the translation. |
| iso8610toDate | Parses a ISO-8610 Date to a Date-Object. |
| isEmptyObject | IE7 doesn’t work with jQuery.isEmptyObject (<=1.5.1), workaround. |
| forceRedraw | Fix IE7 not redrawing under some circumstances. |
| Candy. | Parser for emoticons, links and also supports escaping. |
| Functions | |
| setEmoticonPath | Set emoticons location. |
| Variables | |
| emoticons | Array containing emoticons to be replaced by their images. |
| Functions | |
| emotify | Replaces text-emoticons with their image equivalent. |
| linkify | Replaces URLs with a HTML-link. |
| escape | Escapes a text using a jQuery function (like htmlspecialchars in PHP) |
| all | Does everything of the parser: escaping, linkifying and emotifying. |
| Candy. | A class can be extended with the observable to be able to notify observers |
| Functions | |
| addObserver | Add an observer to the observer list |
| deleteObserver | Delete observer from list |
| clearObservers | Deletes all observers in list |
| notifyObservers | Notify all of its observers of a certain event. |
| Files | |
| action.js | |
| Candy. | Chat Actions (basicly a abstraction of Jabber commands) |
| Candy. | Jabber actions |
| Functions | |
| Version | Replies to a version request |
| Roster | Sends a request for a roster |
| Presence | Sends a request for presence |
| Services | Sends a request for disco items |
| Autojoin | When Candy.Core.getOptions().autojoin is true, request autojoin bookmarks (OpenFire) |
| ResetIgnoreList | Create new ignore privacy list (and reset the old one, if it exists). |
| RemoveIgnoreList | Remove an existing ignore list. |
| GetIgnoreList | Get existing ignore privacy list when connecting. |
| SetIgnoreListActive | Set ignore privacy list active |
| GetJidIfAnonymous | On anonymous login, initially we don’t know the jid and as a result, Candy.Core._user doesn’t have a jid. |
| Candy. | Room-specific commands |
| Functions | |
| Join | Requests disco of specified room and joins afterwards. |
| Leave | Leaves a room. |
| Disco | Requests disco info of a room. |
| Message | Send message |
| IgnoreUnignore | Checks if the user is already ignoring the target user, if yes: unignore him, if no: ignore him. |
| UpdatePrivacyList | Updates privacy list according to the privacylist in the currentUser |
| Candy. | Room administration commands |
| Functions | |
| UserAction | Kick or ban a user |
| SetSubject | Sets subject (topic) of a room. |
| Files | |
| chatRoom.js | |
| Candy. | Candy Chat Room |
| Variables | |
| room | Object containing roomJid and name. |
| user | Current local user of this room. |
| Roster | Candy.Core.ChatRoster instance |
| Functions | |
| setUser | Set user of this room. |
| getUser | Get current local user |
| getJid | Get room jid |
| setName | Set room name |
| getName | Get room name |
| setRoster | Set roster of room |
| getRoster | Get roster |
| Files | |
| chatRoster.js | |
| Candy. | Chat Roster |
| Variables | |
| items | Roster items |
| Functions | |
| add | Add user to roster |
| remove | Remove user from roster |
| get | Get user from roster |
| getAll | Get all items |
| Files | |
| chatUser.js | |
| Candy. | Chat User |
| Constants | |
| ROLE_MODERATOR | Moderator role |
| AFFILIATION_OWNER | Affiliation owner |
| Variables | |
| data | |
| Functions | |
| getJid | Gets an unescaped user jid |
| getEscapedJid | Escapes the user’s jid (node & resource get escaped) |
| getNick | Gets user nick |
| getRole | Gets user role |
| getAffiliation | Gets user affiliation |
| isModerator | Check if user is moderator. |
| addToOrRemoveFromPrivacyList | Convenience function for adding/removing users from ignore list. |
| getPrivacyList | Returns the privacy list of the listname of the param. |
| isInPrivacyList | Tests if this user ignores the user provided by jid. |
| setCustomData | Stores custom data |
| getCustomData | Retrieve custom data |
| Files | |
| event.js | |
| Candy. | Chat Events |
| Enumerations | |
| KEYS | Observer keys |
| Candy. | Strophe-related events |
| Functions | |
| Connect | Acts on strophe status events and notifies view. |
| Login | Notify view that the login window should be displayed |
| Candy. | Jabber related events |
| Functions | |
| Version | Responds to a version request |
| Presence | Acts on a presence event |
| Bookmarks | Acts on a bookmarks event. |
| PrivacyList | Acts on a privacy list event and sets up the current privacy list of this user. |
| PrivacyListError | Acts when a privacy list error has been received. |
| Message | Acts on room, admin and server messages and notifies the view if required. |
| Candy. | Room specific events |
| Functions | |
| Leave | Leaves a room and cleans up related data and notifies view. |
| Disco | Sets informations to rooms according to the disco info received. |
| Presence | Acts on various presence messages (room leaving, room joining, error presence) and notifies view. |
| PresenceError | Acts when a presence of type error has been retrieved. |
| Message | Acts on various message events (subject changed, private chat message, multi-user chat message) and notifies view. |
| Files | |
| event.js | |
| Candy. | Empty hooks to capture events and inject custom code. |
| Candy. | Chat-related events |
| Functions | |
| onAdminMessage | Called when receiving admin messages |
| onDisconnect | Called when client disconnects |
| onAuthfail | Called when authentication fails |
| Candy. | Room-related events |
| Functions | |
| onAdd | Called when a new room gets added |
| onShow | Called when a room gets shown |
| onHide | Called when a room gets hidden |
| onSubjectChange | Called when a subject of a room gets changed |
| onClose | Called after a room has been left/closed |
| onPresenceChange | Called when presence of user changes (kick, ban) |
| Candy. | Roster-related events |
| Functions | |
| onUpdate | Called after a user have been added to the roster |
| onContextMenu | Called when a user clicks on the action menu arrow. |
| afterContextMenu | Called when after a the context menu is rendered |
| Candy. | Message-related events |
| Functions | |
| beforeShow | Called before a new message will be shown. |
| onShow | Called after a new message has been shown |
| beforeSend | Called before a message get sent |
| Candy. | Observes Candy core events |
| Candy. | Chat events |
| Functions | |
| update | The update method gets called whenever an event to which “Chat” is subscribed. |
| Candy. | Presence update events |
| Functions | |
| update | Every presence update gets dispatched from this method. |
| notifyPrivateChats | Notify private user chats if existing |
| Candy. | Presence error events |
| Functions | |
| update | Presence errors get handled in this method |
| Candy. | Message related events |
| Functions | |
| update | Messages received get dispatched from this method. |
| Candy. | Handles when display login window should appear |
| Functions | |
| update | The login event gets dispatched to this method |
| Candy. | Candy view pane handles everything regarding DOM updates etc. |
| Candy. | Window related view updates |
| Variables | |
| autoscroll | Boolean whether autoscroll is enabled |
| Functions | |
| hasFocus | Checks if window has focus |
| increaseUnreadMessages | Increases unread message count in window title by one. |
| reduceUnreadMessages | Reduce unread message count in window title by `num`. |
| clearUnreadMessages | Clear unread message count in window title. |
| renderUnreadMessages | Update window title to show message count. |
| onFocus | Window focus event handler. |
| onBlur | Window blur event handler. |
| Candy. | Chat-View related view updates |
| Variables | |
| rooms | Contains opened room elements |
| Functions | |
| addTab | Add a tab to the chat pane. |
| getTab | Get tab by JID. |
| removeTab | Remove tab element. |
| setActiveTab | Set the active tab. |
| increaseUnreadMessages | Increase unread message count in a tab by one. |
| clearUnreadMessages | Clear unread message count in a tab. |
| tabClick | Tab click event: show the room associated with the tab and stops the event from doing the default. |
| tabClose | Tab close (click) event: Leave the room (groupchat) or simply close the tab (chat). |
| allTabsClosed | All tabs closed event: Disconnect from service. |
| fitTabs | Fit tab size according to window size |
| updateToolbar | Show toolbar |
| adminMessage | Display admin message |
| infoMessage | Display info message. |
| onInfoMessage | Display info message. |
| Candy. | Chat toolbar for things like emoticons toolbar, room management etc. |
| Functions | |
| show | Show toolbar. |
| hide | Hide toolbar. |
| playSound | Play sound (default method). |
| onPlaySound | Sound play event handler. |
| onSoundControlClick | Sound control click event handler. |
| onAutoscrollControlClick | Autoscroll control event handler. |
| onStatusMessageControlClick | Status message control event handler. |
| updateUserCount | Update usercount element with count. |
| Candy. | Modal window |
| Functions | |
| show | Display modal window |
| hide | Hide modal window |
| showSpinner | Show loading spinner |
| hideSpinner | Hide loading spinner |
| showCloseControl | Show a close button |
| hideCloseControl | Hide the close button |
| showLoginForm | Show the login form modal |
| showEnterPasswordForm | Shows a form for entering room password |
| showNicknameConflictForm | Shows a form indicating that the nickname is already taken and for chosing a new nickname |
| showError | Show modal containing error message |
| Candy. | Class to display tooltips over specific elements |
| Functions | |
| show | Show a tooltip on event.currentTarget with content specified or content within the target’s attribute data-tooltip. |
| Candy. | Context menu for actions and settings |
| Functions | |
| init | Initialize context menu and setup mouseleave handler. |
| show | Show context menu (positions it according to the window height/width) |
| getMenuLinks | Extends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those. |
| initialMenuLinks | |
| showEmoticonsMenu | Shows the special emoticons menu |
| Candy. | Everything which belongs to room view things belongs here. |
| Functions | |
| init | Initialize a new room and inserts the room html into the DOM |
| show | Show a specific room and hides the other rooms (if there are any) |
| setSubject | Called when someone changes the subject in the channel |
| close | Close a room and remove everything in the DOM belonging to this room. |
| appendToMessagePane | Append a new message to the message pane. |
| sliceMessagePane | Slices the message pane after the max amount of messages specified in the Candy View options (limit setting). |
| scrollToBottom | Scroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function. |
| onScrollToBottom | Scrolls to the latest message received/sent. |
| onScrollToStoredPosition | 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 | Set focus to the message input field within the message form. |
| setUser | 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 | Get the current user in the room specified with the jid |
| ignoreUser | Ignore specified user and add the ignore icon to the roster item of the user |
| unignoreUser | Unignore an ignored user and remove the ignore icon of the roster item. |
| addIgnoreIcon | Add the ignore icon to the roster item of the specified user |
| removeIgnoreIcon | Remove the ignore icon to the roster item of the specified user |
| getPane | Get the chat room pane or a subPane of it (if subPane is specified) |
| Candy. | Private room handling |
| Functions | |
| open | Opens a new private room |
| setStatus | Set offline or online status for private rooms (when one of the participants leaves the room) |
| update | Called by Candy.View.Observer.Presence.update to update the roster if needed. |
| userClick | Click handler for opening a private room |
| joinAnimation | Animates specified elementId on join |
| leaveAnimation | Leave animation for specified element id and removes the DOM element on completion. |
| Candy. | Message submit/show handling |
| Functions | |
| submit | 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 | Show a message in the message pane |
| Files | |
| template.js | |
| Candy. | Contains mustache.js templates |
| Files | |
| translation.js | |
| Candy. | Contains translations |
self.init = function( service, options )
Init view & core
| (String) service | URL to the BOSH interface |
| (Object) options | Options for candy |
| (Boolean) debug | Debug (Default: false) |
| (Array|Boolean) autojoin | Autojoin these channels. When boolean true, do not autojoin, wait if the server sends something. |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
Candy Chat Core
| (Candy.Core) self | itself |
| (Strophe) Strophe | Strophe JS |
| (jQuery) $ | jQuery |
| Variables | |
| autojoin | If set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire). |
| Functions | |
| init | Initialize Core. |
| connect | Connect to the jabber host. |
| attach | Attach an already binded & connected session to the server |
| disconnect | Leave all rooms and disconnect |
| addHandler | Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection. |
| getUser | Gets current user |
| setUser | Set current user. |
| getConnection | Gets Strophe connection |
| getRooms | Gets all joined rooms |
| isAnonymousConnection | Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param. |
| getOptions | Gets options |
| getRoom | Gets a specific room |
| onWindowUnload | window.onbeforeunload event which disconnects the client from the Jabber server. |
| rawInput | (Overridden from Strophe.Connection.rawInput) |
| log | Overridden to do something useful if debug is set to true. |
| Files | |
| view.js |
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: `[‘room1@conference.host.tld’, ‘room2...]` (ejabberd, Openfire, ...)
self.connect = function( jidOrHost, password, nick )
Connect to the jabber host.
| 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. |
Candy.Core.attach() for attaching an already established session.
| (String) jidOrHost | JID or Host |
| (String) password | Password of the user |
| (String) nick | Nick 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. |
self.addHandler = function( handler, ns, name, type, id, from, options )
Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
| (Function) handler | The user callback. |
| (String) ns | The namespace to match. |
| (String) name | The stanza name to match. |
| (String) type | The stanza type attribute to match. |
| (String) id | The stanza id attribute to match. |
| (String) from | The stanza from attribute to match. |
| (String) options | The handler options |
A reference to the handler that can be used to remove it.
self.isAnonymousConnection = function()
Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
(Boolean)
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
The Candy View Class
| (Candy.View) self | itself |
| (jQuery) $ | jQuery |
| Functions | |
| init | Initialize chat view (setup DOM, register handlers & observers) |
| getCurrent | Get current container & roomJid in an object. |
| getOptions | Gets options |
| Files | |
| util.js |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
Candy utils
| (Candy.Util) self | itself |
| (jQuery) $ | jQuery |
| Functions | |
| jidToId | Translates a jid to a MD5-Id |
| escapeJid | Escapes a jid (node & resource get escaped) |
| unescapeJid | Unescapes a jid (node & resource get unescaped) |
| crop | Crop a string with the specified length |
| setCookie | Sets a new cookie |
| cookieExists | Tests if a cookie with the given name exists |
| getCookie | Returns the cookie value if there’s one with this name, otherwise returns undefined |
| deleteCookie | Deletes a cookie with the given name |
| getPosLeftAccordingToWindowBounds | Fetches the window width and element width and checks if specified position + element width is bigger than the window width. |
| getPosTopAccordingToWindowBounds | Fetches the window height and element height and checks if specified position + element height is bigger than the window height. |
| localizedTime | Localizes ISO-8610 Date with the time/dateformat specified in the translation. |
| iso8610toDate | Parses a ISO-8610 Date to a Date-Object. |
| isEmptyObject | IE7 doesn’t work with jQuery.isEmptyObject (<=1.5.1), workaround. |
| forceRedraw | Fix IE7 not redrawing under some circumstances. |
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.
| (jQuery.Element) elem | Element to position |
| (Integer) pos | Position left |
Object containing `px` (calculated position in pixel) and `alignment` (alignment of the element in relation to pos, either ‘left’ or ‘right’)
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.
| (jQuery.Element) elem | Element to position |
| (Integer) pos | Position top |
Object containing `px` (calculated position in pixel) and `alignment` (alignment of the element in relation to pos, either ‘top’ or ‘bottom’)
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
| (String) dateTime | ISO-8610 Datetime |
If current date is equal to the date supplied, format with timeFormat, otherwise with dateFormat
Parses a ISO-8610 Date to a Date-Object.
Uses a fallback if the client’s browser doesn’t support it.
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.
| (String) date | ISO-8610 Date |
Date-Object
Parser for emoticons, links and also supports escaping.
| Functions | |
| setEmoticonPath | Set emoticons location. |
| Variables | |
| emoticons | Array containing emoticons to be replaced by their images. |
| Functions | |
| emotify | Replaces text-emoticons with their image equivalent. |
| linkify | Replaces URLs with a HTML-link. |
| escape | Escapes a text using a jQuery function (like htmlspecialchars in PHP) |
| all | Does everything of the parser: escaping, linkifying and emotifying. |
A class can be extended with the observable to be able to notify observers
| Functions | |
| addObserver | Add an observer to the observer list |
| deleteObserver | Delete observer from list |
| clearObservers | Deletes all observers in list |
| notifyObservers | Notify all of its observers of a certain event. |
| Files | |
| action.js |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
Jabber actions
| Functions | |
| Version | Replies to a version request |
| Roster | Sends a request for a roster |
| Presence | Sends a request for presence |
| Services | Sends a request for disco items |
| Autojoin | When Candy.Core.getOptions().autojoin is true, request autojoin bookmarks (OpenFire) |
| ResetIgnoreList | Create new ignore privacy list (and reset the old one, if it exists). |
| RemoveIgnoreList | Remove an existing ignore list. |
| GetIgnoreList | Get existing ignore privacy list when connecting. |
| SetIgnoreListActive | Set ignore privacy list active |
| GetJidIfAnonymous | On anonymous login, initially we don’t know the jid and as a result, Candy.Core._user doesn’t have a jid. |
Room-specific commands
| Functions | |
| Join | Requests disco of specified room and joins afterwards. |
| Leave | Leaves a room. |
| Disco | Requests disco info of a room. |
| Message | Send message |
| IgnoreUnignore | Checks if the user is already ignoring the target user, if yes: unignore him, if no: ignore him. |
| UpdatePrivacyList | Updates privacy list according to the privacylist in the currentUser |
Disco: function( roomJid )
Requests disco info of a room.
| (String) roomJid | Room to get info for |
Room administration commands
| Functions | |
| UserAction | Kick or ban a user |
| SetSubject | Sets subject (topic) of a room. |
| Files | |
| chatRoom.js |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
Candy Chat Room
| (String) roomJid | Room jid |
| Variables | |
| room | Object containing roomJid and name. |
| user | Current local user of this room. |
| Roster | Candy.Core.ChatRoster instance |
| Functions | |
| setUser | Set user of this room. |
| getUser | Get current local user |
| getJid | Get room jid |
| setName | Set room name |
| getName | Get room name |
| setRoster | Set roster of room |
| getRoster | Get roster |
| Files | |
| chatRoster.js |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
Chat User
| Constants | |
| ROLE_MODERATOR | Moderator role |
| AFFILIATION_OWNER | Affiliation owner |
| Variables | |
| data | |
| Functions | |
| getJid | Gets an unescaped user jid |
| getEscapedJid | Escapes the user’s jid (node & resource get escaped) |
| getNick | Gets user nick |
| getRole | Gets user role |
| getAffiliation | Gets user affiliation |
| isModerator | Check if user is moderator. |
| addToOrRemoveFromPrivacyList | Convenience function for adding/removing users from ignore list. |
| getPrivacyList | Returns the privacy list of the listname of the param. |
| isInPrivacyList | Tests if this user ignores the user provided by jid. |
| setCustomData | Stores custom data |
| getCustomData | Retrieve custom data |
| Files | |
| event.js |
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.
| (String) list | To which privacy list the user should be added / removed from. Candy supports curently only the “ignore” list. |
| (String) jid | User jid to add/remove |
| (Array) | Current privacy list. |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
Chat Events
| (Candy.Core.Event) self | itself |
| (Strophe) Strophe | Strophe |
| (jQuery) $ | jQuery |
| (Candy.Util.Observable) observable | Observable to mixin |
| Enumerations | |
| KEYS | Observer keys |
Jabber related events
| Functions | |
| Version | Responds to a version request |
| Presence | Acts on a presence event |
| Bookmarks | Acts on a bookmarks event. |
| PrivacyList | Acts on a privacy list event and sets up the current privacy list of this user. |
| PrivacyListError | Acts when a privacy list error has been received. |
| Message | Acts on room, admin and server messages and notifies the view if required. |
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.
| (String) msg | Raw XML Message |
| (Boolean) | false to disable the handler after first call. |
Room specific events
| Functions | |
| Leave | Leaves a room and cleans up related data and notifies view. |
| Disco | Sets informations to rooms according to the disco info received. |
| Presence | Acts on various presence messages (room leaving, room joining, error presence) and notifies view. |
| PresenceError | Acts when a presence of type error has been retrieved. |
| Message | Acts on various message events (subject changed, private chat message, multi-user chat message) and notifies view. |
| Files | |
| event.js |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
Chat-related events
| Functions | |
| onAdminMessage | Called when receiving admin messages |
| onDisconnect | Called when client disconnects |
| onAuthfail | Called when authentication fails |
Room-related events
| Functions | |
| onAdd | Called when a new room gets added |
| onShow | Called when a room gets shown |
| onHide | Called when a room gets hidden |
| onSubjectChange | Called when a subject of a room gets changed |
| onClose | Called after a room has been left/closed |
| onPresenceChange | Called when presence of user changes (kick, ban) |
Roster-related events
| Functions | |
| onUpdate | Called after a user have been added to the roster |
| onContextMenu | Called when a user clicks on the action menu arrow. |
| afterContextMenu | Called when after a the context menu is rendered |
Message-related events
| Functions | |
| beforeShow | Called before a new message will be shown. |
| onShow | Called after a new message has been shown |
| beforeSend | Called before a message get sent |
Presence update events
| Functions | |
| update | Every presence update gets dispatched from this method. |
| notifyPrivateChats | Notify private user chats if existing |
Window related view updates
| Variables | |
| autoscroll | Boolean whether autoscroll is enabled |
| Functions | |
| hasFocus | Checks if window has focus |
| increaseUnreadMessages | Increases unread message count in window title by one. |
| reduceUnreadMessages | Reduce unread message count in window title by `num`. |
| clearUnreadMessages | Clear unread message count in window title. |
| renderUnreadMessages | Update window title to show message count. |
| onFocus | Window focus event handler. |
| onBlur | Window blur event handler. |
Chat-View related view updates
| Variables | |
| rooms | Contains opened room elements |
| Functions | |
| addTab | Add a tab to the chat pane. |
| getTab | Get tab by JID. |
| removeTab | Remove tab element. |
| setActiveTab | Set the active tab. |
| increaseUnreadMessages | Increase unread message count in a tab by one. |
| clearUnreadMessages | Clear unread message count in a tab. |
| tabClick | Tab click event: show the room associated with the tab and stops the event from doing the default. |
| tabClose | Tab close (click) event: Leave the room (groupchat) or simply close the tab (chat). |
| allTabsClosed | All tabs closed event: Disconnect from service. |
| fitTabs | Fit tab size according to window size |
| updateToolbar | Show toolbar |
| adminMessage | Display admin message |
| infoMessage | Display info message. |
| onInfoMessage | Display info message. |
infoMessage: function( roomJid, subject, message )
Display info message. This is a wrapper for onInfoMessage to be able to disable certain info messages.
| (String) roomJid | Room JID |
| (String) subject | Subject |
| (String) message | Message |
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).
| (String) roomJid | Room JID |
| (String) subject | Subject |
| (String) message | Message |
Chat toolbar for things like emoticons toolbar, room management etc.
| Functions | |
| show | Show toolbar. |
| hide | Hide toolbar. |
| playSound | Play sound (default method). |
| onPlaySound | Sound play event handler. |
| onSoundControlClick | Sound control click event handler. |
| onAutoscrollControlClick | Autoscroll control event handler. |
| onStatusMessageControlClick | Status message control event handler. |
| updateUserCount | Update usercount element with count. |
Modal window
| Functions | |
| show | Display modal window |
| hide | Hide modal window |
| showSpinner | Show loading spinner |
| hideSpinner | Hide loading spinner |
| showCloseControl | Show a close button |
| hideCloseControl | Hide the close button |
| showLoginForm | Show the login form modal |
| showEnterPasswordForm | Shows a form for entering room password |
| showNicknameConflictForm | Shows a form indicating that the nickname is already taken and for chosing a new nickname |
| showError | Show modal containing error message |
show: function( html, showCloseControl, showSpinner )
Display modal window
| (String) html | HTML code to put into the modal window |
| (Boolean) showCloseControl | set to true if a close button should be displayed [default false] |
| (Boolean) showSpinner | set to true if a loading spinner should be shown [default false] |
Context menu for actions and settings
| Functions | |
| init | Initialize context menu and setup mouseleave handler. |
| show | Show context menu (positions it according to the window height/width) |
| getMenuLinks | Extends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those. |
| initialMenuLinks | |
| showEmoticonsMenu | Shows the special emoticons menu |
show: function( elem, roomJid, user )
Show context menu (positions it according to the window height/width)
getMenuLinks for getting menulinks the user has access to Candy.Util.getPosLeftAccordingToWindowBounds for positioning Candy.Util.getPosTopAccordingToWindowBounds for positioning
Candy.View.Event.Roster.afterContextMenu after showing the context menu
| (Element) elem | On which element it should be shown |
| (String) roomJid | Room Jid of the room it should be shown |
| (Candy.Core.chatUser) user | User |
getMenuLinks: function( roomJid, user, elem )
Extends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those.
| (Object) | object containing the extended menulinks. |
Everything which belongs to room view things belongs here.
| Functions | |
| init | Initialize a new room and inserts the room html into the DOM |
| show | Show a specific room and hides the other rooms (if there are any) |
| setSubject | Called when someone changes the subject in the channel |
| close | Close a room and remove everything in the DOM belonging to this room. |
| appendToMessagePane | Append a new message to the message pane. |
| sliceMessagePane | Slices the message pane after the max amount of messages specified in the Candy View options (limit setting). |
| scrollToBottom | Scroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function. |
| onScrollToBottom | Scrolls to the latest message received/sent. |
| onScrollToStoredPosition | 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 | Set focus to the message input field within the message form. |
| setUser | 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 | Get the current user in the room specified with the jid |
| ignoreUser | Ignore specified user and add the ignore icon to the roster item of the user |
| unignoreUser | Unignore an ignored user and remove the ignore icon of the roster item. |
| addIgnoreIcon | Add the ignore icon to the roster item of the specified user |
| removeIgnoreIcon | Remove the ignore icon to the roster item of the specified user |
| getPane | Get the chat room pane or a subPane of it (if subPane is specified) |
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.
| (String) roomJid | Room JID |
scrollToBottom: function( roomJid )
Scroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function.
| (String) roomJid | Room JID |
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).
| (String) roomJid | Room in which the user is set to. |
| (Candy.Core.ChatUser) user | The user |
Private room handling
| Functions | |
| open | Opens a new private room |
| setStatus | Set offline or online status for private rooms (when one of the participants leaves the room) |
| update | Called by Candy.View.Observer.Presence.update to update the roster if needed. |
| userClick | Click handler for opening a private room |
| joinAnimation | Animates specified elementId on join |
| leaveAnimation | Leave animation for specified element id and removes the DOM element on completion. |
open: function( roomJid, roomName, switchToRoom, isNoConferenceRoomJid )
Opens a new private room
| (String) roomJid | Room jid to open |
| (String) roomName | Room name |
| (Boolean) switchToRoom | If true, displayed room switches automatically to this room (e.g. when user clicks itself on another user to open a private chat) |
| (Boolean) isNoConferenceRoomJid | true 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. |
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.
| (String) roomJid | Room JID in which the update happens |
| (Candy.Core.ChatUser) user | User on which the update happens |
| (String) action | one of “join”, “leave”, “kick” and “ban” |
| (Candy.Core.ChatUser) currentUser | Current user |
Message submit/show handling
| Functions | |
| submit | 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 | Show a message in the message pane |
| Files | |
| template.js |
show: function( roomJid, name, message, timestamp )
Show a message in the message pane
| (String) roomJid | room in which the message has been sent to |
| (String) name | Name of the user which sent the message |
| (String) message | Message |
| (String) timestamp | [optional] Timestamp of the message, if not present, current date. |
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
| Candy | Chats are not dead yet. |
© 2011 Amiado Group AG. All rights reserved.
About candy
self.about
Init view & core
self.init = function( service, options )
If set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).
autojoin: true
Initialize Core.
self.init = function( service, options )
Connect to the jabber host.
self.connect = function( jidOrHost, password, nick )
Attach an already binded & connected session to the server
self.attach = function( jid, sid, rid )
Leave all rooms and disconnect
self.disconnect = function()
Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
self.addHandler = function( handler, ns, name, type, id, from, options )
Gets current user
self.getUser = function()
Set current user.
self.setUser = function( user )
Gets Strophe connection
self.getConnection = function()
Gets all joined rooms
self.getRooms = function()
Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
self.isAnonymousConnection = function()
Gets options
self.getOptions = function()
Gets a specific room
self.getRoom = function( roomJid )
window.onbeforeunload event which disconnects the client from the Jabber server.
self.onWindowUnload = function()
(Overridden from Strophe.Connection.rawInput)
self.rawInput = function( data )
Overridden to do something useful if debug is set to true.
self.log = function()
Initialize chat view (setup DOM, register handlers & observers)
self.init = function( container, options )
Get current container & roomJid in an object.
self.getCurrent = function()
Gets options
self.getOptions = function()
Translates a jid to a MD5-Id
self.jidToId = function( jid )
Escapes a jid (node & resource get escaped)
self.escapeJid = function( jid )
Unescapes a jid (node & resource get unescaped)
self.unescapeJid = function( jid )
Crop a string with the specified length
self.crop = function( str, len )
Sets a new cookie
self.setCookie = function( name, value, lifetime_days )
Tests if a cookie with the given name exists
self.cookieExists = function( name )
Returns the cookie value if there’s one with this name, otherwise returns undefined
self.getCookie = function( name )
Deletes a cookie with the given name
self.deleteCookie = function( name )
Fetches the window width and element width and checks if specified position + element width is bigger than the window width.
self.getPosLeftAccordingToWindowBounds = function( elem, pos )
Fetches the window height and element height and checks if specified position + element height is bigger than the window height.
self.getPosTopAccordingToWindowBounds = function( elem, pos )
Localizes ISO-8610 Date with the time/dateformat specified in the translation.
self.localizedTime = function( dateTime )
IE7 doesn’t work with jQuery.isEmptyObject (<=1.5.1), workaround.
self.isEmptyObject = function( obj )
Fix IE7 not redrawing under some circumstances.
self.forceRedraw = function( elem )
Set emoticons location.
setEmoticonPath: function( path )
Replaces text-emoticons with their image equivalent.
emotify: function( text )
Replaces URLs with a HTML-link.
linkify: function( text )
Escapes a text using a jQuery function (like htmlspecialchars in PHP)
escape: function( text )
Does everything of the parser: escaping, linkifying and emotifying.
all: function( text )
Add an observer to the observer list
self.addObserver = function( key, obj )
Delete observer from list
self.deleteObserver = function( key, obj )
Deletes all observers in list
self.clearObservers = function( key )
Notify all of its observers of a certain event.
self.notifyObservers = function( key, arg )
Replies to a version request
Version: function( msg )
Sends a request for a roster
Roster: function()
Sends a request for presence
Presence: function( attr )
Sends a request for disco items
Services: function()
When Candy.Core.getOptions().autojoin is true, request autojoin bookmarks (OpenFire)
Autojoin: function()
Create new ignore privacy list (and reset the old one, if it exists).
ResetIgnoreList: function()
Remove an existing ignore list.
RemoveIgnoreList: function()
Get existing ignore privacy list when connecting.
GetIgnoreList: function()
Set ignore privacy list active
SetIgnoreListActive: function()
On anonymous login, initially we don’t know the jid and as a result, Candy.Core._user doesn’t have a jid.
GetJidIfAnonymous: function()
Requests disco of specified room and joins afterwards.
Join: function( roomJid, password )
Leaves a room.
Leave: function( roomJid )
Requests disco info of a room.
Disco: function( roomJid )
Send message
Message: function( roomJid, msg, type )
Checks if the user is already ignoring the target user, if yes: unignore him, if no: ignore him.
IgnoreUnignore: function( userJid )
Updates privacy list according to the privacylist in the currentUser
UpdatePrivacyList: function()
Kick or ban a user
UserAction: function( roomJid, userJid, type, reason )
Sets subject (topic) of a room.
SetSubject: function( roomJid, subject )
Object containing roomJid and name.
this.room
Current local user of this room.
this.user
Set user of this room.
this.setUser = function( user )
Get current local user
this.getUser = function()
Get room jid
this.getJid = function()
Set room name
this.setName = function( name )
Get room name
this.getName = function()
Set roster of room
this.setRoster = function( roster )
Get roster
this.getRoster = function()
Roster items
this.items
Add user to roster
this.add = function( user )
Remove user from roster
this.remove = function( jid )
Get user from roster
this.get = function( jid )
Get all items
this.getAll = function()
this.data
Gets an unescaped user jid
this.getJid = function()
Escapes the user’s jid (node & resource get escaped)
this.getEscapedJid = function()
Gets user nick
this.getNick = function()
Gets user role
this.getRole = function()
Gets user affiliation
this.getAffiliation = function()
Check if user is moderator.
this.isModerator = function()
Convenience function for adding/removing users from ignore list.
this.addToOrRemoveFromPrivacyList = function( list, jid )
Returns the privacy list of the listname of the param.
this.getPrivacyList = function( list )
Tests if this user ignores the user provided by jid.
this.isInPrivacyList = function( list, jid )
Stores custom data
this.setCustomData = function( data )
Retrieve custom data
this.getCustomData = function()
Acts on strophe status events and notifies view.
Connect: function( status )
Notify view that the login window should be displayed
self.Login = function( presetJid )
Responds to a version request
Version: function( msg )
Acts on a presence event
Presence: function( msg )
Acts on a bookmarks event.
Bookmarks: function( msg )
Acts on a privacy list event and sets up the current privacy list of this user.
PrivacyList: function( msg )
Acts when a privacy list error has been received.
PrivacyListError: function( msg )
Acts on room, admin and server messages and notifies the view if required.
Message: function( msg )
Leaves a room and cleans up related data and notifies view.
Leave: function( msg )
Sets informations to rooms according to the disco info received.
Disco: function( msg )
Acts on various presence messages (room leaving, room joining, error presence) and notifies view.
Presence: function( msg )
Acts when a presence of type error has been retrieved.
PresenceError: function( msg )
Acts on various message events (subject changed, private chat message, multi-user chat message) and notifies view.
Message: function( msg )
Called when receiving admin messages
onAdminMessage: function( args )
Called when client disconnects
onDisconnect: function()
Called when authentication fails
onAuthfail: function()
Called when a new room gets added
onAdd: function( args )
Called when a room gets shown
onShow: function( args )
Called when a room gets hidden
onHide: function( args )
Called when a subject of a room gets changed
onSubjectChange: function( args )
Called after a room has been left/closed
onClose: function( args )
Called when presence of user changes (kick, ban)
onPresenceChange: function( args )
Called after a user have been added to the roster
onUpdate: function( args )
Called when a user clicks on the action menu arrow.
onContextMenu: function( args )
Called when after a the context menu is rendered
afterContextMenu: function( args )
Called before a new message will be shown.
beforeShow: function( args )
Called after a new message has been shown
onShow: function( args )
Called before a message get sent
beforeSend: function( message )
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.
update: function( obj, args )
Notify private user chats if existing
notifyPrivateChats: function( user, type )
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
update: function( obj, args )
Boolean whether autoscroll is enabled
autoscroll: true
Checks if window has focus
hasFocus: function()
Increases unread message count in window title by one.
increaseUnreadMessages: function()
Reduce unread message count in window title by `num`.
reduceUnreadMessages: function( num )
Clear unread message count in window title.
clearUnreadMessages: function()
Update window title to show message count.
renderUnreadMessages: function( count )
Window focus event handler.
onFocus: function()
Window blur event handler.
onBlur: function()
Contains opened room elements
rooms: []
Add a tab to the chat pane.
addTab: function( roomJid, roomName, roomType )
Get tab by JID.
getTab: function( roomJid )
Remove tab element.
removeTab: function( roomJid )
Set the active tab.
setActiveTab: function( roomJid )
Increase unread message count in a tab by one.
increaseUnreadMessages: function( roomJid )
Clear unread message count in a tab.
clearUnreadMessages: function( roomJid )
Tab click event: show the room associated with the tab and stops the event from doing the default.
tabClick: function( e )
Tab close (click) event: Leave the room (groupchat) or simply close the tab (chat).
tabClose: function( e )
All tabs closed event: Disconnect from service.
allTabsClosed: function()
Fit tab size according to window size
fitTabs: function()
Show toolbar
updateToolbar: function( roomJid )
Display admin message
adminMessage: function( subject, message )
Display info message.
infoMessage: function( roomJid, subject, message )
Display info message.
onInfoMessage: function( roomJid, subject, message )
Show toolbar.
show: function()
Hide toolbar.
hide: function()
Play sound (default method).
playSound: function()
Sound play event handler.
onPlaySound: function()
Sound control click event handler.
onSoundControlClick: function()
Autoscroll control event handler.
onAutoscrollControlClick: function()
Status message control event handler.
onStatusMessageControlClick: function()
Display modal window
show: function( html, showCloseControl, showSpinner )
Hide modal window
hide: function( callback )
Show loading spinner
showSpinner: function()
Hide loading spinner
hideSpinner: function()
Show a close button
showCloseControl: function()
Hide the close button
hideCloseControl: function()
Show the login form modal
showLoginForm: function( message, presetJid )
Shows a form for entering room password
showEnterPasswordForm: function( roomJid, roomName, message )
Shows a form indicating that the nickname is already taken and for chosing a new nickname
showNicknameConflictForm: function( roomJid )
Show modal containing error message
showError: function( message, replacements )
Show a tooltip on event.currentTarget with content specified or content within the target’s attribute data-tooltip.
show: function( event, content )
Initialize context menu and setup mouseleave handler.
init: function()
Show context menu (positions it according to the window height/width)
show: function( elem, roomJid, user )
Extends initialMenuLinks with Candy.View.Event.Roster.onContextMenu links and returns those.
getMenuLinks: function( roomJid, user, elem )
initialMenuLinks: function()
Shows the special emoticons menu
showEmoticonsMenu: function( elem )
Initialize a new room and inserts the room html into the DOM
init: function( roomJid, roomName, roomType )
Show a specific room and hides the other rooms (if there are any)
show: function( roomJid )
Called when someone changes the subject in the channel
setSubject: function( roomJid, subject )
Close a room and remove everything in the DOM belonging to this room.
close: function( roomJid )
Append a new message to the message pane.
appendToMessagePane: function( roomJid, html )
Slices the message pane after the max amount of messages specified in the Candy View options (limit setting).
sliceMessagePane: function( roomJid )
Scroll to bottom wrapper for onScrollToBottom to be able to disable it by overwriting the function.
scrollToBottom: function( roomJid )
Scrolls to the latest message received/sent.
onScrollToBottom: 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.
onScrollToStoredPosition: function( roomJid )
Set focus to the message input field within the message form.
setFocusToForm: function( roomJid )
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).
setUser: function( roomJid, user )
Get the current user in the room specified with the jid
getUser: function( roomJid )
Ignore specified user and add the ignore icon to the roster item of the user
ignoreUser: function( roomJid, userJid )
Unignore an ignored user and remove the ignore icon of the roster item.
unignoreUser: function( roomJid, userJid )
Add the ignore icon to the roster item of the specified user
addIgnoreIcon: function( roomJid, userJid )
Remove the ignore icon to the roster item of the specified user
removeIgnoreIcon: function( roomJid, userJid )
Get the chat room pane or a subPane of it (if subPane is specified)
getPane: function( roomJid, subPane )
Opens a new private room
open: function( roomJid, roomName, switchToRoom, isNoConferenceRoomJid )
Set offline or online status for private rooms (when one of the participants leaves the room)
setStatus: function( roomJid, status )
Called by Candy.View.Observer.Presence.update to update the roster if needed.
update: function( roomJid, user, action, currentUser )
Click handler for opening a private room
userClick: function()
Animates specified elementId on join
joinAnimation: function( elementId )
Leave animation for specified element id and removes the DOM element on completion.
leaveAnimation: function( elementId )
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.
submit: function( event )
Show a message in the message pane
show: function( roomJid, name, message, timestamp )