mirror of
https://github.com/discourse/discourse.git
synced 2025-04-01 21:26:36 +08:00
DEV: adds touchMove
support for widgets (#22635)
No tests as widgets are in maintenance mode until we can remove it, and this is also hard to test.
This commit is contained in:
parent
c042978778
commit
a610c86302
@ -17,6 +17,7 @@ const MOUSE_OVER_ATTRIBUTE_NAME = "_discourse_mouse_over_widget";
|
||||
const MOUSE_OUT_ATTRIBUTE_NAME = "_discourse_mouse_out_widget";
|
||||
const TOUCH_START_ATTRIBUTE_NAME = "_discourse_touch_start_widget";
|
||||
const TOUCH_END_ATTRIBUTE_NAME = "_discourse_touch_end_widget";
|
||||
const TOUCH_MOVE_ATTRIBUTE_NAME = "_discourse_touch_move_widget";
|
||||
|
||||
class WidgetBaseHook {
|
||||
constructor(widget) {
|
||||
@ -73,6 +74,9 @@ export const WidgetTouchEndHook = buildHook(TOUCH_END_ATTRIBUTE_NAME);
|
||||
function touchStartHandler(e) {
|
||||
return e.currentTarget[TOUCH_START_ATTRIBUTE_NAME].touchStart(e);
|
||||
}
|
||||
function touchMoveHandler(e) {
|
||||
return e.currentTarget[TOUCH_MOVE_ATTRIBUTE_NAME].touchMove(e);
|
||||
}
|
||||
|
||||
export class WidgetTouchStartHook extends WidgetBaseHook {
|
||||
hook(node, propertyName, previousValue) {
|
||||
@ -92,6 +96,24 @@ export class WidgetTouchStartHook extends WidgetBaseHook {
|
||||
}
|
||||
}
|
||||
}
|
||||
export class WidgetTouchMoveHook extends WidgetBaseHook {
|
||||
hook(node, propertyName, previousValue) {
|
||||
node[TOUCH_MOVE_ATTRIBUTE_NAME] = this.widget;
|
||||
if (!previousValue) {
|
||||
// Element added to DOM
|
||||
node.addEventListener("touchmove", touchMoveHandler, {
|
||||
passive: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
unhook(node, propertyName, newValue) {
|
||||
if (!newValue) {
|
||||
// Element removed from DOM
|
||||
node.removeEventListener("touchmove", touchMoveHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _currentlyDraggingElement;
|
||||
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
WidgetMouseOverHook,
|
||||
WidgetMouseUpHook,
|
||||
WidgetTouchEndHook,
|
||||
WidgetTouchMoveHook,
|
||||
WidgetTouchStartHook,
|
||||
} from "discourse/widgets/hooks";
|
||||
import DecoratorHelper from "discourse/widgets/decorator-helper";
|
||||
@ -481,6 +482,10 @@ export default class Widget {
|
||||
properties["widget-touch-end"] = new WidgetTouchEndHook(this);
|
||||
}
|
||||
|
||||
if (this.touchMove) {
|
||||
properties["widget-touch-move"] = new WidgetTouchMoveHook(this);
|
||||
}
|
||||
|
||||
const attributes = properties["attributes"] || {};
|
||||
properties.attributes = attributes;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user