diff --git a/CHANGELOG.md b/CHANGELOG.md index af29d6ca..3566ac9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - scripting - add `uploadFile` function for reading client-side files + - add `scrollIntoView` function ## 1.30.2 diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 64921dea..090bd3a0 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -328,10 +328,6 @@ Gives focus to a widget (ie input widget). If `id` is omitted or falsy, currentl Returns the scroll position of a container as a `[x, y]` array. -**Deprecated** - -Scrollable panels expose their scroll position normalized between 0 and 1 with their value. - ---- #### `setScroll(id, x, y)` @@ -341,9 +337,14 @@ Scrollable panels expose their scroll position normalized between 0 and 1 with t Sets the scroll state of a container. -**Deprecated** +---- + +#### `scrollIntoView(id, option)` +- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. +- `option`: `alignToTop` or `options` argument as defined in https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView + +Scroll containers to make widget(s) visible. -Scrollable panels expose their scroll position normalized between 0 and 1 with their value. ---- diff --git a/src/client/widgets/scripts/script-vm.mjs b/src/client/widgets/scripts/script-vm.mjs index ac8ce537..e1781c58 100644 --- a/src/client/widgets/scripts/script-vm.mjs +++ b/src/client/widgets/scripts/script-vm.mjs @@ -279,6 +279,24 @@ class ScriptVm extends Vm { } + this.globals.scrollIntoView = (id, options)=>{ + + this.checkContext('setScroll') + + var widgets = this.resolveId(id) + + for (var i = widgets.length - 1; i >= 0; i--) { + + if (widgets[i].container && widgets[i].isVisible()) { + widgets[i].container.scrollIntoView(options) + } + + } + + } + + + this.globals.httpGet = (url, callback)=>{ this.checkContext('httpGet')