widgets: use a single options object to pass extra params to widgets' setValue method

This commit is contained in:
jean-emmanuel 2016-10-02 18:56:38 +02:00
parent 034cfba05f
commit c34d2e93c1
9 changed files with 36 additions and 36 deletions

View file

@ -63,7 +63,7 @@ module.exports = {
if (WIDGETS[data[0]]!=undefined) {
for (var i=WIDGETS[data[0]].length-1;i>=0;i--) {
if (WIDGETS[data[0]][i].setValue) {
WIDGETS[data[0]][i].setValue(data[1],send,true)
WIDGETS[data[0]][i].setValue(data[1],{send:send,sync:true})
}
}
}

View file

@ -37,7 +37,7 @@ module.exports = {
// compare arrays using > and < operators (both false = equality)
if (!target || !(WIDGETS_BY_PATH[pathref][i].target < target || WIDGETS_BY_PATH[pathref][i].target > target)) {
// update matching widgets
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,false,true)
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,{send:false,sync:true})
}
}

View file

@ -63,7 +63,7 @@ module.exports.sync = function() {
var v = widget.getValue()
for (i in WIDGETS[id]) {
if (!WIDGETS[id][i].is(widget) && WIDGETS[id][i].setValue) {
WIDGETS[id][i].setValue(v,false,false)
WIDGETS[id][i].setValue(v)
}
}
}
@ -73,7 +73,7 @@ module.exports.sync = function() {
var v = widget.getValue()
for (i in WIDGETS_LINKED[linkId]) {
if (!WIDGETS_LINKED[linkId][i].is(widget) && WIDGETS_LINKED[linkId][i].setValue) {
WIDGETS_LINKED[linkId][i].setValue(v,true,false)
WIDGETS_LINKED[linkId][i].setValue(v,{send:true,sync:true})
}
}
}

View file

@ -76,19 +76,19 @@ module.exports.create = function(widgetData,container) {
}
}
widget.setValue = function(v,send,sync) {
widget.setValue = function(v,options={}) {
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
widget.addClass('on')
widget.state = 1
if (send) widget.sendValue(v)
if (options.send) widget.sendValue(v)
widget.lastChanged = 'state'
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
widget.removeClass('on')
widget.state = 0
if (send) widget.sendValue(v)
if (options.send) widget.sendValue(v)
widget.lastChanged = 'state'
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
}
}

View file

