Close menus by sliding objects on mobile

This commit is contained in:
2022-09-26 16:47:36 +02:00
parent a092b5e39a
commit c33e848e07
5 changed files with 43 additions and 17 deletions

View File

@@ -381,21 +381,46 @@ $.prototype.hoverSwap = function(sDefault, sHover)
.text(sDefault);
};
$.prototype.onSwipe = function(fCallBack){
$.prototype.onSwipe = function(fOnEnd){
return $(this)
.on('mousedown touchstart', function(e) {
var $This = $(this);
$This.data('x-down', e.pageX);
$This.data('y-down', e.pageY);
.on('dragstart', (e) => {
e.preventDefault();
})
.on('mouseup touchend',function (e) {
.on('mousedown touchstart', (e) => {
var $This = $(this);
var iDeltaX = e.pageX - $This.data('x-down');
var iDeltaY = e.pageY - $This.data('y-down');
fCallBack({x:iDeltaX, y:iDeltaY});
var oPos = getDragPosition(e);
$This.data('x-start', oPos.x);
$This.data('y-start', oPos.y);
$This.data('moving', true).addClass('moving');
})
.on('touchmove mousemove', (e) => {
var $This = $(this);
if($This.data('moving')) {
var oPos = getDragPosition(e);
$This.data('x-move', oPos.x);
$This.data('y-move', oPos.y);
}
})
.on('mouseup mouseleave touchend', (e) => {
var $This = $(this);
$This.data('moving', false).removeClass('moving');
fOnEnd({
xStart: $This.data('x-start'),
yStart: $This.data('y-start'),
xEnd: $This.data('x-move'),
yEnd: $This.data('y-move')
});
});
};
function getDragPosition(oEvent) {
let bMouse = oEvent.type.includes('mouse');
return {
x: bMouse?oEvent.pageX:oEvent.touches[0].clientX,
y: bMouse?oEvent.pageY:oEvent.touches[0].clientY
};
}
function copyTextToClipboard(text) {
if(!navigator.clipboard) {
var textArea = document.createElement('textarea');