DLSupport

JavaScript framework containing common functionalities.

This is used when we cannot use Prototype.

Summary
DLSupportJavaScript framework containing common functionalities.
Data
BrowserContains browser information.
ErrorLog(array) Contains a log of all the errors during the script execution.
IdCounter(int) Counter used for generating unqiue IDs.
ModuleUrl(string) The URL to the directory containing this module.
Methods
addClassNameAdd the given class name ot the given DOM element.
addErrorLogAdd a message to the error log.
checboxSelectAllToggleCheck or uncheck all input checkboxes with the same class name as the given target based on the current status of the given element.
childElementsRetrieves an array of all direct child DOM elements of the given element.
cloneArrayCreate a copy of the given array.
combineArrayCreate an associative array (object) by using the first given array as the keys and the second given array as the value.
curryCurrify the given function.
defaultValuesUsing the given base values object, copy values from the source object if they have the same property name.
delayFunctionDelay the execution of the given function by the given number of seconds.
getCookieGet a value from the cookie.
getElementIf given is a string, this will try to get the object with the same ID as the string.
hasClassNameDetermine whether or not the given DOM element has the given class name.
hideLoadingImageHide the loading image.
humanReadableRetrieves the given data into human readable format.
identifyRetrieve the ID of the given object, creating one if it does not exist.
inArrayFind out whether or not the given item is in the given array.
isArrayDetermine whether or not the given item is an array.
isNumericDetermine whether or not the given item is numeric.
newEventAttach a new event to the given element.
PropertyNamesGet the property names of the given object.
removeClassNameRemove the given class name from the given DOM element.
removeCookieWrapper method around the method setCookie.
removeElementThis will remove the given element from the DOM structure of the web site.
reverseArrayGet the array that has the reverse order of the given array.
setCookieStore the given value to cookie under the given key for the given number of days.
showLoadingImageFade out the entire page and show the loading image.
toggleDisplayToggle the display of the given DOM element.
toQueryStringConvert the given object to a query string.
uniqueArrayGet the array that has only the unique values of the given array.
windowOnloadThis will add a new event to the event listener that will run the given function after the window has finish loading (basically when all of the DOM structure has finish loading).

Data

Browser

Contains browser information.

The stucture of this object will look something similar to the following:

Object(
    Gecko: {
        (boolean) Whether or not the current browser is Gecko based
        like Firefox.
    },
    IE: {
        (boolean) Whether or not the current browser is Internet
        Explorer.
    },
    MobileSafari: {
        (boolean) Whether or not the current browser is Mobile
        Safari like the iPhone.
    },
    Opera: {
        (boolean) Whether or not the current browser is Opera.
    },
    WebKit: {
        (boolean) Whether or not the current browser is WebKit based
        like Safari and Google Chrome.
    }
)

ErrorLog

(array) Contains a log of all the errors during the script execution.

IdCounter

(int) Counter used for generating unqiue IDs.

ModuleUrl

(string) The URL to the directory containing this module.  This will be set dynamically after the script loads.

Methods

addClassName

addClassName: function(obj,
class_name)

Add the given class name ot the given DOM element.

Parameters

obj(object) The DOM element that the class name will be added to if it does not already have it.
class_name(string) The class name to be added.

addErrorLog

addErrorLog: function(method,
parameters,
message)

Add a message to the error log.

Parameters

method(string) The name of the method that generated the error.
parameters(array) The parameters that was given to the method that generated the error.
message(string) The error message.

checboxSelectAllToggle

Check or uncheck all input checkboxes with the same class name as the given target based on the current status of the given element.

Parameters

element(object) The DOM element in which if it is checked, all input boxes with the given class name, will be checked and vice versa.
target(string) The class name of all input checkboxes that will be checked or unchecked.

childElements

childElements: function(parent)

Retrieves an array of all direct child DOM elements of the given element.

Parameters

parent(object) The DOM element that will serve as the parent.

Returns

(array) An array of DOM elements that is the child of the given DOM element.

cloneArray

cloneArray: function(data)

Create a copy of the given array.

Parameters

data(array) The array to be cloned.

Returns

(array) A clone of the given array.

combineArray

combineArray: function(keys,
values)

Create an associative array (object) by using the first given array as the keys and the second given array as the value.

It is required that both arrays be of the same length.

Parameters

keys(array) The array to be used as the keys.
values(array) The array to be used as the values.

