Li Class
Contains useful and most frequently used functions.
Item Index
Methods
Properties
Methods
augment
()
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]
-
[...]
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
FunctionFunction to call
-
context
ObjectSet the value of the 'this' keyword to be within the function.
-
[append=false]
Boolean optionalIf true, appends binded arguments to any call to the new (returned) function. If false, prepend arguments.
-
[...]
Any optionalOptional. Any number of arguments, which will be forwarded to func on call.
Returns:
childIndex
()
jQuery's index() method doesn't return the child index properly for non-element nodes (like text node, comment).
contains
-
ancestor
-
descendent
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:
dom
-
html
-
Any
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:
extend
-
baseC
-
derived
Classical inheritence, where only prototype is inherited.
Parameters:
-
baseC
FunctionThe constructor to be inherited from (the parent)
-
derived
ObjectThe object which has a constructor and methods/properties. This will be the derived class.
-
constructor
FunctionShould be a function constructor of derived class.
-
statics
ObjectAn object whose properties will be added to the derived constructor as static properties/methods.
-
Returns:
forEach
-
obj
-
callback
-
[context]
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
ObjectThe array/object to iterate through.
-
callback
FunctionCallback function. Value, index/key and a reference to the array/object are sent as parameters (in order) to the callback.
-
[context]
Object optionalOptional The value of the 'this' keyword within the callback.
Returns:
format
-
str
-
arg
String formatting
Parameters:
-
str
StringString 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
()
Same as Array.isArray
isBoolean
-
val
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
Checks whether a variable is defined.
Parameters:
-
val
Any
isElement
-
obj
Checks whether a given value is a DOM Element (Text nodes aren't included, nodeType should = 1)
Parameters:
-
obj
Object
isFinite
-
val
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
()
Same as jQuery.isFunction
isNaN
-
val
Returns true only when value is NaN.
Parameters:
-
val
Any
isNumber
-
val
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
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
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]
-
[...]
'Left' bind
Same as bind, except that arguments are always prepended.
Parameters:
-
func
FunctionFunction to bind
-
[context]
Object | Null optionalThe context in which func is to be called. null would default to the global object.
-
[...]
Any optionalAny number of arguments to be binded to func.
mix
-
target
-
source
-
[...]
Copies properties of given object(s) into a target object. Only does a shallow copy.
Parameters:
-
target
ObjectTarget object into which properties of source object is copies to.
-
source
ObjectOne or more objects from which the properties are taken from.
-
[...]
Arguments optional
move
-
target
-
source
-
props
Move properties from one object to another.
Property is only moved if source.hasOwnProperty(property) is true.
Parameters:
-
target
ObjectObject to which properties are to be moved
-
source
ObjectObject from which properties are to moved.
-
props
ArraystringArray of properties to move.
Returns:
namespace
-
path
Parameters:
-
path
String
Example:
Li.namespace('mynamespace.ui.widgets');
rbind
-
func
-
[context]
-
[...]
'Right' bind
Same as bind, except that arguments are always appended.
Parameters:
-
func
FunctionFunction to bind
-
[context]
Object | Null optionalThe context in which func is to be called. null would default to the global object.
-
[...]
Any optionalAny number of arguments to be binded to func.
slice
-
array
Same as Array.slice except that it can work on array-like data types (i.e arguments, element.childNodes, NodeList...)
Parameters:
-
array
Array-likeArray like values.
Example:
var elements = Li.slice(document.body.childNodes, 3); //get first 3 nodes.
toHTML
-
frag
Converts DOM to HTML string
Parameters:
-
frag
DocumentFragment
Returns:
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
ObjectCould be a any node (element node or text node)
-
ancestor
ObjectNode 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
FunctionA 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 optionalValue of 'this' keyword within callback
uuid
-
[len=10]
-
[hypenate=false]
Generates an unique alpha-numeric identifier.
To get the same permutation as RFC-4122 use len=24.
Parameters:
-
[len=10]
Object optionalLength of the UUID.
-
[hypenate=false]
Object optionalWhen set to true, hyphens are added to the UUID.
Returns:
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).