events: 🎆 migrate from jquery custom events to non-dom event emitter ("change" event ok)

This commit is contained in:
jean-emmanuel 2018-01-10 20:03:29 +01:00
parent 50e6ae37c0
commit a0040ab488
35 changed files with 172 additions and 126 deletions

View file

@ -0,0 +1,17 @@
var WolfyEventEmitter = require('wolfy87-eventemitter')
module.exports = class EventEmitter extends WolfyEventEmitter {
emitEvent(evt, args) {
super.emitEvent(evt, args)
if (args[0] && !args[0].stopPropagation) {
if (this.parent) this.parent.emitEvent(evt, args)
}
return this
}
}

View file

@ -1,9 +1,12 @@
var ipc = require('../ipc/')
var EventEmitter = require('../event-emitter'),
ipc = require('../ipc/')
var WidgetManager = class WidgetManager {
var WidgetManager = class WidgetManager extends EventEmitter {
constructor() {
super()
this.widgets = {}
this.addressRoute = {}
@ -14,37 +17,7 @@ var WidgetManager = class WidgetManager {
this.preArgsSeparator = '||||'
$(document).ready(()=>{
$('body').off('change.global').on('change.global',(e)=>{
var {id, widget, linkId, fromExternal, options} = e,
widgetsById = this.getWidgetById(id),
widgetsByLinkId = this.getWidgetByLinkId(linkId)
// Widget that share the same id will update each other
// without sending any extra osc message
if (widgetsById.length>1) {
var v = widget.getValue()
for (let i in widgetsById) {
if (widgetsById[i].hash != widget.hash && widgetsById[i].setValue) {
widgetsById[i].setValue(v,{send:false,sync:false})
}
}
}
// widgets that share the same linkId will update each other.
// Updated widgets will send osc messages normally
if (widgetsByLinkId.length>1) {
var v = widget.getValue()
for (let i in widgetsByLinkId) {
if (widgetsByLinkId[i].hash != widget.hash && widgetsByLinkId[i].setValue) {
widgetsByLinkId[i].setValue(v,{send:options.send,sync:false})
}
}
}
})
})
this.on('change', this.onChange, this)
ipc.on('reconnect', ()=>{
for (var hash in this.widgets) {
@ -63,6 +36,36 @@ var WidgetManager = class WidgetManager {
}
onChange(e) {
var {id, widget, linkId, options} = e,
widgetsById = this.getWidgetById(id),
widgetsByLinkId = linkId ? this.getWidgetByLinkId(linkId) : []
// Widget that share the same id will update each other
// without sending any extra osc message
if (widgetsById.length>1) {
var v = widget.getValue()
for (let i in widgetsById) {
if (widgetsById[i].hash != widget.hash && widgetsById[i].setValue) {
widgetsById[i].setValue(v,{send:false,sync:false})
}
}
}
// widgets that share the same linkId will update each other.
// Updated widgets will send osc messages normally
if (widgetsByLinkId.length>1) {
var v = widget.getValue()
for (let i in widgetsByLinkId) {
if (widgetsByLinkId[i].hash != widget.hash && widgetsByLinkId[i].setValue) {
widgetsByLinkId[i].setValue(v,{send:options.send,sync:false})
}
}
}
}
createAddressRef(widget, preArgs, address) {
var preArgs = preArgs || widget.getProp('preArgs'),
address = address || widget.getProp('address')

View file

@ -71,12 +71,12 @@ module.exports = class Dropdown extends _widgets_base {
this.value = this.values[i]
if (!options.fromLocal) this.select[0].selectedIndex = i
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options})
if (options.sync) this.changed(options)
this.container.removeClass('noselect')
} else {
this.value = undefined
this.select[0].selectedIndex = -1
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options})
if (options.sync) this.changed(options)
this.container.addClass('noselect')
}

View file

@ -91,14 +91,14 @@ module.exports = class Push extends _widgets_base {
this.lastChanged = 'active'
this.updateValue()
if (options.send) this.sendValue(v)
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
} else if (v===this.getProp('off') || (this.getProp('off') != null && v === this.getProp('off').value && v !== undefined)) {
this.widget.removeClass('active')
this.active = 0
this.lastChanged = 'active'
this.updateValue()
if (options.send) this.sendValue(v, this.getProp('norelease'))
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}
}

View file

@ -91,11 +91,11 @@ module.exports = class Switch extends _widgets_base {
this.widget.find('.on').removeClass('on')
this.widget.find('.value').eq(i).addClass('on')
if (options.send) this.sendValue(this.value)
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options})
if (options.sync) this.changed(options)
} else {
this.widget.find('.on').removeClass('on')
this.value = undefined
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options})
if (options.sync) this.changed(options)
}
}}