Returns

(object) An object with the given keys as the property names and the given values as its corresponding value.

curry

curry: function(func,
scope)

Currify the given function.

Don’t know what currify means?  Google it.

Parameters

func(function) The function to currify.
scope(object) The scope of the function, namely, the object that will serve as the “this”.

Returns

(function) A function that wraps the given function with some of its parameters preset.

defaultValues

defaultValues: function(source,
base)

Using the given base values object, copy values from the source object if they have the same property name.

Parameters

source(object) The object being used to copy values over from.
base(object) The object that contains the default values.

Returns

(object) The object containing values from both the source and base object with the source object’s value replacing the base object’s value if they have the same property name.

delayFunction

delayFunction: function(func,
delay)

Delay the execution of the given function by the given number of seconds.

Parameters

func(function) The function whose execution will be delayed.
delay(int) The number of seconds to wait before the given function is executed.

getCookie

getCookie: function(key)

Get a value from the cookie.

Parameters

key(string) The key under which the cookie was stored.

Returns

(mixed) Returns the value of the cookie of the given key or null if it does not exist.

getElement

getElement: function(data)

If given is a string, this will try to get the object with the same ID as the string.  Otherwise, this just returns back the given data if it is anything else.

Parameters

data(mixed) A string representing the ID of a DOM element or anything else.

Returns

(mixed) The DOM element with the given ID or whatever was given.

hasClassName

hasClassName: function(obj,
class_name)

Determine whether or not the given DOM element has the given class name.

Parameters

obj(object) The DOM element that will be tested.
class_name(string) The class name to look for.

Returns

(boolean) Whether or not the given class name exist in the given DOM element.

hideLoadingImage

hideLoadingImage: function()

Hide the loading image.

humanReadable

humanReadable: function(data)

Retrieves the given data into human readable format.  Credits goes to Michael White & Ben Bryan.

Parameters

data(mixed) The data to be parsed and returned.

Returns

(string) The string representation of the given data.

identify

identify: function(obj)

Retrieve the ID of the given object, creating one if it does not exist.

Parameters

obj(object) The object to retrieve the ID from.

Returns

(string) The ID of the given object.  This will return an empty string if the object does not exist.

inArray

inArray: function(item,
haystack)

Find out whether or not the given item is in the given array.

Parameters

item(mixed) The item to look for.
haystack(array) The array to used for the search.
strict(boolean) This is optional and defaults to true.  If this is true, then the search will use === when comparing the data, otherwise, it will just use ==.

Returns

(boolean) Returns true if the given item is in the given array, false otherwise.

isArray

isArray: function(item)

Determine whether or not the given item is an array.

Parameters

item(mixed) The item to check.

Returns

(boolean) Returns true if the given item is an array, false otherwise.

isNumeric

isNumeric: function(item)

Determine whether or not the given item is numeric.

Parameters

item(mixed) The item to check.

Returns

(boolean) Returns true if the given item is a number, false otherwise.

newEvent

newEvent: function(element,
event,
func,
delay)

Attach a new event to the given element.

Parameters

element(object) The element in which the event should be attached to.
event(string) The event by which the given function should be executed.  This should not include the text “on”.
func(function) The function to append to the list.
delay(int) The time, in seconds, to delay the execution after the page has loaded.  This is optional & defaults to 0.

Returns

(boolean) Returns true if successful, otherwise, false.

PropertyNames

Get the property names of the given object.

Parameters

item(object) The item to retrieve the property names.

Returns

(array) An array containing all the properties belonging to the given object.  Note that this will only contain properties that the given object actually own.

removeClassName

removeClassName: function(obj,
class_name)

Remove the given class name from the given DOM element.

Parameters

obj(object) The DOM element that will have the given class name removed.
class_name(string) The class name to remove.

removeCookie

removeCookie: function(key)

Wrapper method around the method setCookie.  This method will set the expire time to the current time.

Parameters

key(string) The key under which the cookie was stored.

removeElement

removeElement: function(element)

This will remove the given element from the DOM structure of the web site.

Be careful when using this method because it is a mutation of the DOM structure.  Removing the given element will also remove all of its children.

Parameters

element(object) The DOM element to remove.

Returns

(boolean) Returns true if successful, false, otherwise.

reverseArray

reverseArray: function(data)

Get the array that has the reverse order of the given array.

