script: add getScroll and setScroll

This commit is contained in:
bordun 2020-07-02 12:17:40 +02:00
parent 8692896c3a
commit 27d2613ddd
2 changed files with 29 additions and 3 deletions

View file

@ -223,8 +223,8 @@ class Panel extends Container() {
if (!s) {
return [this.widget.scrollLeft, this.widget.scrollTop]
} else {
this.widget.scrollLeft = s[0]
this.widget.scrollTop = s[1]
if (s[0] !== undefined) this.widget.scrollLeft = s[0]
if (s[1] !== undefined) this.widget.scrollTop = s[1]
}
}

View file

@ -147,6 +147,32 @@ class ScriptVm extends Vm {
}
this.sandbox.contentWindow.getScroll = (id)=>{
var widgets = this.resolveId(id)
for (var i = widgets.length - 1; i >= 0; i--) {
if (widgets[i].scroll) return widgets[i].scroll()
}
return []
}
this.sandbox.contentWindow.setScroll = (id, x, y)=>{
var widgets = this.resolveId(id)
for (var i = widgets.length - 1; i >= 0; i--) {
if (widgets[i].scroll) widgets[i].scroll([x, y])
}
}
this.sandbox.contentWindow.httpGet = (url, callback)=>{
var parser = urlParser(url),
@ -286,7 +312,7 @@ class ScriptVm extends Vm {
}
for (var imports of ['set', 'get', 'getProp', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus']) {
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus', 'setScroll', 'getScroll']) {
this.sanitize(this.sandbox.contentWindow[imports])
}