Reusable Accessible Mapping Platform

API Docs for: 5.3.1
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.

Methods

_wrapFileCallInPromise

(
  • readMethod
)
Function private

Helper function for wrapping File API calls in Promise objects. Used for building a series of helpers which call different file read methods.

Parameters:

  • readMethod String

    a string indicating the FileReader method to call

Returns:

Function:

a function which accepts a {File} object and returns a Promise

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 accommodate for the scrollbar assuming target's width is set to "100%".

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

b64EncodeUnicode

(
  • str
)
String

Base64 encoding for unicode text.

Parameters:

  • str String

    a string to encode

Returns:

String:

encoded string

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

containsInDom

(
  • el
)
Boolean static

Checks if the given dom node is present in the dom.

Parameters:

Returns:

Boolean:

true if the given node is in the dom

createGraphic

(
  • extent
)
Esri/Graphic static

Create boudingbox graphic for a bounding box extent

Parameters:

  • extent Esri/geometry/Extent

    of a bounding box

Returns:

Esri/Graphic:

An ESRI graphic object represents a bouding box

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 variable

detectDelimiter

(
  • data
  • [type]
)
String static

Detects either cell or line delimiter in a given csv data.

Parameters:

  • data String

    csv content

  • [type] String optional

    Type of the delimiter to detect. Possible values "cell" or "line". Defaults to "cell".

Returns:

String:

Detected delimiter

endsWith

(
  • str
  • suffix
)
Boolean static

Checks if the string ends with the supplied suffix.

Parameters:

  • str String

    String to be evaluated

  • suffix String

    Ending string to be matched

Returns:

Boolean:

True if suffix matches

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

(
  • target
  • func
  • callback
)
static

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

Parameters:

  • target Object

    an object on which to wait for function to appear

  • 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

hexToRgb

(
  • hex
)
Object static

Parameters:

Returns:

Object:

object containing r, g, and b components of the supplied colour

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

isSpatialRefEqual

(
  • sr1
  • sr2
)
Boolean static

Checks if two spatial reference objects are equivalent. Handles both wkid and wkt definitions

Parameters:

Returns:

Boolean:

true if the two spatial references are equivalent. False otherwise.

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

keyboardSortable

(
  • ulNodes
  • [settings]
)
static

Augments lists of items to be sortable using keyboard.

Parameters:

  • ulNodes Array

    An array of

      tags containing a number of
    • tags to be made keyboard sortable.

  • [settings] Object optional

    Additional settings

    • [linkLists] Object optional

      Indicates if the supplied lists (if more than one) should be linked - items could be moved from one to another; Update: this is wrong - items can't be moved from list to list right now, but the keyboard focus can be moved between lists - need to fix.

    • [onStart] Object optional

      A callback function to be called when the user initiates sorting process

    • [onUpdate] Object optional

      A callback function to be called when the user moves the item around

    • [onStop] Object optional

      A callback function to be called when the user commits the item to its new place ending the sorting process

mergeRecursive

() static

Recursively merge JSON objects into a target object. The merge will also merge array elements.

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

readFileAsArrayBuffer

(
  • file
)
Object static

Parses a file using the FileReader API. Wraps readAsArrayBuffer and returns a promise.

Parameters:

  • file File

    a dom file object to be read

Returns:

Object:

a promise which sends an ArrayBuffer containing the file output if successful

readFileAsBinary

(
  • file
)
Object static

Parses a file using the FileReader API. Wraps readAsBinaryString and returns a promise.

Parameters:

  • file File

    a dom file object to be read

Returns:

Object:

a promise which sends a string containing the file output if successful

readFileAsText

(
  • file
)
Object static

Parses a file using the FileReader API. Wraps readAsText and returns a promise.

Parameters:

  • file File

    a dom file object to be read

Returns:

Object:

a promise which sends a string containing the file output if successful

resetTimelines

(
  • tls
  • keepPosition
)
static

Takes an array of timelines and their generator functions, clear and recreates timelines optionally preserving the play position.

Example of tls parameter

 [
     {
         timeline: {timeline},
         generator: {function}
     }
 ]

Parameters:

  • tls Array

    An array of objects containing timeline objects and their respective generator functions

  • keepPosition Boolean

    Indicates if the timeline should be set in the play position it was in before the reset

rgbToHex

(
  • r
  • g
  • b
)
Object static

Parameters:

Returns:

Object:

hex colour code

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

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

Subscribes 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)}