JAVASCRIPT
Auxiliar utilities for UI Modules
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Ink UI Base Class
You don't use this class directly, or inherit from it directly.
See createUIComponent() (in this module) for how to create a UI component and inherit from this. It's not plain old JS inheritance, for several reasons.
Method name | Description |
---|---|
new BaseUIComponent(element, [options]) | Constructor |
.createUIComponent(theConstructor, [options]) | Take a constructor, and make it an Ink UI component. |
.getElement() | Get the element associated with an UI component (IE the one you used in the constructor) |
.getOption(name) | Get an UI component's option's value. |
.getOption(name, value) | Sets an option's value. |
element
Element to associate this UI component with. It's the element you can get later using `comp.getElement()`options
Options to pass to the component. You should see your specific UI component for this information.Take a constructor, and make it an Ink UI component.
Makes it inherit BaseUIComponent, makes sure it has the basic properties Ink.UI.Common needs it to have, adds the necessary static methods, sets its options, etc.
theConstructor
UI component constructor. It should have an _init function in its prototype, an _optionDefinition object, and a _name property indicating its name.options
Options hash, containing:options.elementIsOptional
falseWhether the element argument is optional (For example, when the component might work on existing markup or create its own).Get the element associated with an UI component (IE the one you used in the constructor)
Example
Get an UI component's option's value.
name
The option's name.Example
Sets an option's value.
name
Name of the option.value
New option value.Example
Function name | Description |
---|---|
.ajaxJSON(endpoint, params, cb) | AJAX JSON request shortcut method |
.childIndex(childEl) | deprecated Gets an element's one-base index relative to its parent. |
.cleanChildren(parentEl) | Removes children nodes from a given object. |
.clone(o) | deprecated Deep copy (clone) an object. |
.currentLayout() | Gets the current Ink layout. |
.destroyComponent() | Boilerplate method to destroy a component. |
.elOrSelector(elOrSelector, fieldName) | Gets a DOM Element. |
.elsOrSelector(elsOrSelector, [fieldName], required) | Like elOrSelector but returns an array of elements. |
.getInstance(el, [UIComponent]) | Gets an UI component instance from an element. |
.getInstanceFromSelector(selector) | Gets an instance based on a selector. |
.getInstanceIds() | Gets all the instance ids |
.getInstances() | Gets all the instances |
.hashSet(o) | Sets the location's hash (window.location.hash). |
.isDOMElement(o) | Checks if an item is a valid DOM Element. |
.isInteger(n) | Checks if an item is a valid integer. |
.options([fieldId], defaults, overrides, [element]) | Gets options an object and element's metadata. |
.registerInstance(inst, el) | Saves an object (which should inherit BaseUIComponent) in the registry, associated with an element. You can retrieve it later by calling getInstance. |
.restoreIdAndClasses(toEl, inObj) | Sets the id and className properties of an element based |
.storeIdAndClasses(fromEl, inObj) | Stores the id and/or classes of an element in an object. |
.unregisterInstance(inst) | Unregisters (removes from the registry) a UI component instance from whatever element it's on. |
Property name | Description |
---|---|
.Layouts | Supported Ink Layouts |
AJAX JSON request shortcut method
It provides a more convenient way to do an AJAX request and expect a JSON response.It also offers a callback option, as third parameter, for better async handling.
endpoint
Valid URL to be used as target by the request.params
This field is used in the thrown Exception to identify the parameter.cb
Callback for the request.Example
Gets an element's one-base index relative to its parent.
Deprecated. Use Ink.Dom.Element.parentIndexOf instead.
childEl
Valid DOM Element.Example
Removes children nodes from a given object.
This method was initially created to help solve a problem in Internet Explorer(s) that occurred when trying to set the innerHTML of some specific elements like 'table'.
parentEl
Valid DOM ElementExample
Deep copy (clone) an object.
Note: The object cannot have referece loops.
o
The object to be cloned/copied.Example
Gets the current Ink layout.
Example
Boilerplate method to destroy a component.
Components should copy this method as its destroy method and modify it.
Gets a DOM Element.
elOrSelector
DOM Element or CSS SelectorfieldName
The name of the field. Commonly used for debugging.Example
Like elOrSelector
but returns an array of elements.
elsOrSelector
DOM Element, array of DOM Elements, or CSS SelectorfieldName
The name of the field. Used for the error shown when no elements are found.required
If this is true, throw an error instead of returning an empty array.Example
Gets an UI component instance from an element.
This function is already available in the UI components' classes themselves. You can call Modal.getInstance() and retrieve a modal.
el
Element from which we want the instances. A selector is okay.UIComponent
If you pass an Ink UI component class (Like Ink.UI.Modal or Ink.UI.Carousel), this won't return an array of all instances associated with the element. Instead it will return only the object which is an instance of that class.Gets an instance based on a selector.
selector
CSS selector to get the instances from. This function will only use the *first* element.Gets all the instance ids
Gets all the instances
Sets the location's hash (window.location.hash).
o
Object with the info to be placed in the location's hash.Example
Checks if an item is a valid DOM Element.
o
The object to be checked.Example
Checks if an item is a valid integer.
n
The value to be checked.Example
Gets options an object and element's metadata.
The element's data attributes take precedence. Values from the element's data-atrributes are coerced into the required type.
fieldId
Name to be used in error reports.defaults
Object with the options' types and defaults.overrides
Options to override the defaults. Usually passed when instantiating an UI module.element
Element with data-attributesExample
Saves an object (which should inherit BaseUIComponent) in the registry, associated with an element. You can retrieve it later by calling getInstance.
This won't allow two instances of the same class to be created on a single element. It will fail and print a warning to the console if you try to do it. That is a common error when using Ink.
inst
Object that holds the instance.el
Element to associate with `inst`.Sets the id and className properties of an element based
toEl
Valid DOM Element to set the id and classes on.inObj
Object where the id and classes to be set are. This method uses the same format as the one given in `storeIdAndClasses`Example
Stores the id and/or classes of an element in an object.
fromEl
Valid DOM Element to get the id and classes from.inObj
Object where the id and classes will be saved.Example
Unregisters (removes from the registry) a UI component instance from whatever element it's on.
inst
Instance to be unregistered.Object
Supported Ink Layouts