View file

@ -102,7 +102,7 @@ module.exports = class Toggle extends _widgets_base {
if (options.send) this.sendValue()
}
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options})
if (options.sync) this.changed(options)
}

View file

@ -1,10 +1,11 @@
var osc = require('../../osc'),
var EventEmitter = require('../../event-emitter'),
osc = require('../../osc'),
shortid = require('shortid'),
widgetManager = require('../../managers/widgets'),
updateDom = function(){ updateDom = require('../../editor/data-workers').updateDom; updateDom(...arguments)}
module.exports = class _widgets_base {
module.exports = class _widgets_base extends EventEmitter {
static defaults() {
@ -19,6 +20,8 @@ module.exports = class _widgets_base {
constructor(options={}) {
super()
this.container = options.container
this.widget = $(options.html)
this.props = options.props
@ -40,7 +43,7 @@ module.exports = class _widgets_base {
}
// strip parent ? no position
if (this.parent && this.parent.props.type == 'strip') {
if (this.parent && this.parent.props && this.parent.props.type == 'strip') {
delete this.props.top
delete this.props.left
delete this.props[this.parent.getProp('horizontal') ? 'height' : 'width']
@ -75,7 +78,7 @@ module.exports = class _widgets_base {
if (Object.keys(this.linkedPropsValue).length) {
$('body').on(`change.${this.hash}`, (e)=>{
widgetManager.on(`change.${this.hash}`, (e)=>{
var {id} = e
if (this.linkedPropsValue[id] && id != this.getProp('id')) {
this.checkPropsChanged(this.linkedPropsValue[id], e.options.send)
@ -97,6 +100,17 @@ module.exports = class _widgets_base {
}
changed(options) {
this.trigger(/change(\..*)?/, [{
widget: this,
options: options,
id: this.getProp('id'),
linkId: this.getProp('linkId')
}])
}
sendValue(overrides) {
var data = {
@ -266,7 +280,7 @@ module.exports = class _widgets_base {
onRemove(){
$('body').off(`widget-created.${this.hash}`)
.off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
}
}

View file

@ -128,7 +128,7 @@ module.exports = class Modal extends Panel {
if (!this.init && this.value) this.init = true
if (options.send) this.sendValue()
if (options.sync) this.light.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options})
if (options.sync) this.changed(options)
}

View file

@ -197,7 +197,7 @@ module.exports = class Panel extends _widgets_base {
this.navigation.find('li').removeClass('on').eq(v).addClass('on')
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options})
if (options.sync) this.changed(options)
}
}

View file

@ -1,6 +1,7 @@
var Panel = require('./panel'),
{iconify} = require('../../utils'),
Tab = require('./tab')
Tab = require('./tab'),
widgetManager = require('../../managers/widgets')
@ -45,6 +46,7 @@ module.exports = class Root extends Panel {
super(options)
this.parent = widgetManager
this.widget.addClass('root')
this.widget.find('> .navigation').addClass('main')

View file

@ -52,10 +52,6 @@ module.exports = class Tab extends Panel {
var $body = $('body')
this.widget.on('change.detached', (e)=>{
if (this.detached) $body.trigger(e)
})
}
hide() {

View file

@ -71,7 +71,11 @@ module.exports = class Input extends _canvas_base {
}
if (this.getProp('widgetId').length) $('body').on(`change.${this.hash}`,this.syncHandle.bind(this))
if (this.getProp('widgetId').length) {
widgetManager.on(`change.${this.hash}`, this.syncHandle.bind(this))
}
}
@ -116,7 +120,7 @@ module.exports = class Input extends _canvas_base {
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}
@ -170,8 +174,8 @@ module.exports = class Input extends _canvas_base {
this.stringValue = this.getStringValue()
this.draw()
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.send && !options.fromSync) this.sendValue()
if (options.sync) this.changed(options)
}

View file

@ -91,7 +91,7 @@ module.exports = class Formula extends _widgets_base {
this.conditionState = true
$('body').on(`change.${this.hash}`,this.syncHandle.bind(this))
widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
this.updateValue({options:{}})
this.input.widget.on('change', (e)=>{
@ -102,7 +102,7 @@ module.exports = class Formula extends _widgets_base {
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}
@ -143,7 +143,7 @@ module.exports = class Formula extends _widgets_base {
var s = this.condition.eval(variables).valueOf()
if (Array.isArray(s) && s.length == 1) s = s[0]
this.conditionState = s.data !== undefined ? s.data : s
} catch(err) {
@ -165,6 +165,7 @@ module.exports = class Formula extends _widgets_base {
this.showValue()
if (e.options.sync && this.conditionState) this.widget.trigger({type: 'change',id: this.getProp('id'),widget: this, linkId: this.getProp('linkId'), options: e.options})
if (e.options.sync && this.conditionState) this.changed(e.options)
if (e.options.send && this.conditionState) this.sendValue()
} catch(err) {

View file

@ -10,11 +10,12 @@ module.exports = class _matrices_base extends _widgets_base {
this.start = parseInt(this.getProp('start'))
this.widget.on('change',(e)=>{
this.on('change',(e)=>{
if (e.id==this.getProp('id')) return
if (e.widget == this) return
this.value[e.widget.container.index()] = e.widget.getValue()
this.widget.trigger({type:'change',id:this.getProp('id'),widget:this,options:e.options})
this.changed(e.options)
})

View file

@ -66,7 +66,7 @@ module.exports = class Keyboard extends _matrices_base {
data.preArgs = this.getProp('split') ? this.getProp('preArgs') : [].concat(this.getProp('preArgs'), i)
data.css = ''
var element = parser.parse([data],this.widget)
var element = parser.parse([data], this.widget, this)
element[0].classList.add('not-editable')
if (pattern[i % 12] == 'w') {

View file

@ -87,7 +87,7 @@ module.exports = class Multifader extends _matrices_base {
data.color = typeof this.getProp('color') == 'object' ? '' + this.getProp('color')[i % this.getProp('color').length] : this.getProp('color')
data.css = ''
var element = parser.parse([data],this.widget)
var element = parser.parse([data], this.widget, this)
element[0].classList.add('not-editable')
if (this.getProp('traversing')) element.find('canvas').off('drag')

View file

@ -67,7 +67,7 @@ module.exports = class Multipush extends _matrices_base {
data.color = typeof this.getProp('color') == 'object' ? '' + this.getProp('color')[i % this.getProp('color').length] : this.getProp('color')
data.css = ''
var element = parser.parse([data],this.widget)
var element = parser.parse([data], this.widget, this)
element[0].classList.add('not-editable')
this.value[i-this.start] = this.getProp('off')

View file

@ -67,7 +67,7 @@ module.exports = class Multitoggle extends _matrices_base {
data.color = typeof this.getProp('color') == 'object' ? '' + this.getProp('color')[i % this.getProp('color').length] : this.getProp('color')
data.css = ''
var element = parser.parse([data],this.widget)
var element = parser.parse([data], this.widget, this)
element[0].classList.add('not-editable')
this.value[i-this.start] = this.getProp('off')

View file

@ -95,7 +95,7 @@ module.exports = class MultiXy extends _pads_base {
pointSize: this.getProp('pointSize'),
pips: this.getProp('pips') && i == this.npoints-1,
input:false
}})
}, parent: this})
this.pads[i].sendValue = ()=>{}
this.wrapper.append(this.pads[i].widget)
@ -151,8 +151,9 @@ module.exports = class MultiXy extends _pads_base {
})
this.wrapper.on('change',(e)=>{
e.stopPropagation()
this.on('change',(e)=>{
if (e.widget == this) return
e.stopPropagation = true
this.setValue(this.getValue(), e.options)
})
@ -234,7 +235,7 @@ module.exports = class MultiXy extends _pads_base {
}
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'change', id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}

View file

@ -94,17 +94,13 @@ module.exports = class Rgb extends _pads_base {
this.value = []
this.hsb = {h:0,s:0,b:0}
this.wrapper.on('change',(e)=>{
e.stopPropagation()
})
this.hue.widget.on('change',(e)=>{
e.stopPropagation()
this.hue.on('change',(e)=>{
e.stopPropagation = true
this.dragHandle(true)
})
this.wrapper.on('change',(e)=>{
e.stopPropagation()
this.pad.on('change',(e)=>{
e.stopPropagation = true
this.dragHandle()
})
@ -115,8 +111,8 @@ module.exports = class Rgb extends _pads_base {
parent:this, parentNode:this.widget
})
this.widget.append(this.input.widget)
this.input.widget.on('change', (e)=>{
e.stopPropagation()
this.input.on('change', (e)=>{
e.stopPropagation = true
this.setValue(this.input.getValue(), {sync:true, send:true})
this.showValue()
})
@ -167,7 +163,7 @@ module.exports = class Rgb extends _pads_base {
this.value = v
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'change', id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
this.update({dragged:options.dragged, nohue:options.nohue || (v[0]==v[1]&&v[1]==v[2])})

View file

@ -106,8 +106,12 @@ module.exports = class Xy extends _pads_base {
this.wrapper.append(this.faders.x.widget)
this.wrapper.append(this.faders.y.widget)
this.wrapper.on('change',(e)=>{
e.stopPropagation()
this.faders.x.on('change',(e)=>{
e.stopPropagation = true
})
this.faders.y.on('change',(e)=>{
e.stopPropagation = true
})
this.wrapper.on('draginit',(e, data, traversing)=>{
@ -140,8 +144,8 @@ module.exports = class Xy extends _pads_base {
parent:this, parentNode:this.widget
})
this.widget.append(this.input.widget)
this.input.widget.on('change', (e)=>{
e.stopPropagation()
this.input.on('change', (e)=>{
e.stopPropagation = true
this.setValue(this.input.getValue(), {sync:true, send:true})
this.showValue()
})
@ -181,7 +185,7 @@ module.exports = class Xy extends _pads_base {
]
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'change', id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
this.draw()

View file

@ -35,7 +35,7 @@ module.exports = class _plots_base extends _canvas_base {
$('body').on(`change.${this.hash}`,this.syncHandleProxy.bind(this))
widgetManager.on(`change.${this.hash}`, this.syncHandleProxy.bind(this), this)
}
@ -47,7 +47,7 @@ module.exports = class _plots_base extends _canvas_base {
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}
@ -155,7 +155,7 @@ module.exports = class _plots_base extends _canvas_base {
this.data = v
this.draw()
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}

View file

@ -81,7 +81,7 @@ module.exports = class Led extends _widgets_base {
this.widget[0].style.setProperty('background-image', `url(${this.value}${cache_query})`)
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}

View file

@ -48,7 +48,7 @@ module.exports = class Led extends _widgets_base {
super({...options, html: html})
if (this.getProp('widgetId').length) $('body').on(`change.${this.hash}`,this.syncHandle.bind(this))
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`, this.syncHandle.bind(this))
this.setValue(this.getProp('range').min)
@ -56,7 +56,7 @@ module.exports = class Led extends _widgets_base {
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}
@ -80,7 +80,7 @@ module.exports = class Led extends _widgets_base {
this.value = v
this.widget[0].style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}

View file

@ -57,14 +57,14 @@ module.exports = class Meter extends Fader {
this.canvas.off('draginit drag')
if (this.getProp('widgetId').length) $('body').on(`change.${this.hash}`,this.syncHandle.bind(this))
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
}
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}

View file

@ -46,7 +46,7 @@ module.exports = class Rbgled extends _widgets_base {
super({...options, html: html})
if (this.getProp('widgetId').length) $('body').on(`change.${this.hash}`,this.syncHandle.bind(this))
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
this.setValue([0,0,0,0])
@ -54,7 +54,7 @@ module.exports = class Rbgled extends _widgets_base {
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}
@ -103,7 +103,7 @@ module.exports = class Rbgled extends _widgets_base {
this.widget[0].style.setProperty('--color-led', c)
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}

View file

@ -51,7 +51,7 @@ module.exports = class Text extends _widgets_base {
this.value = this.defaultValue
if (this.getProp('widgetId').length) $('body').on(`change.${this.hash}`,this.syncHandle.bind(this))
if (this.getProp('widgetId').length) widgetManager.on(`change.${this.hash}`,this.syncHandle.bind(this))
this.setValue(this.value)
@ -59,7 +59,7 @@ module.exports = class Text extends _widgets_base {
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}
@ -83,7 +83,7 @@ module.exports = class Text extends _widgets_base {
this.value = v==null ? this.defaultValue : v
this.widget.html(iconify(String(this.value).replace(/\n/g,'<br/>')))
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}

View file

@ -125,7 +125,7 @@ module.exports = class Visualizer extends _plots_base {
this.value = v[v.length - 1]
this.startLoop()
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
} else if (typeof(v) == 'number'){
@ -133,7 +133,7 @@ module.exports = class Visualizer extends _plots_base {
this.value = v
this.startLoop()
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
}

View file

@ -81,8 +81,8 @@ module.exports = class _sliders_base extends _canvas_base {
})
this.widget.append(this.input.widget)
this.input.widget.on('change', (e)=>{
e.stopPropagation()
this.input.on('change', (e)=>{
e.stopPropagation = true
this.setValue(this.input.getValue(), {sync:true, send:true})
this.showValue()
})
@ -209,8 +209,8 @@ module.exports = class _sliders_base extends _canvas_base {
this.showValue()
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
}

View file

@ -107,8 +107,11 @@ module.exports = class Encoder extends _widgets_base {
this.previousValue = this.ticks/2
this.wrapper.on('change',(e)=>{
e.stopPropagation()
this.on('change',(e)=>{
if (e.widget == this) return
e.stopPropagation = true
var value = this.knob.getValue()
@ -202,7 +205,7 @@ module.exports = class Encoder extends _widgets_base {
}
if (options.sync && match) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync && match) this.changed(options)
if (options.send && match && !(!this.getProp('snap') && options.draginit)) this.sendValue()
if (options.dragged || options.draginit) this.updateDisplay(options.draginit)

View file

@ -274,13 +274,19 @@ module.exports = class Range extends _widgets_base {
this.wrapper.append(this.faders[0].widget)
this.wrapper.append(this.faders[1].widget)
this.wrapper.on('change',(e)=>{
e.stopPropagation()
this.on('change',(e)=>{
if (e.widget == this) return
e.stopPropagation = true
var v = [
this.faders[0].getValue(),
this.faders[1].getValue()
]
this.setValue(v, e.options)
})
this.handles = [
@ -350,8 +356,8 @@ module.exports = class Range extends _widgets_base {
parent:this, parentNode:this.widget,
})
this.widget.append(this.input.widget)
this.input.widget.on('change', (e)=>{
e.stopPropagation()
this.input.on('change', (e)=>{
e.stopPropagation = true
this.setValue(this.input.getValue(), {sync:true, send:true})
this.showValue()
})
@ -406,7 +412,7 @@ module.exports = class Range extends _widgets_base {
if (options.send) this.sendValue()
if (options.sync) this.widget.trigger({type:'change', id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
this.faders[1].draw()

View file

@ -19,7 +19,7 @@ module.exports = class _switchers_base extends _widgets_base {
}
$('body').on(`change.${this.hash}`,this.syncHandler.bind(this))
widgetManager.on(`change.${this.hash}`,this.syncHandler.bind(this))
}
@ -39,7 +39,7 @@ module.exports = class _switchers_base extends _widgets_base {
onRemove() {
$('body').off(`change.${this.hash}`)
widgetManager.off(`change.${this.hash}`)
super.onRemove()
}
@ -104,7 +104,7 @@ module.exports = class _switchers_base extends _widgets_base {
}
}
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
if (options.sync) this.changed(options)
if (options.send) this.sendValue()
}

View file

@ -33,9 +33,9 @@ module.exports = class Crossfader extends Switcher {
this.widget.append($('<div class="fader-container"></div>').append(this.fader.widget))
this.fader.widget.on('change', (e)=>{
this.fader.on('change', (e)=>{
e.stopPropagation()
e.stopPropagation = true
this.setValue(this.fader.getValue(), e.options)

View file

@ -59,15 +59,12 @@ module.exports = class Switcher extends _switchers_base {
this.widget.append(this.switch.widget)
this.switch.widget.on('change', (e)=>{
this.switch.on('change', (e)=>{
e.stopPropagation()
e.stopPropagation = true
e.options.fromSelf = true
var {widget, options} = e
options.fromSelf = true
this.setValue(this.switch.getValue(), options)
this.setValue(this.switch.getValue(), e.options)
})