make the push not update its own led and give it's value (for state save and widget sync) based on its last changed property (led state or touch on/off)
This commit is contained in:
parent
6f827962e2
commit
238acbdf8d
4 changed files with 57 additions and 15 deletions
File diff suppressed because one or more lines are too long
|
|
@ -37,6 +37,8 @@ module.exports.create = function(widgetData,container) {
|
|||
|
||||
widget.value = widget.find('span')
|
||||
widget.state = 0
|
||||
widget.active = 0
|
||||
widget.lastChanged = 'state'
|
||||
|
||||
widget.on('drag',function(e){e.stopPropagation()})
|
||||
widget.on('draginit.push',function(){
|
||||
|
|
@ -45,9 +47,9 @@ module.exports.create = function(widgetData,container) {
|
|||
})
|
||||
|
||||
widget.fakeclick = function(){
|
||||
if (!widget.state) widget.setValue(widgetData.on,true,true)
|
||||
if (!widget.active) widget.setValuePrivate(widgetData.on,true,true)
|
||||
$document.on('dragend.push',function(){
|
||||
widget.setValue(widgetData.off,true,true)
|
||||
widget.setValuePrivate(widgetData.off,true,true)
|
||||
$document.off('dragend.push')
|
||||
widget.on('draginit.push',function(){
|
||||
widget.off('draginit.push')
|
||||
|
|
@ -57,22 +59,41 @@ module.exports.create = function(widgetData,container) {
|
|||
}
|
||||
|
||||
widget.getValue = function() {
|
||||
return widget.state?widgetData.on:widgetData.off
|
||||
return widget[widget.lastChanged]?widgetData.on:widgetData.off
|
||||
}
|
||||
|
||||
widget.setValuePrivate = function(v,send,sync) {
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
widget.addClass('active')
|
||||
widget.active = 1
|
||||
if (send) widget.sendValue(v)
|
||||
widget.lastChanged = 'active'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
|
||||
widget.removeClass('active')
|
||||
widget.active = 0
|
||||
if (send) widget.sendValue(v)
|
||||
widget.lastChanged = 'active'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
}
|
||||
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
widget.addClass('on')
|
||||
widget.state = 1
|
||||
if (send) widget.sendValue(v)
|
||||
widget.lastChanged = 'state'
|
||||
if (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)
|
||||
widget.lastChanged = 'state'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
|
||||
}
|
||||
|
||||
widget.sendValue = function(v) {
|
||||
if (v===false) return
|
||||
var args = widgetData.preArgs.concat(v)
|
||||
|
|
|
|||
|
|
@ -2923,6 +2923,8 @@ module.exports.create = function(widgetData,container) {
|
|||
|
||||
widget.value = widget.find('span')
|
||||
widget.state = 0
|
||||
widget.active = 0
|
||||
widget.lastChanged = 'state'
|
||||
|
||||
widget.on('drag',function(e){e.stopPropagation()})
|
||||
widget.on('draginit.push',function(){
|
||||
|
|
@ -2931,9 +2933,9 @@ module.exports.create = function(widgetData,container) {
|
|||
})
|
||||
|
||||
widget.fakeclick = function(){
|
||||
if (!widget.state) widget.setValue(widgetData.on,true,true)
|
||||
if (!widget.active) widget.setValuePrivate(widgetData.on,true,true)
|
||||
$document.on('dragend.push',function(){
|
||||
widget.setValue(widgetData.off,true,true)
|
||||
widget.setValuePrivate(widgetData.off,true,true)
|
||||
$document.off('dragend.push')
|
||||
widget.on('draginit.push',function(){
|
||||
widget.off('draginit.push')
|
||||
|
|
@ -2943,22 +2945,41 @@ module.exports.create = function(widgetData,container) {
|
|||
}
|
||||
|
||||
widget.getValue = function() {
|
||||
return widget.state?widgetData.on:widgetData.off
|
||||
return widget[widget.lastChanged]?widgetData.on:widgetData.off
|
||||
}
|
||||
|
||||
widget.setValuePrivate = function(v,send,sync) {
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
widget.addClass('active')
|
||||
widget.active = 1
|
||||
if (send) widget.sendValue(v)
|
||||
widget.lastChanged = 'active'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
|
||||
widget.removeClass('active')
|
||||
widget.active = 0
|
||||
if (send) widget.sendValue(v)
|
||||
widget.lastChanged = 'active'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
}
|
||||
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||||
widget.addClass('on')
|
||||
widget.state = 1
|
||||
if (send) widget.sendValue(v)
|
||||
widget.lastChanged = 'state'
|
||||
if (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)
|
||||
widget.lastChanged = 'state'
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
|
||||
}
|
||||
|
||||
widget.sendValue = function(v) {
|
||||
if (v===false) return
|
||||
var args = widgetData.preArgs.concat(v)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
.push-container {
|
||||
--color-custom:var(--color-accent);
|
||||
|
||||
|
||||
width:100rem;
|
||||
min-height: 65rem;
|
||||
flex-shrink: 0;
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
cursor: pointer;
|
||||
|
||||
.push {
|
||||
&.on {
|
||||
&.active {
|
||||
background: var(--color-fg);
|
||||
}
|
||||
border-bottom:2rem solid var(--color-fg);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue