scrollbar: fix locking mechanism
This commit is contained in:
parent
b53af33b09
commit
4c754bfaf4
5 changed files with 45 additions and 27 deletions
|
|
@ -152,6 +152,8 @@ class Modal extends Panel {
|
|||
this.updatePopupLabel()
|
||||
}
|
||||
|
||||
if (this.getProp('scroll') && this.value) this.scrollLock = true
|
||||
|
||||
this.popup.classList.toggle('show', this.value)
|
||||
this.container.classList.toggle('on', this.value)
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,12 @@ class Panel extends Container() {
|
|||
gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns or a valid value for the css property "grid-template".'},
|
||||
contain: {type: 'boolean', value: true, help:'If `layout` is `vertical` or `horizontal`, prevents children from overflowing the panel.'},
|
||||
scroll: {type: 'boolean|string', value: true, choices: [true, false, 'hidden'], help: 'Set to `false` to disable scrollbars, set to `hidden` to hide scrollbars while allowing to scroll (may not work on old browsers).'},
|
||||
scroll: {type: 'boolean|string', value: true, choices: [true, false, 'hidden', 'manual'], help: [
|
||||
'- `true`: scrollbars are show and content is scrollble',
|
||||
'- `false`: scrollbars are hidden and content is not scrollble',
|
||||
'- `"hidden"`: scrollbars are hidden (using css, may not work on old browsers) and content is scrollble',
|
||||
'- `"manual"`: scrollbars are hidden (using css, may not work on old browsers) and content is scrollble only using scripting or scrollbar widgets',
|
||||
]},
|
||||
innerPadding: {type : 'boolean', value: true, help: 'Set to `false` to make the `padding` property apply only between children and not at the container\'s inner boundaries.'},
|
||||
tabsPosition: {type: 'string', value: 'top', choices: ['top', 'bottom', 'left', 'right', 'hidden'], help: 'Defines the position of the navigation bar if the panel contains tabs'},
|
||||
},
|
||||
|
|
@ -47,7 +53,6 @@ class Panel extends Container() {
|
|||
},
|
||||
scripting: {
|
||||
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 <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]},
|
||||
// onScroll: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the panel is scrolled. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]},
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -71,7 +76,7 @@ class Panel extends Container() {
|
|||
}
|
||||
|
||||
this.container.classList.toggle('no-inner-padding', !this.getProp('innerPadding'))
|
||||
this.container.classList.toggle('no-scroll', !this.getProp('scroll'))
|
||||
this.container.classList.toggle('no-scroll', !this.getProp('scroll') || this.getProp('scroll') == 'manual')
|
||||
this.container.classList.toggle('hidden-scroll', this.getProp('scroll') == 'hidden')
|
||||
this.container.classList.add('layout-' + this.getProp('layout'))
|
||||
this.container.classList.toggle('layout-contain', this.getProp('contain'))
|
||||
|
|
@ -102,6 +107,8 @@ class Panel extends Container() {
|
|||
this.container.classList.add('contains-widgets')
|
||||
|
||||
if (this.getProp('scroll')) {
|
||||
this.scrollLock = false
|
||||
this.scrollLockTimeout = null
|
||||
this.scroll = [0, 0]
|
||||
this.scrollThumb = [1, 1]
|
||||
this.scrollWidth = 1
|
||||
|
|
@ -111,7 +118,8 @@ class Panel extends Container() {
|
|||
this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight
|
||||
this.scrollThumb = [this.widget.clientWidth / this.widget.scrollWidth || 1, this.widget.clientHeight / this.widget.scrollHeight || 1]
|
||||
})
|
||||
this.on('scroll', ()=>{
|
||||
this.on('scroll', (e)=>{
|
||||
if (this.scrollLock) e.locked = true
|
||||
this.scrollWidth = this.widget.scrollWidth - this.widget.clientWidth
|
||||
this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight
|
||||
this.scroll = [this.widget.scrollLeft / this.scrollWidth || 0, this.widget.scrollTop / this.scrollHeight || 0]
|
||||
|
|
@ -269,15 +277,34 @@ class Panel extends Container() {
|
|||
|
||||
}
|
||||
|
||||
setScroll(x, y, updateDom) {
|
||||
setScroll(x, y, updateDom, lock=true) {
|
||||
|
||||
if (x !== undefined) {
|
||||
this.scroll[0] = x
|
||||
if (updateDom) this.widget.scrollLeft = x * this.scrollWidth
|
||||
if (updateDom) {
|
||||
if (this.widget.scrollLeft != x * this.scrollWidth) {
|
||||
this.scrollLock = !!lock
|
||||
this.widget.scrollLeft = x * this.scrollWidth
|
||||
}
|
||||
}
|
||||
}
|
||||
if (y !== undefined) {
|
||||
this.scroll[1] = y
|
||||
if (updateDom) this.widget.scrollTop = y * this.scrollHeight
|
||||
if (updateDom) {
|
||||
if (this.widget.scrollTop != y * this.scrollHeight) {
|
||||
this.scrollLock = !!lock
|
||||
this.widget.scrollTop = y * this.scrollHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unlock scroll events only after some time to prevent smooth scrolling
|
||||
// issues in firefox and prevent feedback loops
|
||||
if (this.scrollLock) {
|
||||
clearTimeout(this.scrollLockTimeout)
|
||||
this.scrollLockTimeout = setTimeout(()=>{
|
||||
this.scrollLock = false
|
||||
},100)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, true)
|
||||
if (widgets[i].getProp('scroll')) widgets[i].setScroll(x, y, true, false)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ export default class Scrollbar extends StaticProperties(Fader, {
|
|||
|
||||
this.scrollTarget = null
|
||||
this.thumbSize = 1
|
||||
this.lock = false
|
||||
|
||||
if (!this.getProp('horizontal')) {
|
||||
this.rangeVals[0] = 1
|
||||
|
|
@ -134,8 +133,6 @@ export default class Scrollbar extends StaticProperties(Fader, {
|
|||
this.scrollTarget.off(undefined, undefined, this)
|
||||
|
||||
this.scrollTarget = null
|
||||
|
||||
this.lock = false
|
||||
}
|
||||
|
||||
bindTarget(target) {
|
||||
|
|
@ -149,26 +146,23 @@ export default class Scrollbar extends StaticProperties(Fader, {
|
|||
this.unbindTarget()
|
||||
}
|
||||
}, {context: this})
|
||||
|
||||
var onScroll = (e, init)=>{
|
||||
if (!this.scrollTarget) return
|
||||
|
||||
if (this.lock) {
|
||||
this.lock = false
|
||||
return
|
||||
}
|
||||
if (!this.scrollTarget || e.locked) return
|
||||
|
||||
var index = this.getProp('horizontal') ? 0 : 1,
|
||||
size = this.getProp('horizontal') ? this.width : this.height
|
||||
|
||||
this.thumbSize = this.scrollTarget.scrollThumb[index]
|
||||
this.cssVars.knobSize = Math.max(this.thumbSize * size, 30)
|
||||
this.setValue(this.scrollTarget.scroll[index], {fromPanel:true, send:!init, sync:!init})
|
||||
if (this.scrollTarget.scroll[index] != this.value) {
|
||||
this.setValue(this.scrollTarget.scroll[index], {fromScrollEvent:true, send:!init, sync:!init})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.scrollTarget.on('scroll', onScroll)
|
||||
fastdom.measure(()=>{
|
||||
this.scrollTarget.on('scroll', onScroll)
|
||||
onScroll({}, true)
|
||||
})
|
||||
|
||||
|
|
@ -178,18 +172,12 @@ export default class Scrollbar extends StaticProperties(Fader, {
|
|||
|
||||
super.setValue(v, options)
|
||||
|
||||
if (!options.fromPanel && this.scrollTarget) {
|
||||
if (!options.fromScrollEvent && this.scrollTarget) {
|
||||
var scroll = this.scrollTarget.getScroll()
|
||||
if (this.getProp('horizontal')) {
|
||||
if (scroll[0] != this.value) {
|
||||
this.lock = true
|
||||
this.scrollTarget.setScroll(this.value, undefined, true)
|
||||
}
|
||||
this.scrollTarget.setScroll(this.value, undefined, true)
|
||||
} else {
|
||||
if (scroll[1] != this.value) {
|
||||
this.lock = true
|
||||
this.scrollTarget.setScroll(undefined, this.value, true)
|
||||
}
|
||||
this.scrollTarget.setScroll(undefined, this.value, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
> inner {
|
||||
overflow: auto;
|
||||
scroll-behavior: auto!important; // smooth mode breaks scrollbar widget
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue