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:
parent
3207b835ba
commit
0a868a71b5
20 changed files with 502 additions and 322 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget.value
|
||||
}
|
||||
|
||||
widget.delegateDrag()
|
||||
widget.handleDragging(true)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget.value
|
||||
}
|
||||
|
||||
widget.delegateDrag()
|
||||
widget.handleDragging(true)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ module.exports.create = function(widgetData,container) {
|
|||
return widget.value
|
||||
}
|
||||
|
||||
widget.delegateDrag()
|
||||
widget.handleDragging(true)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue