script: add getIndex function
This commit is contained in:
parent
beea543d96
commit
42f316cf81
3 changed files with 19 additions and 1 deletions
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
## 1.6.1
|
||||
|
||||
- bug fixes
|
||||
- keyboard: prevent `script` property from being copied to each key
|
||||
|
||||
- widgets
|
||||
- keyboard: make `on` and `off` properties dynamic
|
||||
- script: add `getIndex` function
|
||||
|
||||
## 1.6.0
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,13 @@ Returns the property called `"name"` of the first matching widget.
|
|||
|
||||
----
|
||||
|
||||
#### `getIndex(id)`
|
||||
- `id` (optional): widget `id` as a string. Defaults to `"this"`.
|
||||
|
||||
Returns the widget's index in its container.
|
||||
|
||||
----
|
||||
|
||||
#### `updateProp(id, name)`
|
||||
- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget.
|
||||
- `name`: property name.
|
||||
|
|
|
|||
|
|
@ -162,6 +162,13 @@ class ScriptVm extends Vm {
|
|||
|
||||
}
|
||||
|
||||
this.sandbox.contentWindow.getIndex = (id = 'this')=>{
|
||||
|
||||
var widget = this.resolveId(id).pop()
|
||||
if (widget) return widget.parent.children.indexOf(widget)
|
||||
|
||||
}
|
||||
|
||||
this.sandbox.contentWindow.getScroll = (id)=>{
|
||||
|
||||
var widgets = this.resolveId(id)
|
||||
|
|
@ -346,7 +353,7 @@ class ScriptVm extends Vm {
|
|||
|
||||
}
|
||||
|
||||
for (var imports of ['set', 'get', 'getProp', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
|
||||
for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
|
||||
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) {
|
||||
this.sanitize(this.sandbox.contentWindow[imports])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue