Lithium

API Docs for: 0.8.0
Show:

Li Class

Defined in: src\lithium.js:22
Module: core

Contains useful and most frequently used functions.

Methods

augment

()

Defined in src\lithium.js:269

Adds properties (and methods) to a function's prototype. Note: You won't be warned if you overwrite an existing method/property.

bind

(
  • func
  • context
  • [append=false]
  • [...]
)
Function

Defined in src\lithium.js:129

The arguments sent to this new function, followed by the optional arguments which were sent to 'bind', will be forwarded to func.
Similar to JS 1.8.5 bind, but with append as extra parameter.

Parameters:

  • func Function

    Function to call

  • context Object

    Set the value of the 'this' keyword to be within the function.

  • [append=false] Boolean optional

    If true, appends binded arguments to any call to the new (returned) function. If false, prepend arguments.

  • [...] Any optional

    Optional. Any number of arguments, which will be forwarded to func on call.

Returns:

Function: A new function which will have binded context and arguments.

childIndex

()

jQuery's index() method doesn't return the child index properly for non-element nodes (like text node, comment).

contains

(
  • ancestor
  • descendent
)
Boolean

Checks if 'ancestor' is ancestor of 'descendent'. This is still needed because IE10's element.contains is buggy sometimes.

Parameters:

  • ancestor HTMLElement
  • descendent HTMLElement

Returns:

Boolean: Returns true if 'ancestor' is indeed the ancestor of 'descendent'. Also returns true if ancestor == descendent.

dom

(
  • html
  • Any
)
DocumentFragment

Defined in src\lithium.js:328

Converts html string to a document fragment.
The html string and arguments are first sent to Li.format to get the final html string.

Parameters:

  • html String
  • Any ...

    number of arguments that will be passed on to Li.format. Check Li.format documentation for more information.

Returns:

DocumentFragment:

extend

(
  • baseC
  • derived
)
Function

Defined in src\lithium.js:189

Classical inheritence, where only prototype is inherited.

Parameters:

  • baseC Function

    The constructor to be inherited from (the parent)

  • derived Object

    The object which has a constructor and methods/properties. This will be the derived class.

    • constructor Function

      Should be a function constructor of derived class.

    • statics Object

      An object whose properties will be added to the derived constructor as static properties/methods.

Returns:

Function: Returns the derived constructor (the same derived.constructor).

forEach

(
  • obj
  • callback
  • [context]
)
Object

Defined in src\lithium.js:245

Iterate through an array or object.
Iterates through an object's properties and calls the given callback for each (enumerable) property.

Note: For arrays, this method calls Array.forEach, so for IE8 you must include lithium.ie.lang module.

Parameters:

  • obj Object

    The array/object to iterate through.

  • callback Function

    Callback function. Value, index/key and a reference to the array/object are sent as parameters (in order) to the callback.

  • [context] Object optional

    Optional The value of the 'this' keyword within the callback.

Returns:

Object: obj

format

(
  • str
  • arg
)

Defined in src\lithium.js:305

String formatting

Parameters:

  • str String

    String with placeholders

  • arg Object | ...

    If object then you can use {propertyName} as placeholder. Else you can supply n number of args and use {argument index} as placholder

Example:

Li.format('<div class="{0}">', 'box');
Li.format('<div class="{cls}">', {cls: 'box'});
//output of both: <div class="box">

isArray

()

Defined in src\lithium.js:89

Same as Array.isArray

isBoolean

(
  • val
)

Defined in src\lithium.js:38

Returns true for all values that are of type 'boolean'
Note that booleans declared with 'new' keyword are objects and aren't considered "boolean"s.

Parameters:

  • val Any

isDefined

(
  • val
)

Defined in src\lithium.js:29

Checks whether a variable is defined.

Parameters:

  • val Any

isElement

(
  • obj
)

Defined in src\lithium.js:103

Checks whether a given value is a DOM Element (Text nodes aren't included, nodeType should = 1)

Parameters:

  • obj Object

isFinite

(
  • val
)

Defined in src\lithium.js:78

Returns true for any finite number. Note that numbers declared with 'new' keyword are objects and aren't considered "number"s.

Parameters:

  • val Any

isFunction

()

Defined in src\lithium.js:95

Same as jQuery.isFunction

isNaN

(
  • val
)

Defined in src\lithium.js:116

Returns true only when value is NaN.

Parameters:

  • val Any

isNumber

(
  • val
)

Defined in src\lithium.js:68

Returns true for any number (including Infinity). Note that numbers declared with 'new' keyword are objects and aren't considered "number"s.

Parameters:

  • val Any

isObject

(
  • val
)

Defined in src\lithium.js:48

Any value that is an object (excluding null).
Note that arrays, functions and all data declared with 'new' keyword is an object.

Parameters:

  • val Any

isString

(
  • val
)

Defined in src\lithium.js:58

Checks whether a given value is a string.
Note that strings declared with 'new' keyword are objects and aren't considered "string"s.

Parameters:

  • val Any

lbind

(
  • func
  • [context]
  • [...]
)

Defined in src\lithium.js:149

'Left' bind
Same as bind, except that arguments are always prepended.

Parameters:

  • func Function

    Function to bind

  • [context] Object | Null optional

    The context in which func is to be called. null would default to the global object.

  • [...] Any optional

    Any number of arguments to be binded to func.

mix

(
  • target
  • source
  • [...]
)

Defined in src\lithium.js:173

Copies properties of given object(s) into a target object. Only does a shallow copy.

Parameters:

  • target Object

    Target object into which properties of source object is copies to.

  • source Object

    One or more objects from which the properties are taken from.

  • [...] Arguments optional

move

(
  • target
  • source
  • props
)
Object

Move properties from one object to another.
Property is only moved if source.hasOwnProperty(property) is true.

Parameters:

  • target Object

    Object to which properties are to be moved

  • source Object

    Object from which properties are to moved.

  • props Arraystring

    Array of properties to move.

Returns:

Object: target Returns target object

namespace

(
  • path
)

Defined in src\lithium.js:291

Parameters:

  • path String

Example:

Li.namespace('mynamespace.ui.widgets');

rbind

(
  • func
  • [context]
  • [...]
)

Defined in src\lithium.js:161

'Right' bind
Same as bind, except that arguments are always appended.

Parameters:

  • func Function

    Function to bind

  • [context] Object | Null optional

    The context in which func is to be called. null would default to the global object.

  • [...] Any optional

    Any number of arguments to be binded to func.

slice

(
  • array
)

Defined in src\lithium.js:345

Same as Array.slice except that it can work on array-like data types (i.e arguments, element.childNodes, NodeList...)

Parameters:

  • array Array-like

    Array like values.

Example:

var elements = Li.slice(document.body.childNodes, 3); //get first 3 nodes.

toHTML

(
  • frag
)
String

Converts DOM to HTML string

Parameters:

  • frag DocumentFragment

Returns:

String:

traverse

(
  • node
  • ancestor
  • callback
  • [scope]
)

Given a DOM node, this method finds the next tag/node that would appear in the dom. WARNING: Do not remove or add nodes while traversing, because it could cause the traversal logic to go crazy.

Parameters:

  • node Object

    Could be a any node (element node or text node)

  • ancestor Object

    Node An ancestorial element that can be used to limit the search. The search algorithm, while traversing the ancestorial heirarcy, will not go past/above this element.

  • callback Function

    A callback called on each element traversed.

    callback gets following parameters: node: Current node being traversed. isOpenTag: boolean. On true, node would be the next open tag/node that one would find when going linearly downwards through the DOM. Filtering with isOpenTag=true, one would get exactly what native TreeWalker does. Similarly isOpenTag=false when a close tag is encountered when traversing the DOM. AFAIK TreeWalker doesn't give this info.

    callback can return one of the following values (with their meanings): 'halt': Stops immediately and returns null. 'return': Halts and returns node. 'continue': Skips further traversal of current node (i.e won't traverse it's child nodes). 'break': Skips all sibling elements of current node and goes to it's parent node.

    relation: The relation compared to the previously traversed node.

  • [scope] Object optional

    Value of 'this' keyword within callback

uuid

(
  • [len=10]
  • [hypenate=false]
)
String

Defined in src\lithium.js:372

Generates an unique alpha-numeric identifier.
To get the same permutation as RFC-4122 use len=24.

Parameters:

  • [len=10] Object optional

    Length of the UUID.

  • [hypenate=false] Object optional

    When set to true, hyphens are added to the UUID.

Returns:

String: The UUID

Properties

browser

Object final

Browser information. This object has 3 sub-properties: name, version and OS.
Overrides jQuery.browser. You also get three 'is' prefixed boolean properties attached to Li:
1. for OS (e.g Li.isWindows), 2. for browser vendor (e.g Li.isIE), and 3. vendor+version (e.g Li.isIE8).