From ced7250d98310d0c6fc28325087fe6905024a0f2 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 19 Mar 2019 11:35:47 +0100 Subject: [PATCH] switch: add `traversing` option (`true` by default) (#491) --- CHANGELOG.md | 4 +++- src/client/app/widgets/buttons/switch.js | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b69b85a..d01d81d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ - launcher - added context menu action to display midi device list without starting the server - +- widgets + - switch: add `traversing` option (`true` by default) + ## 0.42.0 - widgets diff --git a/src/client/app/widgets/buttons/switch.js b/src/client/app/widgets/buttons/switch.js index 80bf6af3..86d8d32e 100644 --- a/src/client/app/widgets/buttons/switch.js +++ b/src/client/app/widgets/buttons/switch.js @@ -16,7 +16,8 @@ module.exports = class Switch extends Widget { values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [ '`Array` of possible values to switch between : `[1,2,3]`', '`Object` of `"label":value` pairs. Numeric labels must be prepended or appended with a white space (or any other non-numeric character) otherwise the order of the values won\'t be kept', - ]} + ]}, + traversing: {type: 'boolean', value: true, help: 'Set to `false` to disable traversing gestures'}, }) @@ -61,11 +62,13 @@ module.exports = class Switch extends Widget { this.value = undefined - this.on('draginit', (e)=>{ + var dragCallback = (e)=>{ var index = 0, node = e.target + if (node === this.widget || !this.widget.contains(node)) return + while ( (node = node.previousSibling) ) { if (node.nodeType != 3) { index++ @@ -76,7 +79,10 @@ module.exports = class Switch extends Widget { if (value!=this.value || this.value===undefined) this.setValue(value,{sync:true,send:true}) - }, {element: this.widget}) + } + + this.on('draginit', dragCallback , {element: this.widget}) + if (this.getProp('traversing') this.on('drag', dragCallback , {element: this.widget}) }