diff --git a/CHANGELOG.md b/CHANGELOG.md index 62cb5dd6..f9f88ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - file: honor server's `remote-root` option (remove root path from displayed path and returned value) - matrix: if `scroll` is `true`, children's values no longer feed the matrix' value and onValue script, it will be used for scrolling state, like with panels - menu: changed default `layout` to `vertical` + - root/panel/modal/tab: add `onScroll` script; value is no longer used for scrolling - scripting - user scripts are longer protected against infinite loop and the main window object may be reached (it's not supported to break out of scripting context, but resources are no longer wasted to prevent it) @@ -25,6 +26,7 @@ - dropped support for iOS 10.3 - scrollbars are no longer emulated iOS; in general now only the scrollbar color and width are set (using the standard css scrollbar-* properties) to be more in line with system scrollbars in general - macOS Catalina or abov is now required (the node package will work on older system) + - panels no longer use their value to set/get their scrolling state, not do they sync scrolling automatically. There's now a dedicated onScroll script that must be used instead, along with the setScroll and getScroll functions. ## 1.29.8 diff --git a/src/client/widgets/containers/modal.mjs b/src/client/widgets/containers/modal.mjs index 464e41d2..eb6261ad 100644 --- a/src/client/widgets/containers/modal.mjs +++ b/src/client/widgets/containers/modal.mjs @@ -162,6 +162,14 @@ class Modal extends Panel { this.setVisibility() if (this.value) { resize.check(this.widget, true) + + if (this.getProp('scroll')) { + setTimeout(()=>{ + this.scrollWidth = this.widget.scrollWidth - this.widget.clientWidth + this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight + this.setScroll(this.scroll[0], this.scroll[1], true) + }) + } } @@ -278,13 +286,6 @@ class Modal extends Panel { } - setScroll(x, y) { - - if (x !== undefined) this.popupContent.firstChild.scrollLeft = this.scroll[0] = x - if (y !== undefined) this.popupContent.firstChild.scrollTop = this.scroll[1] = y - - } - } Modal.cssVariables = Modal.prototype.constructor.cssVariables.concat( diff --git a/src/client/widgets/containers/panel.mjs b/src/client/widgets/containers/panel.mjs index 1d3659e2..57061a6a 100644 --- a/src/client/widgets/containers/panel.mjs +++ b/src/client/widgets/containers/panel.mjs @@ -46,7 +46,8 @@ class Panel extends Container() { tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'}, }, scripting: { - onTouch: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the session is touched and released, and when the pointer moves when the widget is touched. See documentation.',]}, + onTouch: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the panel is touched and released, and when the pointer moves when the widget is touched. See documentation.',]}, + onScroll: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the panel is scrolled. See documentation.',]}, } }) @@ -101,10 +102,15 @@ class Panel extends Container() { if (this.getProp('scroll')) { - if (this.props.type !== 'modal') { - this.value = [0, 0] - this.scrollTimeout = null + if (this.getProp('onScroll')) { + this.scripts.onScroll = new Script({ + widget: this, + property: 'onScroll', + code: this.getProp('onScroll'), + context: {event: {}, value: 0} + }) } + this.scroll = [0, 0] this.scrollWidth = 1 this.scrollHeight = 1 @@ -118,19 +124,20 @@ class Panel extends Container() { this.scrollWidth = this.widget.scrollWidth - this.widget.clientWidth this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight this.scroll = [this.widget.scrollLeft, this.widget.scrollTop] - var x = this.widget.scrollLeft / this.scrollWidth || 0, - y = this.widget.scrollTop / this.scrollHeight || 0 - if (this.props.type !== 'modal') { if (this.settingScroll) { clearTimeout(this.settingScrollEnd) this.settingScrollEnd = setTimeout(()=>{ this.settingScroll = false }) - } else { - this.setValue([x, y], {sync: true, send:true, fromScroll:true}) + } else if (this.scripts.onScroll) { + this.scripts.onScroll.run({ + value: this.value, + event: { + x: this.widget.scrollLeft / this.scrollWidth || 0, + y: this.widget.scrollTop / this.scrollHeight || 0 + } + }, {sync: true, send: true}) } - - } }, {element: this.widget}) } @@ -274,17 +281,8 @@ class Panel extends Container() { if (options.send) this.sendValue() if (options.sync) this.changed(options) - } else if (this.getProp('scroll') && this.childrenType !== 'tab' && Array.isArray(v) && v.length === 2 && this.props.type !== 'modal') { - - this.value = v - clearTimeout(this.scrollTimeout) - this.scrollTimeout = setTimeout(()=>{ - if (this.scroll) this.setScroll(v[0] * this.scrollWidth, v[1] * this.scrollHeight, !options.fromScroll) - }) - - if (options.send) this.sendValue() - if (options.sync) this.changed(options) } + } getScroll() { @@ -297,11 +295,11 @@ class Panel extends Container() { this.settingScroll = true if (x !== undefined) { this.scroll[0] = x - if (updateDom) this.widget.scrollLeft = x + if (updateDom) this.widget.scrollLeft = x * this.scrollWidth } if (y !== undefined) { this.scroll[1] = y - if (updateDom) this.widget.scrollTop = y + if (updateDom) this.widget.scrollTop = y * this.scrollHeight } } diff --git a/src/client/widgets/scripts/script-vm.mjs b/src/client/widgets/scripts/script-vm.mjs index c3d39d02..bf281f2f 100644 --- a/src/client/widgets/scripts/script-vm.mjs +++ b/src/client/widgets/scripts/script-vm.mjs @@ -273,7 +273,7 @@ class ScriptVm extends Vm { for (var i = widgets.length - 1; i >= 0; i--) { - if (widgets[i].getProp('scroll')) widgets[i].setScroll(x, y) + if (widgets[i].getProp('scroll')) widgets[i].setScroll(x, y, true) }