mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Suppress only the synchronous click that touch-punch emits after a jQuery UI sortable drag. Ordinary taps and later clicks retain their normal behavior. Add positive and negative unit coverage plus a real fast-touch drag browser regression. Thanks to xator91 and xet7 ! Fixes #5421,
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const {
|
|
runTouchEndWithoutPostDragClick,
|
|
} = require('../models/lib/touchDragClickGuard');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed++;
|
|
console.log(` ok - ${name}`);
|
|
}
|
|
|
|
test('a completed fast drag suppresses the touch bridge click', () => {
|
|
const target = new EventTarget();
|
|
let navigations = 0;
|
|
|
|
runTouchEndWithoutPostDragClick(true, target, () => {
|
|
const allowed = target.dispatchEvent(new Event('click', { cancelable: true }));
|
|
if (allowed) navigations++;
|
|
});
|
|
|
|
assert.strictEqual(navigations, 0);
|
|
});
|
|
|
|
test('a normal tap keeps its click', () => {
|
|
const target = new EventTarget();
|
|
let navigations = 0;
|
|
|
|
runTouchEndWithoutPostDragClick(false, target, () => {
|
|
const allowed = target.dispatchEvent(new Event('click', { cancelable: true }));
|
|
if (allowed) navigations++;
|
|
});
|
|
|
|
assert.strictEqual(navigations, 1);
|
|
});
|
|
|
|
test('an independent click after a drag is not suppressed', () => {
|
|
const target = new EventTarget();
|
|
let navigations = 0;
|
|
|
|
runTouchEndWithoutPostDragClick(true, target, () => {
|
|
const allowed = target.dispatchEvent(new Event('click', { cancelable: true }));
|
|
if (allowed) navigations++;
|
|
});
|
|
const allowed = target.dispatchEvent(new Event('click', { cancelable: true }));
|
|
if (allowed) navigations++;
|
|
|
|
assert.strictEqual(navigations, 1);
|
|
});
|
|
|
|
test('the touch-punch adapter guards its click while a sortable is active', () => {
|
|
const source = fs.readFileSync(
|
|
path.join(__dirname, '../client/lib/jquery-ui.js'),
|
|
'utf8',
|
|
);
|
|
assert.match(source, /const wasDragging = this\._mouseStarted === true/);
|
|
assert.match(source, /runTouchEndWithoutPostDragClick\(/);
|
|
assert.match(source, /touchEnd\.call\(this, event\)/);
|
|
});
|
|
|
|
console.log(`\n${passed} passing`);
|