API Docs for: 2.0.0

Class SAGE2_runtime

Class defined in: public/src/SAGE2_runtime.js:15

Generic functions used by all SAGE2 applications

Boolean addCookie( sKey, sValue )
public/src/SAGE2_runtime.js:851

Add a key-value pair as a cookie

Parameters:
Returns: <Boolean>

true/false

Bool allTrueDict( dict )
public/src/SAGE2_runtime.js:581

Test if all values of an object are true

Parameters:
Returns: <Bool>

true if all values are true

Number average( arr )
public/src/SAGE2_runtime.js:562

Calculate the average value of an array

Parameters:
  • arr <Array>

    values to be averaged


Returns: <Number>

the average

String base64ToString( base64 )
public/src/SAGE2_runtime.js:385

Decode base64 into string

Parameters:
  • base64 <String>

    content to be decoded


Returns: <String>

string content

TypedArray base64ToUint8Array( base64 )
public/src/SAGE2_runtime.js:443

Convert a string to Uint8Array typed array

Parameters:
  • base64 <String>

    string to be converted


Returns: <TypedArray>

resulting array

broadcast( dataObject )
public/src/SAGE2_runtime.js:334

Send the broadcast call to the server

Parameters:
  • dataObject <Object>

    data to be sent

Number byteBufferToInt( buff )
public/src/SAGE2_runtime.js:802

Convert an array of byte to an integer

Parameters:
  • buff <Array>

    buffer to be processed


Returns: <Number>

resulting value

String byteBufferToString( buff )
public/src/SAGE2_runtime.js:817

Convert an array of byte to a string (using fromCharCode on every character)

Parameters:
  • buff <Array>

    buffer to be processed


Returns: <String>

string

Strinf cleanURL( url )
public/src/SAGE2_runtime.js:670

Cleanup a URL and replace the origin to match the client (to mitigate CORS problems, cross-origin resource sharing)

Parameters:
Returns: <Strinf>

new URL

Boolean copyToClipboard( text )
public/src/SAGE2_runtime.js:965

From stackoverflow: Copies a string to the clipboard. Must be called from within an event handler such as click. May return false if it failed, but this is not always possible. Browser support for Chrome 43+, Firefox 42+, Safari 10+, Edge and IE 10+. IE: The clipboard feature may be disabled by an administrator. By default a prompt is shown the first time the clipboard is used (per session)

Parameters:
  • text <String>

    The text to be copied


Returns: <Boolean>

A Boolean that is false if the command is not supported or enabled

Element createDrawingElement( id, className, posx, posy, width, height, depth )
public/src/SAGE2_runtime.js:150

Basic function for creating a canvas in the DOM

Parameters:
  • id <String>

    DOM id to be created

  • className <String>

    CSS class

  • posx <Number>

    position x

  • posy <Number>

    position y

  • width <Number>

    width (number in pixel)

  • height <Number>

    height (number in pixel)

  • depth <Number>

    z index


Returns: <Element>

DOM canvas element

Array csvToArray( strData, strDelimiter )
public/src/SAGE2_runtime.js:495

Convert CSV data to an array (used by the readFile function)

Parameters:
  • strData <String>

    data to be converter

  • strDelimiter <String>

    string delimter (parsing using RegExp)


Returns: <Array>

array containing the parsed data

Boolean deleteCookie( sKey )
public/src/SAGE2_runtime.js:901

Delete a cookie for a given key

Parameters:
Returns: <Boolean>

true/false

deleteElement( id )
public/src/SAGE2_runtime.js:641

Delete an element in the DOM

Parameters:
  • id <Element>

    DOM element to delete

String format24Hr( date )
public/src/SAGE2_runtime.js:355

Convert date into 24h string format

Parameters:
  • date <Object>

    momentjs object for time


Returns: <String>

formatted date

String formatAMPM( date )
public/src/SAGE2_runtime.js:344

Pretty print a date object into string

Parameters:
  • date <Object>

    momentjs object for time


Returns: <String>

formatted date

String formatHHMMSS( duration )
public/src/SAGE2_runtime.js:366