This differs from the pre-defined reverse array function in that this can be set to be done recursively.

Parameters

data(array) The array to have it values reversed.
recursive(boolean) Optional & defaults to false.  If true, recur into an inner arrays.

Returns

(array) The given array but its order in reverse.

setCookie

setCookie: function(key,
value,
days)

Store the given value to cookie under the given key for the given number of days.

Parameters

key(string) The key under which the cookie’s value is stored.
value(string) The value to be stored in the cookie.
days(int) The number of days until the cookie expires from the current date.

showLoadingImage

showLoadingImage: function(color)

Fade out the entire page and show the loading image.

Parameters

color(string) The color of the loading image.  The possible values are: “black”, “blue”, “brown”, “gold”, “gray”, “green”, “navy”, “orange”, “purple”, “red”, “white”, and “yellow”.

toggleDisplay

toggleDisplay: function(element)

Toggle the display of the given DOM element.  If it is currently is hidden, then show it.  If it is currently visibile, then hdie it.

Parameters

element(object) The DOM element whose display will be toggled.

toQueryString

toQueryString: function(data)

Convert the given object to a query string.

Parameters

data(object) The object to be converted.

Returns

(string) The given data as a query string.

uniqueArray

uniqueArray: function(data)

Get the array that has only the unique values of the given array.

Parameters

data(array) The array to use to create a unique array.
strict(boolean) This is optional and defaults to true.  If this is true, then the search will use === when comparing the data, otherwise, it will just use ==.

Returns

(array) Returns the given array with repeated items removed.

windowOnload

windowOnload: function(func)

This will add a new event to the event listener that will run the given function after the window has finish loading (basically when all of the DOM structure has finish loading).

Since this is adding to the list, you do not have to worry about overwriting someone else’s events or theirs overwriting yours.  The second parameter can futher delay the execution so you can pretty much sort the order of the execution of the function.  It also allows you to wait for other javascript functions to finish running before yours can go.  At worse case, it uses window.setTimeout.

Parameters

func(function) The function to append to the list.
delay(int) The time, in seconds, to delay the execution after the page has loaded.  This is optional & defaults to 0.

Returns

(boolean) Returns true if it was successful in adding the onload to the list.  Returns false if it has to default to using window.setTimeout.

addClassName: function(obj,
class_name)
Add the given class name ot the given DOM element.
addErrorLog: function(method,
parameters,
message)
Add a message to the error log.
childElements: function(parent)
Retrieves an array of all direct child DOM elements of the given element.
cloneArray: function(data)
Create a copy of the given array.
combineArray: function(keys,
values)
Create an associative array (object) by using the first given array as the keys and the second given array as the value.
curry: function(func,
scope)
Currify the given function.
defaultValues: function(source,
base)
Using the given base values object, copy values from the source object if they have the same property name.
delayFunction: function(func,
delay)
Delay the execution of the given function by the given number of seconds.
getCookie: function(key)
Get a value from the cookie.
getElement: function(data)
If given is a string, this will try to get the object with the same ID as the string.
hasClassName: function(obj,
class_name)
Determine whether or not the given DOM element has the given class name.
hideLoadingImage: function()
Hide the loading image.
humanReadable: function(data)
Retrieves the given data into human readable format.
identify: function(obj)
Retrieve the ID of the given object, creating one if it does not exist.
inArray: function(item,
haystack)
Find out whether or not the given item is in the given array.
isArray: function(item)
Determine whether or not the given item is an array.
isNumeric: function(item)
Determine whether or not the given item is numeric.
newEvent: function(element,
event,
func,
delay)
Attach a new event to the given element.
removeClassName: function(obj,
class_name)
Remove the given class name from the given DOM element.
removeCookie: function(key)
Wrapper method around the method setCookie.
setCookie: function(key,
value,
days)
Store the given value to cookie under the given key for the given number of days.
removeElement: function(element)
This will remove the given element from the DOM structure of the web site.
reverseArray: function(data)
Get the array that has the reverse order of the given array.
showLoadingImage: function(color)
Fade out the entire page and show the loading image.
toggleDisplay: function(element)
Toggle the display of the given DOM element.
toQueryString: function(data)
Convert the given object to a query string.
uniqueArray: function(data)
Get the array that has only the unique values of the given array.
windowOnload: function(func)
This will add a new event to the event listener that will run the given function after the window has finish loading (basically when all of the DOM structure has finish loading).