MAIN
The main object of the library, with its state and its low-level methods.
On this page
MAIN is the main object of the library. M, Total and jComponent are other names for the same object. It holds the state of the library and low-level methods that work with any scope. For everyday code, use the global functions described with Paths.
API
class
MAIN.Binder
The class of data bindings.
MAIN.BinderSee ui-bind.
property
MAIN.binders
The active data bindings.
MAIN.bindersReturns Array The active data bindings.
See ui-bind.
property
MAIN.caller
The plugin that was last called through EXEC().
MAIN.callerReturns Plugin The plugin that was last called through EXEC().
<ui-plugin path="users"></ui-plugin>
<script>
PLUGIN('users', function(self) {
self.refresh = NOOP;
});
ON('ready', function() {
EXEC('users/refresh');
console.log(MAIN.caller.name); // users
});
</script>
method
MAIN.cl(name, [callback])
The same function as CL().
MAIN.cl(name, [callback])| Parameter | Type | Description |
|---|---|---|
name |
String |
The names of the code lists. |
callback? |
Function |
A function that runs when the lists are loaded. |
See CL().
class
MAIN.Component
The class of components.
MAIN.ComponentSee Component.
property
MAIN.components
The active component instances.
MAIN.componentsReturns Array The active component instances.
See Component.
<ui-component name="box"></ui-component>
<script>
COMPONENT('box', function(self) {});
ON('ready', function() {
console.log(MAIN.components.length); // 1
});
</script>
property
MAIN.data
The storage of plugins with a generated path.
MAIN.dataReturns Object The storage of plugins with a generated path.
See DEF.path.
property
MAIN.def
The same object as DEF.
MAIN.defReturns Object The same object as DEF.
See DEF.
console.log(MAIN.def === DEF); // true
method
MAIN.emit(name, [a], [b], [c], [d])
The same function as EMIT().
MAIN.emit(name, [a], [b], [c], [d])| Parameter | Type | Description |
|---|---|---|
name |
String |
The name of the event. |
a? |
Object |
The first argument. |
b? |
Object |
The second argument. |
c? |
Object |
The third argument. |
d? |
Object |
The fourth argument. |
See EMIT().
property
MAIN.events
The global event handlers, by event name.
MAIN.eventsReturns Object The global event handlers, by event name.
See Events.
method
MAIN.exec(name, [a], [b], [c], [d])
Runs the same logic as EXEC().
MAIN.exec(name, [a], [b], [c], [d])| Parameter | Type | Description |
|---|---|---|
name |
String |
The target of the call. |
a? |
Object |
The first argument. |
b? |
Object |
The second argument. |
c? |
Object |
The third argument. |
d? |
Object |
The fourth argument. |
See EXEC().
method
MAIN.find(scope, path, callback)
Finds the components of a path in a scope.
MAIN.find(scope, path, callback)| Parameter | Type | Description |
|---|---|---|
scope |
Object |
The scope, usually window. |
path |
String |
The path, optionally with flags. |
callback |
Function |
A function that receives the array of components. |
Flags in the path narrow the result: @visible, @touched, @modified, @required, @invalid, @disabled and @enabled.
<ui-component name="field" path="form.name"></ui-component>
<script>
COMPONENT('field', function(self) {});
ON('ready', function() {
MAIN.find(window, 'form', function(components) {
console.log(components.length); // 1
});
});
</script>
method
MAIN.flags(flags, [callback])
The same function as FLAGS().
MAIN.flags(flags, [callback])| Parameter | Type | Description |
|---|---|---|
flags |
String |
The flags. |
callback? |
Function |
A function that runs afterwards. |
See FLAGS().
method
MAIN.free()
The same function as FREE().
MAIN.free()See FREE().
method
MAIN.get(scope, path)
Reads a value from any object by a path.
MAIN.get(scope, path)| Parameter | Type | Description |
|---|---|---|
scope |
Object |
The object to read from. |
path |
String |
The path inside the object. |
Returns Object The value.
var data = { user: { name: 'Peter' } };
console.log(MAIN.get(data, 'user.name')); // Peter
property
MAIN.is20
Identifies the major version of the library.
MAIN.is20Returns Boolean Identifies the major version of the library.
The value is always true.
console.log(MAIN.is20); // true
property
MAIN.loaded
Becomes true when the persistent cache is loaded.
MAIN.loadedReturns Boolean Becomes true when the persistent cache is loaded.
method
MAIN.newbinder(element, path, config, [callback])
Creates a data binding on an element.
MAIN.newbinder(element, path, config, [callback])| Parameter | Type | Description |
|---|---|---|
element |
jQuery |
The element. |
path |
String |
The path. |
config |
String |
The binding commands. |
callback? |
Function |
A function that runs when the binding is created. |
See NEWUIBIND().
method
MAIN.newcomponent(element, name, path, config, [callback])
Creates a component on an element.
MAIN.newcomponent(element, name, path, config, [callback])| Parameter | Type | Description |
|---|---|---|
element |
jQuery |
The element. |
name |
String |
The name of the component. |
path |
String |
The path. |
config |
String |
The configuration. |
callback? |
Function |
A function that runs when the component is created. |
<div id="target"></div>
<script>
COMPONENT('box', function(self) {
self.make = function() {
console.log(self.path.path); // form.name
};
});
ON('ready', function() {
MAIN.newcomponent($('#target'), 'box', 'form.name', '');
});
</script>
method
MAIN.newimporter(element, path, config)
Imports content into an element.
MAIN.newimporter(element, path, config)| Parameter | Type | Description |
|---|---|---|
element |
jQuery |
The element. |
path |
String |
The address. |
config |
String |
The configuration of the import. |
It works like the ui-import element.
<div id="target"></div>
<script>
ON('ready', function() {
MAIN.newimporter($('#target'), '/parts/menu.html', '');
setTimeout(function() {
console.log($('#target').html()); // <b>Menu</b>
}, 400);
});
</script>
method
MAIN.newplugin(element, path, config, [callback])
Creates a plugin on an element.
MAIN.newplugin(element, path, config, [callback])| Parameter | Type | Description |
|---|---|---|
element |
jQuery |
The element. |
path |
String |
The name of the plugin. |
config? |
String |
The configuration. |
callback? |
Function |
A function that runs when the plugin is created. |
<div id="target"></div>
<script>
PLUGIN('users', function(self) {
self.make = function() {
console.log(self.name); // users
};
});
ON('ready', function() {
MAIN.newplugin($('#target'), 'users');
});
</script>
method
MAIN.notify(scope, path, [onlyflags])
Notifies the observers of a path in a scope.
MAIN.notify(scope, path, [onlyflags])| Parameter | Type | Description |
|---|---|---|
scope |
Object |
The scope, usually window. |
path |
String |
The path, optionally with flags. |
onlyflags? |
Boolean |
Limits the notification to the state of components. Default: false |
With onlyflags, components only refresh their state, and watchers do not run.
WATCH('total', function(value) {
console.log(value); // 5
});
window.total = 5;
MAIN.notify(window, 'total');
method
MAIN.off(name, [callback])
The same function as OFF().
MAIN.off(name, [callback])| Parameter | Type | Description |
|---|---|---|
name |
String |
The name of the event. |
callback? |
Function |
The handler to remove. |
See OFF().
method
MAIN.on(name, callback, [init])
The same function as ON().
MAIN.on(name, callback, [init])| Parameter | Type | Description |
|---|---|---|
name |
String |
The name of the event. |
callback |
Function |
The handler. |
init? |
Boolean |
Also calls the handler once. Default: false |
See ON().
method
MAIN.parse(type, value, [format])
Converts a value to a type.
MAIN.parse(type, value, [format])| Parameter | Type | Description |
|---|---|---|
type |
String |
The type. |
value |
Object |
The value. |
format? |
String |
The format of a date. |
Returns Object The converted value.
The types are number, currency, float, boolean, bool, date and datetime. Numbers follow DEF.thousandsseparator and DEF.decimalseparator, and dates use DEF.dateformat when format is not set. A value that cannot be converted returns null. Other types return the value as it is.
console.log(MAIN.parse('number', '1 200.5')); // 1200.5
console.log(MAIN.parse('boolean', 'yes')); // true
console.log(MAIN.parse('date', '2024-03-01') instanceof Date); // true
class
new MAIN.Path(path)
The class that parses paths.
new MAIN.Path(path)| Parameter | Type | Description |
|---|---|---|
path |
String |
The path, optionally with flags. |
See Path.
var path = new MAIN.Path('form.name @change');
console.log(path.path); // form.name
console.log(path.flags); // {"change":1}
class
MAIN.Plugin
The class of plugins.
MAIN.PluginSee Plugin.
property
MAIN.plugins
The same object as PLUGINS.
MAIN.pluginsReturns Object The same object as PLUGINS.
See PLUGINS.
method
MAIN.process(scope, value, target)
Delivers a value to a function or a path.
MAIN.process(scope, value, target)| Parameter | Type | Description |
|---|---|---|
scope |
Object |
The scope of a path. |
value |
Object |
The value. |
target |
Function|String |
A function or a path. |
A function receives the value. A path is written and notified in the scope.
MAIN.process(window, 5, 'stats.total');
console.log(GET('stats.total')); // 5
property
MAIN.ready
Becomes true when the library has started.
MAIN.readyReturns Boolean Becomes true when the library has started.
ON('ready', function() {
console.log(MAIN.ready); // true
});
method
MAIN.resize()
Measures the window again.
MAIN.resize()
property
MAIN.root
The window object, which is the scope of global paths.
MAIN.rootReturns Object The window object, which is the scope of global paths.
console.log(MAIN.root === window); // true
property
MAIN.scrollbars
The active custom scrollbars.
MAIN.scrollbarsReturns Array The active custom scrollbars.
See SCROLLBAR().
method
MAIN.seex(name, [a], [b], [c], [d])
Runs the same logic as SEEX().
MAIN.seex(name, [a], [b], [c], [d])| Parameter | Type | Description |
|---|---|---|
name |
String |
The target. |
a? |
Object |
The first argument. |
b? |
Object |
The second argument. |
c? |
Object |
The third argument. |
d? |
Object |
The fourth argument. |
See SEEX().
method
MAIN.set(scope, path, value)
Writes a value to any object by a path.
MAIN.set(scope, path, value)| Parameter | Type | Description |
|---|---|---|
scope |
Object |
The object to write to. |
path |
String |
The path inside the object. |
value |
Object |
The value. |
Missing objects along the path are created. Nothing is notified.
var data = {};
MAIN.set(data, 'user.name', 'Peter');
console.log(data); // {"user":{"name":"Peter"}}
method
MAIN.setter(element, name, [a], [b], [c], [d])
Runs SETTER() for the components inside an element.
MAIN.setter(element, name, [a], [b], [c], [d])| Parameter | Type | Description |
|---|---|---|
element |
jQuery|Plugin |
The element or the plugin that limits the search. |
name |
String |
The selector and the method. |
a? |
Object |
The first argument. |
b? |
Object |
The second argument. |
c? |
Object |
The third argument. |
d? |
Object |
The fourth argument. |
Use null for all components. See SETTER().
<div id="a"><ui-component name="box"></ui-component></div>
<div id="b"><ui-component name="box"></ui-component></div>
<script>
COMPONENT('box', function(self) {
self.mark = function() {
console.log(self.element.parent().attr('id')); // a
};
});
ON('ready', function() {
MAIN.setter($('#a'), 'box/mark');
});
</script>
property
MAIN.ua
The detected environment: os, browser and device.
MAIN.uaReturns Object The detected environment: os, browser and device.
The device is desktop, tablet, mobile or tv. The value is available from the ready event onward.
ON('ready', function() {
console.log(Object.keys(MAIN.ua)); // ["os","browser","device"]
});
method
MAIN.unwatch(path, [callback])
The same function as UNWATCH().
MAIN.unwatch(path, [callback])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
callback? |
Function |
The watcher to remove. |
See UNWATCH().
property
MAIN.version
The version of the library.
MAIN.versionReturns Number The version of the library.
console.log(MAIN.version); // 20.015
method
MAIN.watch(path, callback, [init])
The same function as WATCH().
MAIN.watch(path, callback, [init])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
callback |
Function |
The watcher. |
init? |
Boolean |
Also calls the watcher once. Default: false |
See WATCH().
property
MAIN.watchers
The watchers registered with WATCH().
MAIN.watchersReturns Array The watchers registered with WATCH().
See WATCH().