- strict typechecking and value caching instead of class checking in toggle & push
- push doesn't fire its 'on' value if pressed while stuck in 'on' position (ie synchronized with a toggle)
This commit is contained in:
parent
34a8ef72a8
commit
7e24a58aa1
2 changed files with 14 additions and 10 deletions
|
|
@ -36,6 +36,7 @@ module.exports.create = function(widgetData,container) {
|
|||
light = widget.find('.light')[0]
|
||||
|
||||
widget.value = widget.find('span')
|
||||
widget.state = 0
|
||||
|
||||
widget.on('drag',function(e){e.stopPropagation()})
|
||||
widget.on('draginit.push',function(){
|
||||
|
|
@ -44,7 +45,7 @@ module.exports.create = function(widgetData,container) {
|
|||
})
|
||||
|
||||
widget.fakeclick = function(){
|
||||
widget.setValue(widgetData.on,true,true)
|
||||
if (!widget.state) widget.setValue(widgetData.on,true,true)
|
||||
$document.on('dragend.push',function(){
|
||||
widget.setValue(widgetData.off,true,true)
|
||||
$document.off('dragend.push')
|
||||
|
|
@ -56,16 +57,16 @@ module.exports.create = function(widgetData,container) {
|
|||
}
|
||||
|
||||
widget.getValue = function() {
|
||||
return widget.hasClass('on')?widgetData.on:widgetData.off
|
||||
return widget.state?widgetData.on:widgetData.off
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
var on = widgetData.on,
|
||||
off= widgetData.off
|
||||
if (v==on) {
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
widget.addClass('on')
|
||||
widget.state = 1
|
||||
if (send) widget.sendValue(v)
|
||||
} else if (v==off) {
|
||||
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
|
||||
widget.removeClass('on')
|
||||
widget.state = 0
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ module.exports.create = function(widgetData,container) {
|
|||
light = widget.find('.light')[0]
|
||||
|
||||
widget.value = widget.find('span')
|
||||
widget.state = 0
|
||||
|
||||
widget.on('drag',function(e){e.stopPropagation()})
|
||||
widget.on('draginit.toggle',function(){
|
||||
|
|
@ -43,7 +44,7 @@ module.exports.create = function(widgetData,container) {
|
|||
})
|
||||
|
||||
widget.fakeclick = function(){
|
||||
var newVal = widget.hasClass('on')?widgetData.off:widgetData.on
|
||||
var newVal = widget.state?widgetData.off:widgetData.on
|
||||
widget.setValue(newVal,true,true)
|
||||
$document.on('dragend.toggle',function(){
|
||||
$document.off('dragend.toggle')
|
||||
|
|
@ -56,14 +57,16 @@ module.exports.create = function(widgetData,container) {
|
|||
|
||||
|
||||
widget.getValue = function() {
|
||||
return widget.hasClass('on')?widgetData.on:widgetData.off
|
||||
return widget.state?widgetData.on:widgetData.off
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (v==widgetData.on) {
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
widget.addClass('on')
|
||||
widget.state = 1
|
||||
if (send) widget.sendValue(widgetData.on)
|
||||
} else if (v==widgetData.off) {
|
||||
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
|
||||
widget.removeClass('on')
|
||||
widget.state = 0
|
||||
if (send) widget.sendValue(widgetData.off)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue