API Docs for: 0.0.8-0
Show:

Util Class

A set of functions used by at least one module in this project. The functions are generic enough that they may become useful for other modules later or functions that are shared amongst multiple modules should be added here.

NOTE: None of these functions require the global configuration object. (i.e. they are not exclusive to RAMP). For functions that depend on the global configuration object, place them in ramp.js.

Item Index

Methods

Methods

adjustWidthForSrollbar

(
  • body
  • targets
)
static

Checks if the height of the scrollable content of the body is taller than its height; if so, offset the content horizontally to accomodate for the scrollbar.

Parameters:

  • body JObject

    A DOM node with a scrollbar (or not)

  • targets JObject

    An array of jObjects to add the offset to

afterAll

(
  • deferredList
  • callback
)
static

Executes the callback function only after all the deferred Objects in the given deferredList has resolved.

Parameters:

  • deferredList Array

    A list of Deferred objects

  • callback Function

    The callback to be executed

arrayToQuery

(
  • array
)
String static

Converts an array into a '+' separated String that can be used as the query parameter of a URL.

 arrayToQuery(["abc", 123, "efg"]) -> "abc+123+efg"

NOTE: the array should only contain primitives, objects will not be serialized properly.

Parameters:

  • array Array

    An array of primitives to be serialized

Returns:

String:

A serialized representation of the given array

checkConsole

() static

Checks if the console exists, if not, redefine the console and all console methods to a function that does nothing. Useful for IE which does not have the console until the debugger is opened.

compareGraphics

(
  • one
  • two
)
Boolean static

Compares two graphic objects.

Parameters:

Returns:

Boolean:

True if the objects represent the same feature

createLazyVariable

(
  • initFunc
)
Object static

Creates an object that acts like a lazy variable (i.e. a variable whose value is only resolved the first time it is retrieved, not when it is assigned). The value given to the lazy variable should be the return value of the given initFunc. The returned object has two methods:

  • get - returns the value of the variable, if it is the first time get is called, the the initFunc will be called to resolve the value of the variable.
  • reset - forces the variable to call the initFunc again the next time get is called

Parameters:

  • initFunc Function

    A function to call to resolve the variable value

Returns:

Object:

The lazy varialbe

escapeHtml

(
  • html
)
String static

Returns an String that has it's angle brackets ('<' and '>') escaped (replaced by '<' and '>'). This will effectively cause the String to be displayed in plain text when embedded in an html page.

Parameters:

  • html String

    String to escape

Returns:

String:

escapeHtml Escaped string

executeOnDone

(
  • o
  • func
  • d
)
static

Loops through all object properties and applies a given function to each. Resolves the given deferred when done.

Parameters:

  • o Object

    Object to look through

  • func Function

    A function to be executed with each object propety. Accepts two parameters: property and deferred to be resolved when it's done.

  • d Object

    A deferred to be resolved when all properties have been processed.

executeOnLoad

(
  • func
  • callback
)
static

Waits until a given function is available and executes a callback function.

Parameters:

  • func Function

    A function whose availability in question

  • callback Function

    The callback function to be executed after func is available

getWhereClause

(
  • varName
  • query
)
String static

Returns an appropriate where clause depending on whether the query is a String (returns a where clause with CASE INSENSITIVE comparison) or an integer.

Parameters:

Returns:

String:

The generated "where" clause

guid

() String static

Generates an rfc4122 version 4 compliant guid. Taken from here: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript

Returns:

String:

The generated guid string

isNumber

(
  • input
)
Boolean static

Returns true if the given String is a number

Parameters:

  • input String

    The string to check

Returns:

Boolean:

True if number

isUndefined

(
  • obj
)
Boolean static

Returns true if the given obj is undefined, false otherwise.

Parameters:

  • obj Object

    Object to be checked

Returns:

Boolean:

True if the given object is undefined, false otherwise

once

(
  • func
)
Function static

Returns a function that has the same functionality as the given function, but can only be executed once (subsequent execution does nothing).

Parameters:

  • func Function

    Function to be decorated

Returns:

Function:

Decorated function that can be executed once

parseBool

(
  • str
)
Boolean static

Parse the given String into a boolean. Returns true if the String is the word "true" (case insensitive). False otherwise.

Parameters:

  • str String

    The string to check

Returns:

Boolean:

