Core.js

Summary
Core.js
$jitDefines the namespace for all library Classes and Objects.
$jit.idWorks just like document.getElementById
$jit.utilContains utility functions.
Functions
extendAugment an object by appending another object’s properties.
splatReturns an array wrapping obj if obj is not an array.
eachIterates through an iterable applying f.
mapMaps or collects an array by applying f.
reduceIteratively applies the binary function f storing the result in an accumulator.
mergeMerges n-objects and their sub-objects creating a new, fresh object.
rgbToHexConverts an RGB array into a Hex string.
hexToRgbConverts an Hex color string into an RGB array.
addEventCross-browser add event listener.
$jit.jsonProvides JSON utility functions.
Functions
pruneClears all tree nodes having depth greater than maxLevel.
getParentReturns the parent node of the node having id as id.
getSubtreeReturns the subtree that matches the given id.
eachLevelIterates on tree nodes with relative depth less or equal than a specified level.
eachA JSON tree iterator.

$jit

Defines the namespace for all library Classes and Objects.  This variable is the only global variable defined in the Toolkit.  There are also other interesting properties attached to this variable described below.

$jit.id

Works just like document.getElementById

Example

var element = $jit.id('elementId');

$jit.util

Contains utility functions.

Some of the utility functions and the Class system were based in the MooTools Framework http://mootools.net.  Copyright © 2006-2010 Valerio Proietti, http://mad4milk.net/.  MIT license http://mootools.net/license.txt.

These methods are generally also implemented in DOM manipulation frameworks like JQuery, MooTools and Prototype.  I’d suggest you to use the functions from those libraries instead of using these, since their functions are widely used and tested in many different platforms/browsers.  Use these functions only if you have to.

Summary
Functions
extendAugment an object by appending another object’s properties.
splatReturns an array wrapping obj if obj is not an array.
eachIterates through an iterable applying f.
mapMaps or collects an array by applying f.
reduceIteratively applies the binary function f storing the result in an accumulator.
mergeMerges n-objects and their sub-objects creating a new, fresh object.
rgbToHexConverts an RGB array into a Hex string.
hexToRgbConverts an Hex color string into an RGB array.
addEventCross-browser add event listener.

Functions

extend

$.extend = function(original,
extended)

Augment an object by appending another object’s properties.

Parameters

original(object) The object to be extended.
extended(object) An object which properties are going to be appended to the original object.

Example

$jit.util.extend({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 4 }); //{ 'a':1, 'b': 3, 'c': 4 }

splat

$.splat = function(obj)

Returns an array wrapping obj if obj is not an array.  Returns obj otherwise.

Parameters

obj(mixed) The object to be wrapped in an array.

Example

$jit.util.splat(3);   //[3]
$jit.util.splat([3]); //[3]

each

$.each = function(iterable,
fn)

Iterates through an iterable applying f.

Parameters

iterable(array) The original array.
fn(function) The function to apply to the array elements.

Example

$jit.util.each([3, 4, 5], function(n) { alert('number ' + n); });

map

$.map = function(array,
f)

Maps or collects an array by applying f.

Parameters

array(array) The original array.
f(function) The function to apply to the array elements.

Example

$jit.util.map([3, 4, 5], function(n) { return n*n; }); //[9, 16, 25]

reduce

$.reduce = function(array,
f,
opt)

Iteratively applies the binary function f storing the result in an accumulator.

Parameters

array(array) The original array.
f(function) The function to apply to the array elements.
opt(optional|mixed) The starting value for the acumulator.

Example

$jit.util.reduce([3, 4, 5], function(x, y) { return x + y; }, 0); //12

merge

$.merge = function()

Merges n-objects and their sub-objects creating a new, fresh object.

Parameters

An arbitrary number of objects.

Example

$jit.util.merge({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 4 }); //{ 'a':1, 'b': 3, 'c': 4 }

rgbToHex

$.rgbToHex = function(srcArray,
array)

Converts an RGB array into a Hex string.

Parameters

srcArray(array) An array with R, G and B values

Example

