ripple effect on button-like widgets

new push button widget
This commit is contained in:
jean-emmanuel 2015-11-04 12:53:33 +01:00
parent e217a189cd
commit 48b6db0d9a
4 changed files with 92 additions and 7 deletions

View file

@ -96,8 +96,11 @@ parsewidgets = function(widgets,parent) {
style = styleW + ';' + styleH
// Sort widgets' properties and turn string-numbers to numbers
for (k in widgetOptions[widgetData.type]) {
var tmp = widgetData[k]
if (parseFloat(tmp)==tmp) tmp=parseFloat(tmp)
if (parseInt(tmp)==tmp) tmp=parseInt(tmp)
delete widgetData[k]
widgetData[k] = tmp
}

View file

@ -37,6 +37,16 @@ widgetOptions = {
path:'auto',
target:[]
},
push: {
id:'auto',
label:'auto',
width:'auto',
height:'auto',
off:0,
on:1,
path:'auto',
target:[]
},
switch: {
id:'auto',
label:'auto',
@ -169,9 +179,7 @@ createWidget.toggle = function(widgetData) {
<div class="toggle">
<div class="light"></div>
</div>\
`),
led = widget.find('.light')
`)
widget.value = widget.find('span')
@ -189,11 +197,9 @@ createWidget.toggle = function(widgetData) {
off= widgetData.off
if (v==on) {
widget.addClass('on')
if (widgetData.color) led[0].setAttribute('style','background:'+widgetData.color)
if (send) widget.sendValue(v)
} else if (v==off) {
widget.removeClass('on')
if (widgetData.color) led[0].setAttribute('style','')
if (send) widget.sendValue(v)
}
@ -201,6 +207,60 @@ createWidget.toggle = function(widgetData) {
}
widget.sendValue = function(v) {
if (v===false) return
sendOsc({
target:widgetData.target,
path:widgetData.path,
args:v
})
}
widget.setValue()
return widget
}
createWidget.push = function(widgetData) {
var widget = $(`
<div class="push toggle">
<div class="light"></div>
</div>\
`)
widget.value = widget.find('span')
widget.on('drag',function(){})
widget.on('draginit',function(){
widget.setValue(widgetData.on,true)
widget.on('dragend',function(){
widget.setValue(widgetData.off,true)
widget.off('dragend')
})
})
widget.getValue = function() {
return widget.hasClass('on')?widgetData.on:widgetData.off
}
widget.setValue = function(v,send,sync) {
var on = widgetData.on,
off= widgetData.off
if (v==on) {
widget.addClass('on')
widget.removeClass('ripple')
setTimeout(function(){
widget.addClass('ripple')
},1)
if (send) widget.sendValue(v)
} else if (v==off) {
widget.removeClass('on')
if (send) widget.sendValue(v)
}
if (send) widget.trigger('sync')
}
widget.sendValue = function(v) {
if (v===false) return
sendOsc({
target:widgetData.target,
path:widgetData.path,