True if true

queryToArray

(
  • query
)
String static

Converts a query String generated by arrayToQuery into an array object. The array object will only contain Strings.

 queryToArray("abc+123+efg") -> ["abc", "123", "efg"]

Parameters:

  • query String

    A query string to be converted

Returns:

String:

A resulting array of strings

scrollbarWidth

() Int static

Returns the width of the scrollbar in pixels. Since different browsers render scrollbars differently, the width may vary.

Returns:

Int:

The width of the scrollbar in pixels

stripHtml

(
  • html
)
String static

Converts html into text by replacing all html tags with their appropriate special characters

Parameters:

  • html String

    HTML to be converted to text

Returns:

String:

The HTML in text form

styleCheckboxes

(
  • nodes
  • checkedClass
  • focusedClass
  • labels
)
CheckboxWrapper static

Wraps the specified checkboxes to provide an alternative rendering of checkboxes without compromising their functionality. Handles synchronisation of the checkbox's state with its new rendering. Also adds highlight/unhighlight on focus/unfocus, update label when checked/unchecked

Parameters:

  • nodes JObject

    An array of jQuery objects

  • checkedClass String

    Name of the CSS class to be used when checked

  • focusedClass String

    Name of the CSS class to be used when focused

  • labels Object

    An object containing labels' text { checked: "label when checked", unchecked: "label when unchecked" }

Returns:

CheckboxWrapper:

A control objects allowing to toggle checkboxes supplying a state, and retrieve original checkbox nodes

subscribe

(
  • name
  • callback
  • scope
)
static

A convenience method that wraps around Dojo's subscribe method to allow a scope to hitched to the given callback function.

Parameters:

  • name String

    Event name

  • callback Function

    The callback to be executed

  • scope Object

    Scope of the callback

subscribeAll

(
  • nameArray
  • callback
)
static

Given an array of event names published by topic.publish, call the given callback function after ALL of the given events have occurred. An array of arguments is passed to the callback function, the arguments are those returned by the events (in the order that the events appear in the array).

Example

Assume somewhere a module publishes a "click" event:

 topic.publish("click", { mouseX: 10, mouseY: 50 });

and somewhere else another module publishes a "finishLoading" event:

 topic.publish("finishLoading", { loadedPictures: [pic1, pic2] });

Then if one wants to do something (e.g. display pictures) only after the pictures have been loaded AND the user clicked somewhere, then:

  • args[0] will be the object returned by the "click" event
  • which in this case will be: { mouseX: 10, mouseY: 50 }
  • args[1] will be the object returned by the "finishLoading" event
  • which in this case will be: { loadedPictures: [pic1, pic2] }
 subscribe(["click", "finishLoading"], function(args) {
     doSomething();
 });

NOTE: If one of the events fires multiple times before the other event, the object passed by this function to the callback will be the object returned when the event FIRST fired (subsequent firings of the same event are ignored). Also, if some event do not return an object, it will also be excluded in the arguments to the callback function. So be careful! For example, say you subscribed to the events: "evt1", "evt2", "evt3". "evt1" returns an object (call it "evt1Obj"), "evt2" does not, "evt3" returns two objects (call it "evt3Obj-1" and "evt3Obj-2" respectively). Then the array passed to the callback will be: ["evt1Obj", "evt3Obj-1", "evt3Obj-2"].

Parameters:

  • nameArray Array

    An array of Strings containing the names of events to subscribe to

  • callback Function

    The callback to be executed

subscribeOnce

(
  • name
  • callback
)
static

Subscribes to an event, after the event has occurred, the handle is removed.

Parameters:

  • name String

    Event name

  • callback Function

    The callback to be executed

subscribeOnceAny

(
  • names
  • callback
)
static

Subscrives to a set of events, executes the callback when any of the events fire, then removes the handle.

Parameters:

  • names String

    An array of event names

  • callback Function

    The callback to be executed

transformXML

(
  • xmlurl
  • xslurl
  • callback
  • returnFragment
)
static

Applies supplied xslt to supplied xml. IE always returns a String; others may return a documentFragment or a jObject.

Parameters:

  • xmlurl String

    Location of the xml file

  • xslurl String

    Location of the xslt file

  • callback Function

    The callback to be executed

  • returnFragment Boolean

    True if you want a document fragment returned (doesn't work in IE)}