$jit.util.rgbToHex([255, 255, 255]); //'#ffffff'

hexToRgb

$.hexToRgb = function(hex)

Converts an Hex color string into an RGB array.

Parameters

hex(string) A color hex string.

Example

$jit.util.hexToRgb('#fff'); //[255, 255, 255]

addEvent

$.addEvent = function(obj,
type,
fn)

Cross-browser add event listener.

Parameters

obj(obj) The Element to attach the listener to.
type(string) The listener type.  For example ‘click’, or ‘mousemove’.
fn(function) The callback function to be used when the event is fired.

Example

$jit.util.addEvent(elem, 'click', function(){ alert('hello'); });

$jit.json

Provides JSON utility functions.

Most of these functions are JSON-tree traversal and manipulation functions.

Summary
Functions
pruneClears all tree nodes having depth greater than maxLevel.
getParentReturns the parent node of the node having id as id.
getSubtreeReturns the subtree that matches the given id.
eachLevelIterates on tree nodes with relative depth less or equal than a specified level.
eachA JSON tree iterator.

Functions

prune

prune: function(tree,
maxLevel)

Clears all tree nodes having depth greater than maxLevel.

Parameters

tree(object) A JSON tree object.  For more information please see Loader.loadJSON.
maxLevel(number) An integer specifying the maximum level allowed for this tree.  All nodes having depth greater than max level will be deleted.

getParent

getParent: function(tree,
id)

Returns the parent node of the node having id as id.

Parameters

tree(object) A JSON tree object.  See also Loader.loadJSON.
id(string) The id of the child node whose parent will be returned.

Returns

A tree JSON node if any, or false otherwise.

getSubtree

getSubtree: function(tree,
id)

Returns the subtree that matches the given id.

Parameters

tree(object) A JSON tree object.  See also Loader.loadJSON.
id(string) A node unique identifier.

Returns

A subtree having a root node matching the given id.  Returns null if no subtree matching the id is found.

eachLevel

eachLevel: function(tree,
initLevel,
toLevel,
action)

Iterates on tree nodes with relative depth less or equal than a specified level.

Parameters

tree(object) A JSON tree or subtree.  See also Loader.loadJSON.
initLevel(number) An integer specifying the initial relative level.  Usually zero.
toLevel(number) An integer specifying a top level.  This method will iterate only through nodes with depth less than or equal this number.
action(function) A function that receives a node and an integer specifying the actual level of the node.

Example

$jit.json.eachLevel(tree, 0, 3, function(node, depth) {
   alert(node.name + ' ' + depth);
});

each

each: function(tree,
action)

A JSON tree iterator.

Parameters

tree(object) A JSON tree or subtree.  See also Loader.loadJSON.
action(function) A function that receives a node.

Example

$jit.json.each(tree, function(node) {
  alert(node.name);
});
$.extend = function(original,
extended)
Augment an object by appending another object’s properties.
$.splat = function(obj)
Returns an array wrapping obj if obj is not an array.
$.each = function(iterable,
fn)
Iterates through an iterable applying f.
$.map = function(array,
f)
Maps or collects an array by applying f.
$.reduce = function(array,
f,
opt)
Iteratively applies the binary function f storing the result in an accumulator.
$.merge = function()
Merges n-objects and their sub-objects creating a new, fresh object.
$.rgbToHex = function(srcArray,
array)
Converts an RGB array into a Hex string.
$.hexToRgb = function(hex)
Converts an Hex color string into an RGB array.
$.addEvent = function(obj,
type,
fn)
Cross-browser add event listener.
prune: function(tree,
maxLevel)
Clears all tree nodes having depth greater than maxLevel.
getParent: function(tree,
id)
Returns the parent node of the node having id as id.
getSubtree: function(tree,
id)
Returns the subtree that matches the given id.
eachLevel: function(tree,
initLevel,
toLevel,
action)
Iterates on tree nodes with relative depth less or equal than a specified level.
each: function(tree,
action)
A JSON tree iterator.
loadJSON: function(json,
i)
Loads a JSON structure to the visualization.
Close