no more $click event for button widgets, only drag* events

This commit is contained in:
Jean-Emmanuel 2015-11-07 19:11:56 +01:00
parent a9a5d0296e
commit 452a04e32a
2 changed files with 29 additions and 15 deletions

View file

@ -65,10 +65,7 @@ init = function(session,callback) {
document.elementFromPoint(dd.originalEvent.changedTouches[0].clientX, dd.originalEvent.changedTouches[0].clientY)
:dd.target
if ($('#sidepanel').has(dd.target)[0]) return
dd.absolute=true
$(dd.target).trigger('draginit',[dd])
if (target!=dd.target) $(dd.target).click()
target = dd.target
})
@ -76,9 +73,7 @@ init = function(session,callback) {
});
$(document).keyup(function (e) {
if (e.keyCode == 16) {
$('body').off('draginit')
$('body').off('drag')
$('body').off('dragend')
}
});

View file

@ -181,14 +181,28 @@ createWidget.toggle = function(widgetData) {
<div class="toggle">
<div class="light"></div>
</div>\
`)
`),
$document = $(document)
widget.value = widget.find('span')
widget.click(function(){
widget.on('drag',function(e){e.stopPropagation()})
widget.on('draginit.toggle',function(){
widget.off('draginit.toggle')
widget.fakeclick()
})
widget.fakeclick = function(){
var newVal = widget.hasClass('on')?widgetData.off:widgetData.on
widget.setValue(newVal,true)
})
$document.on('dragend.toggle',function(){
$document.off('dragend.toggle')
widget.on('draginit.toggle',function(){
widget.off('draginit.toggle')
widget.fakeclick()
})
})
}
widget.getValue = function() {
@ -232,8 +246,8 @@ createWidget.push = function(widgetData) {
widget.value = widget.find('span')
widget.on('drag',function(e){e.stopPropagation()})
widget.on('draginit',function(){
widget.off('draginit')
widget.on('draginit.push',function(){
widget.off('draginit.push')
widget.fakeclick()
})
@ -285,7 +299,8 @@ createWidget.switch = function(widgetData) {
var widget = $(`
<div class="switch">
</div>
`)
`),
$document = $(document)
if (widgetData.horizontal) {
widget.addClass('horizontal')
@ -295,20 +310,24 @@ createWidget.switch = function(widgetData) {
widget.append('<div class="value" data-value="'+widgetData.values[v]+'">'+widgetData.values[v]+'</div>')
}
widget.value = false
widget.find('.value').click(function(){
if ($(this).hasClass('on')) return
var newVal = $(this).data('value')
widget.setValue(newVal,true,true)
widget.on('drag',function(e){e.stopPropagation()})
widget.on('draginit',function(e,dd){
var val = dd.target.getAttribute('data-value')
if (val!==widget.value) widget.setValue(val,true,true)
})
widget.getValue = function() {
return widget.find('.on').data('value')
}
widget.setValue = function(v,send,sync) {
var e = widget.find('.value[data-value="'+v+'"]')
if (e.length) {
widget.value = v
widget.find('.on').removeClass('on')
e.addClass('on').ripple()
if (send) widget.sendValue(v)