Core.js | |
$jit | Defines the namespace for all library Classes and Objects. |
$jit.id | Works just like document.getElementById |
$jit.util | Contains utility functions. |
Functions | |
extend | Augment an object by appending another object’s properties. |
splat | Returns an array wrapping obj if obj is not an array. |
each | Iterates through an iterable applying f. |
map | Maps or collects an array by applying f. |
reduce | Iteratively applies the binary function f storing the result in an accumulator. |
merge | Merges n-objects and their sub-objects creating a new, fresh object. |
rgbToHex | Converts an RGB array into a Hex string. |
hexToRgb | Converts an Hex color string into an RGB array. |
addEvent | Cross-browser add event listener. |
$jit.json | Provides JSON utility functions. |
Functions | |
prune | Clears all tree nodes having depth greater than maxLevel. |
getParent | Returns the parent node of the node having id as id. |
getSubtree | Returns the subtree that matches the given id. |
eachLevel | Iterates on tree nodes with relative depth less or equal than a specified level. |
each | A JSON tree iterator. |
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.
Functions | |
extend | Augment an object by appending another object’s properties. |
splat | Returns an array wrapping obj if obj is not an array. |
each | Iterates through an iterable applying f. |
map | Maps or collects an array by applying f. |
reduce | Iteratively applies the binary function f storing the result in an accumulator. |
merge | Merges n-objects and their sub-objects creating a new, fresh object. |
rgbToHex | Converts an RGB array into a Hex string. |
hexToRgb | Converts an Hex color string into an RGB array. |
addEvent | Cross-browser add event listener. |
$.extend = function( original, extended )
Augment an object by appending another object’s properties.
original | (object) The object to be extended. |
extended | (object) An object which properties are going to be appended to the original object. |
$jit.util.extend({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 4 }); //{ 'a':1, 'b': 3, 'c': 4 }
$.reduce = function( array, f, opt )
Iteratively applies the binary function f storing the result in an accumulator.
array | (array) The original array. |
f | (function) The function to apply to the array elements. |
opt | (optional|mixed) The starting value for the acumulator. |
$jit.util.reduce([3, 4, 5], function(x, y) { return x + y; }, 0); //12
$.addEvent = function( obj, type, fn )
Cross-browser add event listener.
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. |
$jit.util.addEvent(elem, 'click', function(){ alert('hello'); });
Provides JSON utility functions.
Most of these functions are JSON-tree traversal and manipulation functions.
Functions | |
prune | Clears all tree nodes having depth greater than maxLevel. |
getParent | Returns the parent node of the node having id as id. |
getSubtree | Returns the subtree that matches the given id. |
eachLevel | Iterates on tree nodes with relative depth less or equal than a specified level. |
each | A JSON tree iterator. |
prune: function( tree, maxLevel )
Clears all tree nodes having depth greater than maxLevel.
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: function( tree, id )
Returns the parent node of the node having id as id.
tree | (object) A JSON tree object. See also Loader.loadJSON. |
id | (string) The id of the child node whose parent will be returned. |
A tree JSON node if any, or false otherwise.
getSubtree: function( tree, id )
Returns the subtree that matches the given id.
tree | (object) A JSON tree object. See also Loader.loadJSON. |
id | (string) A node unique identifier. |
A subtree having a root node matching the given id. Returns null if no subtree matching the id is found.
eachLevel: function( tree, initLevel, toLevel, action )
Iterates on tree nodes with relative depth less or equal than a specified level.
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. |
$jit.json.eachLevel(tree, 0, 3, function(node, depth) { alert(node.name + ' ' + depth); });
each: function( tree, action )
A JSON tree iterator.
tree | (object) A JSON tree or subtree. See also Loader.loadJSON. |
action | (function) A function that receives a node. |
$jit.json.each(tree, function(node) { alert(node.name); });
Augment an object by appending another object’s properties.
$.extend = function( original, extended )
Returns an array wrapping obj if obj is not an array.
$.splat = function( obj )
Iterates through an iterable applying f.
$.each = function( iterable, fn )
Maps or collects an array by applying f.
$.map = function( array, f )
Iteratively applies the binary function f storing the result in an accumulator.
$.reduce = function( array, f, opt )
Merges n-objects and their sub-objects creating a new, fresh object.
$.merge = function()
Converts an RGB array into a Hex string.
$.rgbToHex = function( srcArray, array )
Converts an Hex color string into an RGB array.
$.hexToRgb = function( hex )
Cross-browser add event listener.
$.addEvent = function( obj, type, fn )
Clears all tree nodes having depth greater than maxLevel.
prune: function( tree, maxLevel )
Returns the parent node of the node having id as id.
getParent: function( tree, id )
Returns the subtree that matches the given id.
getSubtree: function( tree, id )
Iterates on tree nodes with relative depth less or equal than a specified level.
eachLevel: function( tree, initLevel, toLevel, action )
A JSON tree iterator.
each: function( tree, action )
Loads a JSON structure to the visualization.
loadJSON: function( json, i )