Function.prototype.bind alternative/fallback. Creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
Accepts
fn
The function
context
The value to be passed as the this parameter to the target function when the bound function is called. If used as false, it preserves the original context and just binds the arguments.
more...
Additional arguments will be sent to the original function as prefix arguments.
How to keep this in the object context
Code
Ink.bind() can be used to pass more arguments to callback function
Code
.bindEvent(fn, context)
method
Function.prototype.bind alternative for event handlers. Same as bind but keeps first argument of the call the original event. Set context to false to preserve the original context of the function and just bind the arguments.
Accepts
fn
The function
context
The value to be passed as the this parameter to the target
more...
Additional arguments will be sent to the original function as prefix arguments
Ink.bindEvent() is very similar to Ink.bind but it is used to keep the this context in event handlers, and event object is passed to callback as first argument.
Code
.bindMethod(object, methodName)
method
Function.prototype.bind alternative for class methods See Ink.bind. The difference between bindMethod and bind is that bindMethod fetches a method from an object. It can be useful, for instance, to bind a function which is a property of an object returned by another function.
Accepts
object
The object that contains the method to bind
methodName
The name of the method that will be bound
more...
Additional arguments will be sent to the new method as prefix arguments.
Build a function which calls method remove of Ink.Dom.Element on an element
Code
Comparing with Ink.bind to the same effect. The following two calls are equivalent
Does exactly the same as createModule but creates the module in the Ink.Ext namespace
Accepts
moduleName
Extension name
version
Extension version
dependencies
Extension dependencies
modFn
Function returning the extension
With Ink.createExt() you can create your own module to Ink. It works like Ink.createModule() but will expose your module in Ink.Ext namespace. With this method you can contribute to Ink project with new modules and we will promote your module in our page. Read how to contribute to Ink in our CONTRIBUTING.md. Ink.createExt() can be used to create your modules to your project.
Here's an example of Ink.Ext.MyAwesomeModule_1
Code
How to create an UI extension that works with data-attributes as options. This is a simple extension. A clickable div that expands from init height to max heigh.
Code HTML
Code JavaScript
.createModule(mod, version, deps, modFn)
method
Creates a new module. Use this to wrap your code and benefit from the module loading used throughout the Ink library
Accepts
mod
Module name, separated by dots. Like Ink.Dom.Selector, Ink.UI.Modal
version
Version number
deps
Array of module names which are dependencies of the module being created. The order in which they are passed here will define the order they will be passed to the callback function.
modFn
The callback function to be executed when all the dependencies are resolved. The dependencies are passed as arguments, in the same order they were declared. The function itself should return the module.
How to create a new Ink's static module ex: Ink.Util.Calculator version 1 without dependencies
This module is static, that means, all methods will be used as Ink.Util.Calculator_1.method();
Code
How to create a new Ink's instantiable module ex: Ink.UI.ElementClickable version 1 with Ink.Dom.Event_1 and Ink.Dom.Element_1 as dependencies
This module is instantiable, that means, will be used as new Ink.UI.ElementClickable_1();
Code
.error()
method
Calls native console.error if available.
Accepts
more...
Arguments to be evaluated
Ink.error() is an alias to console.error() when it is available.
Code
.extendObj(destination, source)
method
Extends an object with another Copy all of the properties in one or more source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.
Accepts
destination
The object that will receive the new/updated properties
source
The object whose properties will be copied over to the destination object
more...
Additional source objects. The last source will override properties of the same name in the previous defined sources
Copy object person1 to person2
Code
Copy object but define default values in new object.
Code
.getModule(mod, [version])
method
Loads a module. A synchronous method to get the module from the internal registry. It assumes the module is defined and loaded already!
Accepts
mod
Module name
version
Version number of the module
.getModuleScripts()
method
Builds the markup needed to load the modules. This method builds the script tags needed to load the currently used modules
.getModulesLoadOrder()
method
Lists loaded module names. The list is ordered by loaded time (oldest module comes first)
.getPath(key, [noLib])
method
Get the full path of a module. This method looks up the paths given in setPath (and ultimately the default Ink's path).
Accepts
key
Name of the module you want to get the path
noLib
Flag to skip appending 'lib.js' to the returned path.
.i(id)
method
Shorter alias to document.getElementById. Just calls document.getElementById(id), unless id happens to be an element. If id is an element, Ink.i just returns it.
You can use this in situations where you want to accept an element id, but a raw element is also okay.
Accepts
id
Element ID
Code
.loadScript(uri, [contentType])
method
Loads a script URL. This creates a script tag in the head of the document. Reports errors by listening to 'error' and 'readystatechange' events.
Accepts
uri
Can be an external URL or a module name
contentType
'text/javascript'The `type` attribute of the new script tag.
.log()
method
Calls native console.log if available.
Accepts
more...
Arguments to be evaluated
Ink.log() is an alias to console.log() when it is available.
Code
.namespace(ns, [returnParentAndKey])
method
Defines a module namespace.
Accepts
ns
Namespace to define.
returnParentAndKey
Flag to change the return value to an array containing the namespace parent and the namespace key
.requireModules(deps, cbFn)
method
Requires modules asynchronously Use this to get modules, even if they're not loaded yet
Accepts
deps
Array of module names. The order in which they are passed here will define the order they will be passed to the callback function.
cbFn
The callback function to be executed when all the dependencies are resolved. The dependencies are passed as arguments, in the same order they were declared.
Using Ink.requireModules() in a project is a good practice. All dependencies can be controlled, creating aliases to Inks modules making it more easy to use and all variables will keep in a private project scope instead of global scope.
Here's an example of a MyProject.js file.
Code
.s(selector, [from])
method
Selects elements like Ink.ss, but only returns the first element found.
Using sizzle-specific selectors is NOT encouraged!
Accepts
selector
CSS3 selector string
from
documentContext element. If set to a DOM element, the `selector` will only look for descendants of this DOM Element.
Code
.setPath(key, rootURI)
method
Sets the URL path for a namespace. Use this to customize where requireModules and createModule will load dependencies from. This can be useful to set your own CDN for dynamic module loading or simply to change your module folder structure
Accepts
key
Module or namespace
rootURI
Base URL path and schema to be appended to the module or namespace
Example
.ss(selector, [from])
method
Alias for Ink.Dom.Selector
Using sizzle-specific selectors is NOT encouraged!
Accepts
selector
CSS3 selector string
from
documentContext element. If set to a DOM element, the `selector` will only look for descendants of this DOM Element.
Code
.warn()
method
Calls native console.warn if available.
Accepts
more...
Arguments to be evaluated
Ink.warn() is an alias to console.warn() when it is available.