util.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Summary
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.

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.

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
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.
Close