Mouse/touch dragging handler rewritten

now using event delegation and direct handler calls instead of DOM event bubbling whenever it's possible
This commit is contained in:
jean-emmanuel 2016-04-07 15:49:30 +02:00
parent 3207b835ba
commit 0a868a71b5
20 changed files with 502 additions and 322 deletions

View file

@ -3,11 +3,13 @@
## 0.4.6
- engine
- electron 0.37.4
- electron 0.37.5
- node-osc 2.0.3
- features
- `compact` option added to knob and fader
- if an osc input port is specified, osc messages will be sent from it. This enhances compatibility with apps that send their feedback messages directly to the sender.
- misc
- mouse/touch dragging handler rewritten, now using event delegation and direct handler calls instead of DOM event bubbling whenever it's possible
## 0.4.5

File diff suppressed because one or more lines are too long

View file

@ -178,12 +178,10 @@ module.exports = {
},
traversingDisable: function(){
$('#container').delegateDrag('disable')
$('.traversingEnable, .traversingDisable').toggleClass('on')
TRAVERSING = false
},
traversingEnable: function(){
$('#container').delegateDrag()
$('.traversingEnable, .traversingDisable').toggleClass('on')
TRAVERSING = true
}

View file

@ -13,6 +13,8 @@ var correctPosition = function (m, parent){
m.css({'margin-top':totalHeight-(height + pos.top)})
}
}
var ev = 'ontouchstart' in window ?'touchstart':'mousedown'
var menu = function(e,actions,parent){
@ -25,13 +27,13 @@ var menu = function(e,actions,parent){
if (typeof actions[label] == 'object') {
var item = $(`<div class="item has-sub" tabIndex="1">${label}</div>`).appendTo(m).on('touchstart mousedown',function(e){e.stopPropagation()})
var item = $(`<div class="item has-sub" tabIndex="1">${label}</div>`).appendTo(m).on(ev,function(e){e.stopPropagation()})
menu(e,actions[label],item)
} else {
$(`<div class="item">${label}</div>`).on('mousedown.editor touchstart.editor',function(){
$(`<div class="item">${label}</div>`).on(ev + '.editor',function(){
var callback = actions[label]
return function(e){
callback()

View file

@ -1,6 +1,9 @@
var updateDom = require('./data-workers').updateDom,
widgetOptions = require('../widgets').widgetOptions
var ev = 'ontouchstart' in window ?'touchstart':'mousedown'
var editObject = function(container, data, refresh){
if (!refresh && (container.hasClass('editing') || $(`a[data-tab="#${container.attr('id')}"]`).hasClass('editing'))) return
@ -98,7 +101,7 @@ var editObject = function(container, data, refresh){
var editItem = function(i) {
return function(){
container.find('.widget').first().siblings().addBack().eq(i).trigger('mousedown.editor')
container.find('.widget').first().siblings().addBack().eq(i).trigger(ev+'.editor')
}
}
@ -153,7 +156,7 @@ var editObject = function(container, data, refresh){
var editItem = function(i) {
return function(){
container.find('.tab').first().siblings().addBack().eq(i).trigger('mousedown.editor')
container.find('.tab').first().siblings().addBack().eq(i).trigger(ev+'.editor')
}
}
@ -253,7 +256,7 @@ var editSession = function(container,data,refresh){
var editItem = function(i) {
return function(){
container.find('.tab').first().siblings().addBack().eq(i).trigger('mousedown.editor')
container.find('.tab').first().siblings().addBack().eq(i).trigger(ev+'.editor')
}
}

View file

@ -14,11 +14,8 @@ var data = require('./data-workers'),
var init = function(){
document.addEventListener("contextmenu", function(e){
e.preventDefault()
}, false);
$('body').off('.editor').on('mousedown.editor touchstart.editor',function(e){
var ev = 'ontouchstart' in window ?'touchstart':'mousedown'
$('body').off('.editor').on(ev+'.editor fake-right-click',function(e,d){
if (!EDITING) return
@ -43,11 +40,10 @@ var init = function(){
}
if (e.button!=2) return
if (e.type!='fake-right-click') return
if (container.attr('id')=='container') {
menu(e,{
menu(d,{
'<i class="fa fa-plus"></i> Add tab': function(){
data.push({})
updateDom(container,data)
@ -175,7 +171,7 @@ var init = function(){
}
menu(e,actions,'body')
menu(d,actions,'body')
})

View file

@ -148,8 +148,8 @@ module.exports.create = function(widgetData,container) {
widget.updateUi(gauge.size)
})
wrapper.on('mousedown',function(e){
if (e.button==2 && !EDITING) {
wrapper.on('fake-right-click',function(e){
if (!EDITING) {
e.stopPropagation()
e.preventDefault()
input.focus()
@ -208,8 +208,9 @@ module.exports.create = function(widgetData,container) {
})
wrapper.on('drag',function(e,data){
e.stopPropagation()
wrapper.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return

View file

@ -100,10 +100,11 @@ module.exports.create = function(widgetData,container) {
if (!w || mask.size==w) return
mask.size=w
mask[0].setAttribute('style',`height:${w}px;width:${w}px;padding-bottom:0`)
wrapper.size = {width:wrapper[0].clientWidth,height:wrapper[0].clientHeight}
})
wrapper.on('mousedown',function(e){
if (e.button==2 && !EDITING) {
wrapper.on('fake-right-click',function(e){
if (!EDITING) {
e.stopPropagation()
e.preventDefault()
input.focus()
@ -142,8 +143,8 @@ module.exports.create = function(widgetData,container) {
wrapper.on('draginit',function(e,data){
if (snap || TRAVERSING) {
var w = data.target.clientWidth,
h = data.target.clientHeight,
var w = wrapper.size.width,
h = wrapper.size.height,
x = data.offsetX-w/2,
y = data.offsetY-h/2,
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
@ -174,8 +175,9 @@ module.exports.create = function(widgetData,container) {
offR = knob.rotation
})
wrapper.on('drag',function(e,data){
e.stopPropagation()
wrapper.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return

View file

@ -79,7 +79,7 @@ module.exports.create = function(widgetData,container) {
return widget.value
}
widget.delegateDrag()
widget.handleDragging(true)
return widget
}

View file

@ -70,7 +70,7 @@ module.exports.create = function(widgetData,container) {
return widget.value
}
widget.delegateDrag()
widget.handleDragging(true)
return widget
}

View file

@ -70,7 +70,7 @@ module.exports.create = function(widgetData,container) {
return widget.value
}
widget.delegateDrag()
widget.handleDragging(true)
return widget
}

View file

@ -105,8 +105,9 @@ module.exports.create = function(widgetData,container) {
rgbOff = {x:rgbHandle.width,y:rgbHandle.height}
})
pad.on('drag',function(e,data){
e.stopPropagation()
pad.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return
@ -162,8 +163,9 @@ module.exports.create = function(widgetData,container) {
})
huePad.on('drag',function(e,data){
e.stopPropagation()
huePad.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return

View file

@ -45,10 +45,8 @@ module.exports.create = function(widgetData,container) {
widget.value = undefined
widget.on('drag',function(e){e.stopPropagation()})
widget.on('draginit',function(e,dd){
var data = $(dd.target).data()
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)
})

View file

@ -105,8 +105,9 @@ module.exports.create = function(widgetData,container) {
off = {x:handle.width,y:handle.height}
})
pad.on('drag',function(e,data){
e.stopPropagation()
pad.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return

View file

@ -235,12 +235,10 @@ module.exports = {
},
traversingDisable: function(){
$('#container').delegateDrag('disable')
$('.traversingEnable, .traversingDisable').toggleClass('on')
TRAVERSING = false
},
traversingEnable: function(){
$('#container').delegateDrag()
$('.traversingEnable, .traversingDisable').toggleClass('on')
TRAVERSING = true
}
@ -366,6 +364,8 @@ var correctPosition = function (m, parent){
m.css({'margin-top':totalHeight-(height + pos.top)})
}
}
var ev = 'ontouchstart' in window ?'touchstart':'mousedown'
var menu = function(e,actions,parent){
@ -378,13 +378,13 @@ var menu = function(e,actions,parent){
if (typeof actions[label] == 'object') {
var item = $(`<div class="item has-sub" tabIndex="1">${label}</div>`).appendTo(m).on('touchstart mousedown',function(e){e.stopPropagation()})
var item = $(`<div class="item has-sub" tabIndex="1">${label}</div>`).appendTo(m).on(ev,function(e){e.stopPropagation()})
menu(e,actions[label],item)
} else {
$(`<div class="item">${label}</div>`).on('mousedown.editor touchstart.editor',function(){
$(`<div class="item">${label}</div>`).on(ev + '.editor',function(){
var callback = actions[label]
return function(e){
callback()
@ -583,6 +583,9 @@ module.exports = {
var updateDom = require('./data-workers').updateDom,
widgetOptions = require('../widgets').widgetOptions
var ev = 'ontouchstart' in window ?'touchstart':'mousedown'
var editObject = function(container, data, refresh){
if (!refresh && (container.hasClass('editing') || $(`a[data-tab="#${container.attr('id')}"]`).hasClass('editing'))) return
@ -680,7 +683,7 @@ var editObject = function(container, data, refresh){
var editItem = function(i) {
return function(){
container.find('.widget').first().siblings().addBack().eq(i).trigger('mousedown.editor')
container.find('.widget').first().siblings().addBack().eq(i).trigger(ev+'.editor')
}
}
@ -735,7 +738,7 @@ var editObject = function(container, data, refresh){
var editItem = function(i) {
return function(){
container.find('.tab').first().siblings().addBack().eq(i).trigger('mousedown.editor')
container.find('.tab').first().siblings().addBack().eq(i).trigger(ev+'.editor')
}
}
@ -835,7 +838,7 @@ var editSession = function(container,data,refresh){
var editItem = function(i) {
return function(){
container.find('.tab').first().siblings().addBack().eq(i).trigger('mousedown.editor')
container.find('.tab').first().siblings().addBack().eq(i).trigger(ev+'.editor')
}
}
@ -905,11 +908,8 @@ var data = require('./data-workers'),
var init = function(){
document.addEventListener("contextmenu", function(e){
e.preventDefault()
}, false);
$('body').off('.editor').on('mousedown.editor touchstart.editor',function(e){
var ev = 'ontouchstart' in window ?'touchstart':'mousedown'
$('body').off('.editor').on(ev+'.editor fake-right-click',function(e,d){
if (!EDITING) return
@ -934,11 +934,10 @@ var init = function(){
}
if (e.button!=2) return
if (e.type!='fake-right-click') return
if (container.attr('id')=='container') {
menu(e,{
menu(d,{
'<i class="fa fa-plus"></i> Add tab': function(){
data.push({})
updateDom(container,data)
@ -1066,7 +1065,7 @@ var init = function(){
}
menu(e,actions,'body')
menu(d,actions,'body')
})
@ -1849,8 +1848,8 @@ module.exports.create = function(widgetData,container) {
widget.updateUi(gauge.size)
})
wrapper.on('mousedown',function(e){
if (e.button==2 && !EDITING) {
wrapper.on('fake-right-click',function(e){
if (!EDITING) {
e.stopPropagation()
e.preventDefault()
input.focus()
@ -1909,8 +1908,9 @@ module.exports.create = function(widgetData,container) {
})
wrapper.on('drag',function(e,data){
e.stopPropagation()
wrapper.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return
@ -2103,10 +2103,11 @@ module.exports.create = function(widgetData,container) {
if (!w || mask.size==w) return
mask.size=w
mask[0].setAttribute('style',`height:${w}px;width:${w}px;padding-bottom:0`)
wrapper.size = {width:wrapper[0].clientWidth,height:wrapper[0].clientHeight}
})
wrapper.on('mousedown',function(e){
if (e.button==2 && !EDITING) {
wrapper.on('fake-right-click',function(e){
if (!EDITING) {
e.stopPropagation()
e.preventDefault()
input.focus()
@ -2145,8 +2146,8 @@ module.exports.create = function(widgetData,container) {
wrapper.on('draginit',function(e,data){
if (snap || TRAVERSING) {
var w = data.target.clientWidth,
h = data.target.clientHeight,
var w = wrapper.size.width,
h = wrapper.size.height,
x = data.offsetX-w/2,
y = data.offsetY-h/2,
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
@ -2177,8 +2178,9 @@ module.exports.create = function(widgetData,container) {
offR = knob.rotation
})
wrapper.on('drag',function(e,data){
e.stopPropagation()
wrapper.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return
@ -2489,7 +2491,7 @@ module.exports.create = function(widgetData,container) {
return widget.value
}
widget.delegateDrag()
widget.handleDragging(true)
return widget
}
@ -2567,7 +2569,7 @@ module.exports.create = function(widgetData,container) {
return widget.value
}
widget.delegateDrag()
widget.handleDragging(true)
return widget
}
@ -2645,7 +2647,7 @@ module.exports.create = function(widgetData,container) {
return widget.value
}
widget.delegateDrag()
widget.handleDragging(true)
return widget
}
@ -3129,8 +3131,9 @@ module.exports.create = function(widgetData,container) {
rgbOff = {x:rgbHandle.width,y:rgbHandle.height}
})
pad.on('drag',function(e,data){
e.stopPropagation()
pad.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return
@ -3186,8 +3189,9 @@ module.exports.create = function(widgetData,container) {
})
huePad.on('drag',function(e,data){
e.stopPropagation()
huePad.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return
@ -3407,10 +3411,8 @@ module.exports.create = function(widgetData,container) {
widget.value = undefined
widget.on('drag',function(e){e.stopPropagation()})
widget.on('draginit',function(e,dd){
var data = $(dd.target).data()
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)
})
@ -3947,8 +3949,9 @@ module.exports.create = function(widgetData,container) {
off = {x:handle.width,y:handle.height}
})
pad.on('drag',function(e,data){
e.stopPropagation()
pad.on('drag',function(e,data,originalEvent){
if (originalEvent) originalEvent.preventDefault()
if (TRAVERSING) return
@ -4067,16 +4070,65 @@ require('./app')
},{"./app":1,"socket.io-client":71}],34:[function(require,module,exports){
// jQuery drag event handler
var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
// note: triggerHandler() is used instead of trigger() when event bubblig is not
// necessary, this increases performances a lot.
;(function($){
var $document = $(document)
$.event.special.drag = {
setup: function() {
var element = $(this),
previousEvent = null
var events = 'ontouchstart' in window ?
{start:'touchstart.drag',stop:'touchend.drag touchcancel.drag',move:'touchmove.drag',touch:true}:
{start:'mousedown.drag',stop:'mouseup.drag',move:'mousemove.drag',touch:false}
$document = $(document),
getOffset = function(obj) {
var offsetLeft = 0
var offsetTop = 0
if (obj) {
do {
if (!isNaN(obj.offsetLeft)) {
offsetLeft += obj.offsetLeft - obj.scrollLeft
}
if (!isNaN(obj.offsetTop)) {
offsetTop += obj.offsetTop - obj.scrollTop
}
} while(obj = obj.offsetParent )
}
var mousemove = function(e) {
e.preventDefault()
return {left: offsetLeft, top: offsetTop}
}
$.fn.handleDragging = function(traversing) {
// mouse single touch handler
if (!events.touch) {
var previousEvent = null,
target = null,
isPointerDown = false
this.on(events.start,function(e){
e.stopPropagation()
isPointerDown = true
target = $(e.target)
previousEvent = e
e.speedX = 0
e.speedY = 0
e.deltaX = 0
e.deltaY = 0
if (e.button==2) {
e.preventDefault()
$(e.target).triggerHandler('fake-right-click',e)
return
}
target.triggerHandler('draginit',e)
})
this.on(events.move,function(e){
e.stopPropagation()
if (!isPointerDown) return
e.speedX = e.pageX - previousEvent.pageX
e.speedY = e.pageY - previousEvent.pageY
@ -4084,137 +4136,175 @@ var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
e.deltaY = e.speedY + previousEvent.deltaY
element.trigger("drag",e)
if (traversing || TRAVERSING) {
target = $(e.target)
if (target[0]!=previousEvent.target) {
$(previousEvent.target).trigger('dragend',e)
}
e.preventDefault()
target.triggerHandler('draginit',e)
} else {
target.triggerHandler('drag',e)
}
previousEvent = e
}
var mouseup = function(e) {
$document.off("mouseup")
$document.off("mousemove")
})
$document.on(events.stop,function(e){
e.stopPropagation()
if (!isPointerDown) return
e.speedX = e.pageX - previousEvent.pageX
e.speedY = e.pageY - previousEvent.pageY
e.deltaX = e.deltaX + previousEvent.deltaX
e.deltaY = e.deltaY + previousEvent.deltaY
element.trigger("dragend", e)
}
var touchend = function(e) {
e.pageX = e.originalEvent.changedTouches[0].pageX
e.pageY = e.originalEvent.changedTouches[0].pageY
e.offsetX = e.pageX-getOffset(e.target).left
e.offsetY = e.pageY-getOffset(e.target).top
e.speedX = e.pageX - previousEvent.pageX
e.speedY = e.pageY - previousEvent.pageY
e.deltaX = e.deltaX + previousEvent.deltaX
e.deltaY = e.deltaY + previousEvent.deltaY
element.trigger("dragend", e)
}
function getOffset(obj) {
var offsetLeft = 0
var offsetTop = 0
if (obj) {
do {
if (!isNaN(obj.offsetLeft)) {
offsetLeft += obj.offsetLeft - obj.scrollLeft
}
if (!isNaN(obj.offsetTop)) {
offsetTop += obj.offsetTop - obj.scrollTop
}
} while(obj = obj.offsetParent )
}
return {left: offsetLeft, top: offsetTop}
}
element.on(startEvent+".drag", function(e) {
previousEvent = e
if (!e.originalEvent.changedTouches) {
// mouse
$document.on("mousemove", mousemove)
$document.on("mouseup", mouseup)
} else {
// touch
if (e.originalEvent.targetTouches.length == 2) return
e.pageX = e.originalEvent.changedTouches[0].pageX
e.pageY = e.originalEvent.changedTouches[0].pageY
e.offsetX = e.pageX-getOffset(e.target).left
e.offsetY = e.pageY-getOffset(e.target).top
}
e.speedX = 0
e.speedY = 0
e.deltaX = 0
e.deltaY = 0
element.trigger("draginit", e)
target.trigger('dragend',e)
isPointerDown = false
})
element.on("touchmove.drag", function(e) {
e.preventDefault()
e.pageX = e.originalEvent.targetTouches[0].pageX
e.pageY = e.originalEvent.targetTouches[0].pageY
e.speedX = previousEvent?e.pageX - previousEvent.pageX:0
e.speedY = previousEvent?e.pageY - previousEvent.pageY:0
if (e.originalEvent.targetTouches.length == 2) {
e.speedX = e.speedX / 4
e.speedY = e.speedY / 4
}
e.deltaX = previousEvent?e.speedX + previousEvent.deltaX:0
e.deltaY = previousEvent?e.speedY + previousEvent.deltaY:0
e.offsetX = previousEvent&&!e.shiftKey?previousEvent.offsetX+e.speedX:e.pageX-getOffset(e.target).left
e.offsetY = previousEvent&&!e.shiftKey?previousEvent.offsetY+e.speedY:e.pageY-getOffset(e.target).top
element.trigger("drag",e)
previousEvent = e
})
element.on("touchend.drag", touchend)
element.on("touchcancel.drag", touchend)
},
teardown: function() {
var element = $(this)
element.off(".drag")
}
}
$.fn.delegateDrag = function(action) {
if (action=='disable') {
this.off('.delegateDrag')
} else {
var target = null
this.on('drag.delegateDrag',function(ev,dd){
dd.target = dd.originalEvent&&dd.originalEvent.changedTouches?
document.elementFromPoint(dd.originalEvent.changedTouches[0].clientX, dd.originalEvent.changedTouches[0].clientY)
:dd.target
if (target!=dd.target) {
$(target).trigger('dragend',[dd])
$(dd.target).trigger('draginit',[dd])
} else {
$(dd.target).trigger('draginit',[dd])
// multi touch hanlder
if (events.touch) {
var targets = {},
previousTouches = {},
touchTapTimer = false
this.on(events.start,function(e){
// e.stopPropagation()
var oE = e.originalEvent
for (i in oE.changedTouches) {
if (isNaN(i)) continue
var touch = oE.changedTouches[i]
targets[i] = $(touch.target)
previousTouches[i] = touch
touch.speedX = 0
touch.speedY = 0
touch.deltaX = 0
touch.deltaY = 0
var off = getOffset(touch.target)
touch.offsetX = touch.pageX-off.left
touch.offsetY = touch.pageY-off.top
targets[i].triggerHandler('draginit',[touch,e])
}
if (!touchTapTimer&&oE.touches.length==1) {
touchTapTimer = setTimeout(function(){
$(oE.changedTouches[0].target).triggerHandler('fake-right-click',oE.changedTouches[0])
},600)
} else {
clearTimeout(touchTapTimer)
touchTapTimer = false
}
target = dd.target
})
this.on('dragend.delegateDrag',function(){
target = null
this.on(events.move,function(e){
// e.stopPropagation()
var oE = e.originalEvent
if (touchTapTimer) {
clearTimeout(touchTapTimer)
touchTapTimer = false
}
for (i in oE.changedTouches) {
if (isNaN(i)) continue
var touch = oE.changedTouches[i]
touch.speedX = touch.pageX - previousTouches[i].pageX
touch.speedY = touch.pageY - previousTouches[i].pageY
touch.deltaX = touch.speedX + previousTouches[i].deltaX
touch.deltaY = touch.speedY + previousTouches[i].deltaY
touch.offsetX = previousTouches[i].offsetX+touch.speedX
touch.offsetY = previousTouches[i].offsetY+touch.speedY
if (traversing || TRAVERSING) {
targets[i] = $(document.elementFromPoint(touch.clientX, touch.clientY))
var previousTarget = document.elementFromPoint(previousTouches[i].clientX, previousTouches[i].clientY)
if (targets[i][0]!=previousTarget) {
var off = getOffset(targets[i][0])
touch.offsetX = touch.pageX-off.left
touch.offsetY = touch.pageY-off.top
$(previousTarget).trigger('dragend',[touch,e])
}
e.preventDefault()
if (this.contains(targets[i][0])) targets[i].triggerHandler('draginit',[touch,e])
} else {
targets[i].triggerHandler('drag',[touch,e])
}
previousTouches[i] = touch
}
})
$document.on(events.stop,function(e){
e.stopPropagation()
var oE = e.originalEvent
for (i in oE.changedTouches) {
if (isNaN(i)) continue
var touch = oE.changedTouches[i]
$(oE.changedTouches[i].target).trigger('dragend',[touch,e])
previousTouches[i] = touch
}
if (touchTapTimer) {
clearTimeout(touchTapTimer)
touchTapTimer = false
}
})
}
return this
}
$document.handleDragging()
if (events.touch) {
$document.on('mousedown',function(e){
if (e.toElement.tagName!='INPUT') return false
})
}
})(jQuery)
},{}],35:[function(require,module,exports){
(function ($) {
var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
;(function ($) {
$.fn.fakeInput = function(options) {
var settings = $.extend({
@ -4293,9 +4383,9 @@ var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
i.blur(function(){
self.attr('tabindex','0')
i.remove()
$(document).off('mousedown.fakeInput touchstart.fakeInput')
$(document).off('.fakeInput')
})
$(document).on('mousedown.fakeInput touchstart.fakeInput',function(){
$(document).on(startEvent+'.fakeInput',function(){
i.blur()
})

View file

@ -1,14 +1,63 @@
// jQuery drag event handler
var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
// note: triggerHandler() is used instead of trigger() when event bubblig is not
// necessary, this increases performances a lot.
;(function($){
var $document = $(document)
$.event.special.drag = {
setup: function() {
var element = $(this),
previousEvent = null
var events = 'ontouchstart' in window ?
{start:'touchstart.drag',stop:'touchend.drag touchcancel.drag',move:'touchmove.drag',touch:true}:
{start:'mousedown.drag',stop:'mouseup.drag',move:'mousemove.drag',touch:false}
$document = $(document),
getOffset = function(obj) {
var offsetLeft = 0
var offsetTop = 0
if (obj) {
do {
if (!isNaN(obj.offsetLeft)) {
offsetLeft += obj.offsetLeft - obj.scrollLeft
}
if (!isNaN(obj.offsetTop)) {
offsetTop += obj.offsetTop - obj.scrollTop
}
} while(obj = obj.offsetParent )
}
var mousemove = function(e) {
e.preventDefault()
return {left: offsetLeft, top: offsetTop}
}
$.fn.handleDragging = function(traversing) {
// mouse single touch handler
if (!events.touch) {
var previousEvent = null,
target = null,
isPointerDown = false
this.on(events.start,function(e){
e.stopPropagation()
isPointerDown = true
target = $(e.target)
previousEvent = e
e.speedX = 0
e.speedY = 0
e.deltaX = 0
e.deltaY = 0
if (e.button==2) {
e.preventDefault()
$(e.target).triggerHandler('fake-right-click',e)
return
}
target.triggerHandler('draginit',e)
})
this.on(events.move,function(e){
e.stopPropagation()
if (!isPointerDown) return
e.speedX = e.pageX - previousEvent.pageX
e.speedY = e.pageY - previousEvent.pageY
@ -16,131 +65,168 @@ var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
e.deltaY = e.speedY + previousEvent.deltaY
element.trigger("drag",e)
if (traversing || TRAVERSING) {
target = $(e.target)
if (target[0]!=previousEvent.target) {
$(previousEvent.target).trigger('dragend',e)
}
e.preventDefault()
target.triggerHandler('draginit',e)
} else {
target.triggerHandler('drag',e)
}
previousEvent = e
}
var mouseup = function(e) {
$document.off("mouseup")
$document.off("mousemove")
})
$document.on(events.stop,function(e){
e.stopPropagation()
if (!isPointerDown) return
e.speedX = e.pageX - previousEvent.pageX
e.speedY = e.pageY - previousEvent.pageY
e.deltaX = e.deltaX + previousEvent.deltaX
e.deltaY = e.deltaY + previousEvent.deltaY
element.trigger("dragend", e)
}
var touchend = function(e) {
e.pageX = e.originalEvent.changedTouches[0].pageX
e.pageY = e.originalEvent.changedTouches[0].pageY
e.offsetX = e.pageX-getOffset(e.target).left
e.offsetY = e.pageY-getOffset(e.target).top
e.speedX = e.pageX - previousEvent.pageX
e.speedY = e.pageY - previousEvent.pageY
e.deltaX = e.deltaX + previousEvent.deltaX
e.deltaY = e.deltaY + previousEvent.deltaY
element.trigger("dragend", e)
}
function getOffset(obj) {
var offsetLeft = 0
var offsetTop = 0
if (obj) {
do {
if (!isNaN(obj.offsetLeft)) {
offsetLeft += obj.offsetLeft - obj.scrollLeft
}
if (!isNaN(obj.offsetTop)) {
offsetTop += obj.offsetTop - obj.scrollTop
}
} while(obj = obj.offsetParent )
}
return {left: offsetLeft, top: offsetTop}
}
element.on(startEvent+".drag", function(e) {
previousEvent = e
if (!e.originalEvent.changedTouches) {
// mouse
$document.on("mousemove", mousemove)
$document.on("mouseup", mouseup)
} else {
// touch
if (e.originalEvent.targetTouches.length == 2) return
e.pageX = e.originalEvent.changedTouches[0].pageX
e.pageY = e.originalEvent.changedTouches[0].pageY
e.offsetX = e.pageX-getOffset(e.target).left
e.offsetY = e.pageY-getOffset(e.target).top
}
e.speedX = 0
e.speedY = 0
e.deltaX = 0
e.deltaY = 0
element.trigger("draginit", e)
target.trigger('dragend',e)
isPointerDown = false
})
element.on("touchmove.drag", function(e) {
e.preventDefault()
e.pageX = e.originalEvent.targetTouches[0].pageX
e.pageY = e.originalEvent.targetTouches[0].pageY
e.speedX = previousEvent?e.pageX - previousEvent.pageX:0
e.speedY = previousEvent?e.pageY - previousEvent.pageY:0
if (e.originalEvent.targetTouches.length == 2) {
e.speedX = e.speedX / 4
e.speedY = e.speedY / 4
}
e.deltaX = previousEvent?e.speedX + previousEvent.deltaX:0
e.deltaY = previousEvent?e.speedY + previousEvent.deltaY:0
e.offsetX = previousEvent&&!e.shiftKey?previousEvent.offsetX+e.speedX:e.pageX-getOffset(e.target).left
e.offsetY = previousEvent&&!e.shiftKey?previousEvent.offsetY+e.speedY:e.pageY-getOffset(e.target).top
element.trigger("drag",e)
previousEvent = e
})
element.on("touchend.drag", touchend)
element.on("touchcancel.drag", touchend)
},
teardown: function() {
var element = $(this)
element.off(".drag")
}
}
$.fn.delegateDrag = function(action) {
if (action=='disable') {
this.off('.delegateDrag')
} else {
var target = null
this.on('drag.delegateDrag',function(ev,dd){
dd.target = dd.originalEvent&&dd.originalEvent.changedTouches?
document.elementFromPoint(dd.originalEvent.changedTouches[0].clientX, dd.originalEvent.changedTouches[0].clientY)
:dd.target
if (target!=dd.target) {
$(target).trigger('dragend',[dd])
$(dd.target).trigger('draginit',[dd])
} else {
$(dd.target).trigger('draginit',[dd])
// multi touch hanlder
if (events.touch) {
var targets = {},
previousTouches = {},
touchTapTimer = false
this.on(events.start,function(e){
// e.stopPropagation()
var oE = e.originalEvent
for (i in oE.changedTouches) {
if (isNaN(i)) continue
var touch = oE.changedTouches[i]
targets[i] = $(touch.target)
previousTouches[i] = touch
touch.speedX = 0
touch.speedY = 0
touch.deltaX = 0
touch.deltaY = 0
var off = getOffset(touch.target)
touch.offsetX = touch.pageX-off.left
touch.offsetY = touch.pageY-off.top
targets[i].triggerHandler('draginit',[touch,e])
}
if (!touchTapTimer&&oE.touches.length==1) {
touchTapTimer = setTimeout(function(){
$(oE.changedTouches[0].target).triggerHandler('fake-right-click',oE.changedTouches[0])
},600)
} else {
clearTimeout(touchTapTimer)
touchTapTimer = false
}
target = dd.target
})
this.on('dragend.delegateDrag',function(){
target = null
this.on(events.move,function(e){
// e.stopPropagation()
var oE = e.originalEvent
if (touchTapTimer) {
clearTimeout(touchTapTimer)
touchTapTimer = false
}
for (i in oE.changedTouches) {
if (isNaN(i)) continue
var touch = oE.changedTouches[i]
touch.speedX = touch.pageX - previousTouches[i].pageX
touch.speedY = touch.pageY - previousTouches[i].pageY
touch.deltaX = touch.speedX + previousTouches[i].deltaX
touch.deltaY = touch.speedY + previousTouches[i].deltaY
touch.offsetX = previousTouches[i].offsetX+touch.speedX
touch.offsetY = previousTouches[i].offsetY+touch.speedY
if (traversing || TRAVERSING) {
targets[i] = $(document.elementFromPoint(touch.clientX, touch.clientY))
var previousTarget = document.elementFromPoint(previousTouches[i].clientX, previousTouches[i].clientY)
if (targets[i][0]!=previousTarget) {
var off = getOffset(targets[i][0])
touch.offsetX = touch.pageX-off.left
touch.offsetY = touch.pageY-off.top
$(previousTarget).trigger('dragend',[touch,e])
}
e.preventDefault()
if (this.contains(targets[i][0])) targets[i].triggerHandler('draginit',[touch,e])
} else {
targets[i].triggerHandler('drag',[touch,e])
}
previousTouches[i] = touch
}
})
$document.on(events.stop,function(e){
e.stopPropagation()
var oE = e.originalEvent
for (i in oE.changedTouches) {
if (isNaN(i)) continue
var touch = oE.changedTouches[i]
$(oE.changedTouches[i].target).trigger('dragend',[touch,e])
previousTouches[i] = touch
}
if (touchTapTimer) {
clearTimeout(touchTapTimer)
touchTapTimer = false
}
})
}
return this
}
$document.handleDragging()
if (events.touch) {
$document.on('mousedown',function(e){
if (e.toElement.tagName!='INPUT') return false
})
}
})(jQuery)

View file

@ -1,4 +1,5 @@
(function ($) {
var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
;(function ($) {
$.fn.fakeInput = function(options) {
var settings = $.extend({
@ -77,9 +78,9 @@
i.blur(function(){
self.attr('tabindex','0')
i.remove()
$(document).off('mousedown.fakeInput touchstart.fakeInput')
$(document).off('.fakeInput')
})
$(document).on('mousedown.fakeInput touchstart.fakeInput',function(){
$(document).on(startEvent+'.fakeInput',function(){
i.blur()
})

View file

@ -8,10 +8,6 @@
align-items: center;
flex-shrink: 0;
.input {
margin-top:-5rem;
}
&.compact {
.pips {
display: none;
@ -46,7 +42,7 @@
overflow: hidden;
.knob-wrapper {
padding:15rem 0 20rem;
padding:15rem 0 15rem;
margin: 0 auto;
width: 100%;
height: 100%;

View file

@ -87,6 +87,7 @@
bottom:0;
background-color: red;
opacity: .75;
pointer-events: none;
&:before, &:after {
content:"";
position: absolute;
@ -142,6 +143,7 @@
bottom:0;
opacity: 0.5;
background:transparent linear-gradient(to left, #F00, #FF0080, #F0F, #8000FF, #00F, #0080FF, #0FF, #00FF80, #0F0, #80FF00, #FF0, #FF8000, #F00) repeat scroll 0% 0%;
pointer-events: none;
}
&:active {
cursor: -webkit-grabbing;

View file

@ -15,7 +15,7 @@
"socket.io-client": "1.4.5",
"socketio-wildcard": "0.3.0",
"express": "4.13.4",
"electron-prebuilt": "0.37.4"
"electron-prebuilt": "0.37.5"
},
"devDependencies": {
"browserify": "13.0.0",