Convert a duration number into readable string

Parameters:
Returns: <String>

formatted duration

String getCookie( sKey )
public/src/SAGE2_runtime.js:916

Return a cookie value for given key

Parameters:
Returns: <String>

value found or null

String getParameterByName( name )
public/src/SAGE2_runtime.js:598

Extract the parameter value from the current URL (?clientID=0&param=4)

Parameters:
  • name <String>

    parameter to search for


Returns: <String>

null or the value found

Object getTransform( elem )
public/src/SAGE2_runtime.js:932

Extract translate and scale from a DOM element

Parameters:
Returns: <Object>

contains translate and scale specification

Array initializeArray( size, value )
public/src/SAGE2_runtime.js:786

Create an array of given size filled with a value

Parameters:
  • size <Number>

    size of the array

  • value <Value>

    initial value


Returns: <Array>

new array

Bool isEmpty( obj )
public/src/SAGE2_runtime.js:753

Test is an object is equivalen to 'empty'

Parameters:
  • obj <Object>

    value to be tested


Returns: <Bool>

true if empty

Bool isTrue( element, index, array )
public/src/SAGE2_runtime.js:740

Test if element is equal to true (used in .every call on an array)

Parameters:
  • element <Bool>

    The current element being processed in the array

  • index <Number>

    The index of the current element being processed in the array

  • array <Array>

    The array every was called upon


Returns: <Bool>

true if element is true

log( obj )
public/src/SAGE2_runtime.js:129

Debug log function: send parameters to server for printout if mutiple paramters, sent as one array

Parameters:
  • obj <Object>

    data to be printed

Math.seed( s )
public/src/SAGE2_runtime.js:834

Overload Math.seed and Math.random to be deterministic, for distributed work

Parameters:
moveItemToFront( elem )
public/src/SAGE2_runtime.js:627

Reorder elements at given level in the DOM

Parameters:
  • elem <Element>

    DOM element to reorder

parseBool( value )
public/src/SAGE2_runtime.js:714

Utility function to test if a string or number represents a true value. Used for parsing JSON values

Parameters:
  • value <Object>

    value to test

playPauseVideo( elemId )
public/src/SAGE2_runtime.js:612

Search for a video tag and switch its state

Parameters:
  • elemId <String>

    video element to search

readFile( filename, callback, type )
public/src/SAGE2_runtime.js:460

Do a HTTP GET request to the server to retrieve a file content

Parameters:
  • filename <String>

    URL of the file to be read

  • callback <Function>

    called when data is received: callback(err, data)

  • type <String>

    type of data: TEXT, JSON, CSV, or SVG

removeAllChildren( node )
public/src/SAGE2_runtime.js:654

Remove of children of a DOM element

Parameters:
SAGE2_browser( )
public/src/SAGE2_runtime.js:53

Detect the current browser

SAGE2_initialize( data_seed )
public/src/SAGE2_runtime.js:42

Initializes global settings: random generator, ...

Parameters:
  • data_seed <Date>

    seed number

sage2Log( msgObject )
public/src/SAGE2_runtime.js:316

Pretty print in browser and send to server

Parameters:
  • msgObject <Object>

    data to be printed

String smallTansparentGIF( )
public/src/SAGE2_runtime.js:407

Smallest transparent image, put in a image tag source


Returns: <String>

small GIF image in base64 content

String smallWhiteGIF( )
public/src/SAGE2_runtime.js:417

Smallest white image, put in a image tag source


Returns: <String>

small GIF image in base64 content

String stringToBase64( string )
public/src/SAGE2_runtime.js:396

Encode a string to base64

Parameters:
  • string <String>

    content to be encoded


Returns: <String>

base64 content

TypedArray stringToUint8Array( string )
public/src/SAGE2_runtime.js:428

Convert a string to Uint8Array typed array

Parameters:
  • string <String>

    string to be converted


Returns: <TypedArray>

resulting array

__SAGE2__ <Object>
public/src/SAGE2_runtime.js:24

Global object, containing the version number

SAGE2types <Object>
public/src/SAGE2_runtime.js:176

Basic data types for inter-application communications