Scope
The properties and methods of a scope object.
On this page
API
property
scope.path
The absolute path of the scope.
scope.pathvar scope = $('span').last().scope();
console.log(scope.path); // users
property
scope.id
The unique generated identifier of the scope.
scope.idThe same value is available as ID.
var scope = $('span').last().scope();
console.log(scope.id === scope.ID); // true
property
scope.element
The element of the scope as a jQuery object.
scope.elementvar scope = $('span').last().scope();
console.log(scope.element.prop('tagName')); // UI-PLUGIN
property
scope.config
The parsed configuration of the element.
scope.configvar scope = $('span').last().scope();
console.log(scope.config.limit); // 10
property
scope.parent
The parent scope.
scope.parentThe property is undefined for a scope without a parent.
var scope = $('span').last().scope();
console.log(scope.parent.path); // users
property
scope.isolated
Tells whether the path ignores the parent scope.
scope.isolatedvar scope = $('span').last().scope();
console.log(scope.isolated); // false
property
scope.elements
The elements of the parent scopes and of this scope.
scope.elementsThe elements are DOM nodes, and the last one is the element of this scope.
var scope = $('span').last().scope();
console.log(scope.elements.length); // 2
property
scope.plugin
The Plugin connected to the scope.
scope.pluginvar scope = $('span').last().scope();
console.log(scope.plugin.name); // users
method
scope.makepath(path)
Resolves a path relative to the scope.
scope.makepath(path)| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
Returns String The resolved path.
? is the path of the scope, ?1 is the path of the parent scope and ?2 is the path two levels up. When that level does not exist, the path of the scope is used.
var scope = $('ui-plugin').scope();
console.log(scope.makepath('?.name')); // users.name
method
scope.get([path])
Reads a path relative to the scope.
scope.get([path])| Parameter | Type | Description |
|---|---|---|
path? |
String |
The relative path. |
Returns Object The value.
Without an argument, the method returns the whole model.
var scope = $('ui-plugin').scope();
console.log(scope.get('page')); // 1
method
scope.set(path, value, [timeout], [reset])
Writes a value to a path relative to the scope.
scope.set(path, value, [timeout], [reset])| Parameter | Type | Description |
|---|---|---|
path |
String |
The relative path. |
value |
Object |
The value. |
timeout? |
Number |
A value of 10 or more delays the change in milliseconds. A lower value is the type of the change. |
reset? |
Boolean |
true resets the state after a delayed change. |
var scope = $('ui-plugin').scope();
scope.set('page', 2);
console.log(GET('users.page')); // 2
method
scope.push(path, value, [timeout], [reset])
Adds an item to an array relative to the scope.
scope.push(path, value, [timeout], [reset])| Parameter | Type | Description |
|---|---|---|
path |
String |
The relative path. |
value |
Object |
The item. |
timeout? |
Number |
A value of 10 or more delays the change in milliseconds. A lower value is the type of the change. |
reset? |
Boolean |
true resets the state after a delayed change. |
var scope = $('ui-plugin').scope();
scope.push('items', 'A');
console.log(scope.get('items')); // ["A"]
method
scope.update([path], [timeout], [reset])
Notifies the listeners of a path relative to the scope.
scope.update([path], [timeout], [reset])| Parameter | Type | Description |
|---|---|---|
path? |
String |
The relative path. |
timeout? |
Number |
A value of 10 or more delays the change in milliseconds. A lower value is the type of the change. |
reset? |
Boolean |
true resets the state. |
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(value)); // 5
window.users.page = 5;
scope.update('page');
method
scope.change([path])
Marks components on a path as touched and modified.
scope.change([path])| Parameter | Type | Description |
|---|---|---|
path? |
String |
The relative path. |
var scope = $('ui-plugin').scope();
scope.change();
console.log(FIND('field').config.touched); // true
method
scope.reset([path])
Clears the state of components on a path.
scope.reset([path])| Parameter | Type | Description |
|---|---|---|
path? |
String |
The relative path. |
The touched and modified state is cleared. The value does not change.
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.modify('Peter');
scope.reset();
console.log(com.config.touched, com.config.modified); // false false
method
scope.default([path], [timeout])
Restores the default value of the scope.
scope.default([path], [timeout])| Parameter | Type | Description |
|---|---|---|
path? |
String |
The relative path. |
timeout? |
Number |
The delay in milliseconds. |
The default value comes from the default attribute of the element. A number as the first argument is a delay in milliseconds.
var scope = $('ui-plugin').scope();
scope.set('page', 5);
scope.default();
console.log(scope.get('page')); // 1
method
scope.can()
Tells whether the components in the scope can be saved.
scope.can()Returns Boolean The result.
The result is true when at least one component is touched and none is invalid. A scope without components returns true.
var scope = $('ui-plugin').scope();
FIND('field').modify('Peter');
console.log(scope.can()); // true
method
scope.errors()
Returns the touched and invalid components of the scope.
scope.errors()Returns Array The components.
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.validate = value => !!value;
com.bind('touched');
com.validate2();
console.log(scope.errors().length); // 1
method
scope.watch(path, callback, [init])
Watches a path relative to the scope.
scope.watch(path, callback, [init])| Parameter | Type | Description |
|---|---|---|
path |
String |
The relative path. |
callback |
Function |
The function that receives the changes. |
init? |
Boolean |
true calls the callback immediately. |
Returns Scope The scope.
The callback receives path, value and type, and this is the scope.
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(path, value)); // users.page 2
scope.set('page', 2);
method
scope.unwatch(path)
Removes the watchers of a path.
scope.unwatch(path)| Parameter | Type | Description |
|---|---|---|
path |
String |
The relative path. |
Returns Scope The scope.
The method removes all watchers that this scope has on the path.
var scope = $('ui-plugin').scope();
scope.watch('page', () => console.log('called'));
scope.unwatch('page');
scope.set('page', 2);
console.log('end'); // end
method
scope.apply()
Makes the scope active.
scope.apply()Returns Scope The scope.
Functions such as SET() then replace ? with the path of this scope.
var scope = $('ui-plugin').scope();
scope.apply();
SET('?.page', 3);
console.log(GET('users.page')); // 3
method
scope.FIND(selector, [many], [callback], [timeout])
Finds components inside the scope.
scope.FIND(selector, [many], [callback], [timeout])| Parameter | Type | Description |
|---|---|---|
selector |
String |
The selector of the component. |
many? |
Boolean |
true returns an array. |
callback? |
Function |
Waits for the component and receives it. |
timeout? |
Number |
The longest wait in milliseconds. |
Returns Component|Array The result.
The arguments are the same as in the jQuery FIND() extension.
var scope = $('ui-plugin').scope();
console.log(scope.FIND('field').name); // field
method
scope.SETTER(selector, method, [...args])
Calls a method of components inside the scope.
scope.SETTER(selector, method, [...args])| Parameter | Type | Description |
|---|---|---|
selector |
String |
The selector of the component. |
method |
String |
The name of the method. |
args? |
Object |
The arguments. |
var scope = $('ui-plugin').scope();
scope.SETTER('field/reconfigure', 'title:Orders');
console.log(FIND('field').config.title); // Orders
method
scope.RECONFIGURE(selector, value)
Reconfigures components inside the scope.
scope.RECONFIGURE(selector, value)| Parameter | Type | Description |
|---|---|---|
selector |
String |
The selector of the component. |
value |
String|Object |
The configuration. |
var scope = $('ui-plugin').scope();
scope.RECONFIGURE('field', 'title:Orders');
console.log(FIND('field').config.title); // Orders
method
scope.find(selector)
Finds nested elements.
scope.find(selector)| Parameter | Type | Description |
|---|---|---|
selector |
String|Object |
A selector or an object of selectors. |
Returns jQuery|Object The result.
An object of selectors returns an object of jQuery results with the same keys.
var scope = $('ui-plugin').scope();
console.log(scope.find('span').length); // 1
method
scope.closest(selector)
Finds the closest matching parent of the element.
scope.closest(selector)| Parameter | Type | Description |
|---|---|---|
selector |
String |
The selector. |
Returns jQuery The result.
var scope = $('ui-plugin').scope();
console.log(scope.closest('body').length); // 1
method
scope.append(value)
Adds content to the end of the element.
scope.append(value)| Parameter | Type | Description |
|---|---|---|
value |
String|Array |
The content. |
Returns jQuery The element.
An array is joined.
var scope = $('ui-plugin').scope();
scope.append('<b>A</b>');
console.log(scope.find('b').text()); // A
method
scope.event(name, [selector], callback)
Attaches a jQuery event to the element.
scope.event(name, [selector], callback)| Parameter | Type | Description |
|---|---|---|
name |
String |
The name of the event. |
selector? |
String |
The delegated selector. |
callback |
Function |
The handler. |
Returns Scope The scope.
The arguments are the same as in the jQuery on() method.
var scope = $('ui-plugin').scope();
scope.event('click', 'span', () => console.log('clicked')); // clicked
scope.find('span').click();
method
scope.attr(name, [value])
Reads or writes an attribute of the element.
scope.attr(name, [value])| Parameter | Type | Description |
|---|---|---|
name |
String |
The attribute. |
value? |
String |
The new value. |
Returns String|Scope The value, or the scope when value is passed.
var scope = $('ui-plugin').scope();
scope.attr('title', 'Users');
console.log(scope.attr('title')); // Users
method
scope.attrd(name, [value])
Reads or writes a data- attribute of the element.
scope.attrd(name, [value])| Parameter | Type | Description |
|---|---|---|
name |
String |
The name without the data- prefix. |
value? |
String |
The new value. |
Returns String|Scope The value, or the scope when value is passed.
var scope = $('ui-plugin').scope();
scope.attrd('id', '5');
console.log(scope.attr('data-id')); // 5
method
scope.attrd2(name)
Reads a data- attribute from the element or its closest parent that has it.
scope.attrd2(name)| Parameter | Type | Description |
|---|---|---|
name |
String |
The name without the data- prefix. |
Returns String The value.
var scope = $('ui-plugin').scope();
console.log(scope.attrd2('area')); // main
method
scope.css(name, [value])
Reads or writes a CSS property of the element.
scope.css(name, [value])| Parameter | Type | Description |
|---|---|---|
name |
String |
The property. |
value? |
String |
The new value. |
Returns String|Scope The value, or the scope when value is passed.
var scope = $('ui-plugin').scope();
scope.css('display', 'block');
console.log(scope.css('display')); // block
method
scope.autofocus([selector])
Moves the focus to the first visible field in the element.
scope.autofocus([selector])| Parameter | Type | Description |
|---|---|---|
selector? |
String |
The fields. Default: input,select,textarea |
Returns Scope The scope.
The method does nothing on mobile devices.
var scope = $('ui-plugin').scope();
scope.autofocus();
console.log(document.activeElement.tagName); // INPUT
method
scope.remove()
Removes the scope, its element and its components.
scope.remove()var scope = $('ui-plugin').scope();
scope.remove();
console.log($('ui-plugin').length); // 0