Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6224] XB drag-scroll up or down fails when preview markup interferes #3442

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion ui/guest/src/react/GuestProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,39 @@ export function GuestProxy() {
document.querySelectorAll<HTMLElement>('[data-craftercms-model-id]').forEach(registerElement);
});

let stopDragScroll = false;
const handler: JQuery.EventHandlerBase<any, any> = (e: Event): void => {
if (e.type === 'dragover') {
onDragHandler(e);
}
const record = ElementRegistry.fromElement(e.currentTarget as Element);
if (notNullOrUndefined(record)) {
persistenceRef.current.onEvent(e, record.id);
}
};
const onDragHandler: JQuery.EventHandlerBase<any, any> = (e): void => {
const dragScroll = function (step) {
var scrollY = $(window).scrollTop();
$(window).scrollTop(scrollY + step);
if (!stopDragScroll) {
setTimeout(function () {
dragScroll(step);
}, 20);
}
};

stopDragScroll = true;
if (e.originalEvent.clientY < 150) {
stopDragScroll = false;
dragScroll(-1);
}
const windowHeight = document.querySelector('html').clientHeight;
const windowWidth = document.querySelector('html').clientWidth;
if (e.originalEvent.clientX <= windowWidth && e.originalEvent.clientY > windowHeight - 150) {
stopDragScroll = false;
dragScroll(1);
}
};

$(document)
.on('mouseover', '[data-craftercms-model-id]', handler)
Expand All @@ -216,7 +243,9 @@ export function GuestProxy() {
.on('drop', '[data-craftercms-model-id]', handler)
.on('dragend', '[data-craftercms-model-id]', handler)
.on('click', '[data-craftercms-model-id]', handler)
.on('dblclick', '[data-craftercms-model-id]', handler);
.on('dblclick', '[data-craftercms-model-id]', handler)
.on('drag', '[data-craftercms-model-id]', (e) => onDragHandler(e, window, stopDragScroll))
.on('dragend', '[data-craftercms-model-id]', () => (stopDragScroll = true));

const sub = operations$.subscribe((op: Operation) => {
switch (op.type) {
Expand Down