@ -196,7 +196,7 @@ module.exports.create = function(widgetData,container) {
rgb = hsbToRgb({h:h,s:s,b:l})
return [rgb.r,rgb.g,rgb.b]
}
widget.setValue = function(v,send,sync) {
widget.setValue = function(v,options={}) {
if (!v || v.length!=3) return
for (i in [0,1,2]) {
@ -226,8 +226,8 @@ module.exports.create = function(widgetData,container) {
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (send) widget.sendValue(v)
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (options.send) widget.sendValue(v)
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
@ -273,17 +273,17 @@ module.exports.create = function(widgetData,container) {
value.r.change(function(){
var r = clip(value.r.val(),[0,255])
var v = widget.getValue()
widget.setValue([r,v[1],v[2]],true,true)
widget.setValue([r,v[1],v[2]],{sync:true,send:true})
})
value.g.change(function(){
var g = clip(value.g.val(),[0,255])
var v = widget.getValue()
widget.setValue([v[0],g,v[2]],true,true)
widget.setValue([v[0],g,v[2]],{sync:true,send:true})
})
value.b.change(function(){
var b = clip(value.b.val(),[0,255])
var v = widget.getValue()
widget.setValue([v[0],v[1],b],true,true)
widget.setValue([v[0],v[1],b],{sync:true,send:true})
})
widget.setValue([0,0,0])

View file

@ -62,7 +62,7 @@ var _sliders_base = module.exports = function(){
this.canvas.on('drag',this.dragHandleProxy.bind(this))
this.input.change(function(){
this.widget.setValue(parseFloat(this.input.val()),true,true)
this.widget.setValue(parseFloat(this.input.val()),{sync:true,send:true})
}.bind(this))
this.widget.getValue = function(){
@ -104,7 +104,7 @@ _sliders_base.prototype.mousewheelHandle = function(e, data, traversing) {
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
this.setValue(this.percentToValue(this.percent), true, true)
this.setValue(this.percentToValue(this.percent), {sync:true,send:true})
}
@ -144,23 +144,23 @@ _sliders_base.prototype.valueToPercent = function(value) {
}
}
_sliders_base.prototype.setValue = function(v,send,sync, dragged) {
_sliders_base.prototype.setValue = function(v,options={}) {
if (typeof v != 'number') return
var value = roundTo(clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax]),this.widgetData.precision)
if (dragged && this.value == value) send = false
if (options.dragged && this.value == value) send = false
this.value = value
if (!dragged) this.percent = this.valueToPercent(this.value)
if (!options.dragged) this.percent = this.valueToPercent(this.value)
this.draw()
this.showValue()
if (sync) this.widget.trigger('sync',[this.widgetData.id,this.widget,this.widgetData.linkId])
if (send) this.sendValue(v)
if (options.sync) this.widget.trigger('sync',[this.widgetData.id,this.widget,this.widgetData.linkId])
if (options.send) this.sendValue(v)
}
_sliders_base.prototype.sendValue = function(value) {

View file

@ -47,7 +47,7 @@ module.exports.create = function(widgetData,container) {
widget.find('.value').on('draginit',function(e,dd){
var data = $(this).data()
if (data.value!=widget.value || widget.value===undefined) widget.setValue(data.value,true,true)
if (data.value!=widget.value || widget.value===undefined) widget.setValue(data.value,{sync:true,send:true})
})
@ -55,7 +55,7 @@ module.exports.create = function(widgetData,container) {
widget.getValue = function() {
return widget.value
}
widget.setValue = function(v,send,sync) {
widget.setValue = function(v,options={}) {
var i = widget.values.indexOf(v)
if (i!=-1) {
widget.value = widget.values[i]
@ -64,8 +64,8 @@ module.exports.create = function(widgetData,container) {
$(this).removeClass('ripple')
next()
})
if (send) widget.sendValue(widget.value)
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (options.send) widget.sendValue(widget.value)
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
}
}

View file

@ -43,7 +43,7 @@ module.exports.create = function(widgetData,container) {
widget.fakeclick = function(){
var newVal = widget.state?widgetData.off:widgetData.on
widget.setValue(newVal,true,true)
widget.setValue(newVal,{sync:true,send:true})
$document.on('dragend.toggle',function(){
$document.off('dragend.toggle')
widget.on('draginit.toggle',function(){
@ -57,18 +57,18 @@ module.exports.create = function(widgetData,container) {
widget.getValue = function() {
return widget.state?widgetData.on:widgetData.off
}
widget.setValue = function(v,send,sync) {
widget.setValue = function(v,options={}) {
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
widget.addClass('on')
widget.state = 1
if (send) widget.sendValue(widgetData.on)
if (options.send) widget.sendValue(widgetData.on)
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
widget.removeClass('on')
widget.state = 0
if (send) widget.sendValue(widgetData.off)
if (options.send) widget.sendValue(widgetData.off)
}
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
}
widget.sendValue = function(v) {

View file

@ -140,7 +140,7 @@ module.exports.create = function(widgetData,container) {
return [x,y]
}
widget.setValue = function(v,send,sync) {
widget.setValue = function(v,options={}) {
if (!v || v.length!=2) return
for (i in [0,1]) {
@ -158,8 +158,8 @@ module.exports.create = function(widgetData,container) {
widget.value = v
widget.showValue(v)
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (send) widget.sendValue(v)
if (options.sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
if (options.send) widget.sendValue(v)
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
@ -196,12 +196,12 @@ module.exports.create = function(widgetData,container) {
value.x.change(function(){
var v = widget.getValue()
v[0] = clip(value.x.val(),[range.x.min,range.x.max])
widget.setValue(v,true,true)
widget.setValue(v,{sync:true,send:true})
})
value.y.change(function(){
var v = widget.getValue()
v[1] = clip(value.y.val(),[range.y.min,range.y.max])
widget.setValue(v,true,true)
widget.setValue(v,{sync:true,send:true})
})
widget.setValue([range.x.min,range.y.min])