mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 14:52:46 +08:00
FIX: reorder custom sidebar links on touch screen (#20856)
Previously, reorder on touch screens was disabled https://github.com/discourse/discourse/pull/20769. This PR enables it again. However, link has to be hold for 300 ms to enable drag&drop. Otherwise, normal scroll is performed.
This commit is contained in:
parent
aa09a78d14
commit
f5fadc3149
|
@ -17,15 +17,11 @@
|
||||||
@prefixValue={{link.icon}}
|
@prefixValue={{link.icon}}
|
||||||
@href={{link.value}}
|
@href={{link.value}}
|
||||||
@class={{link.linkDragCss}}
|
@class={{link.linkDragCss}}
|
||||||
{{(if
|
{{draggable
|
||||||
this.canReorder
|
|
||||||
(modifier
|
|
||||||
"draggable"
|
|
||||||
didStartDrag=link.didStartDrag
|
didStartDrag=link.didStartDrag
|
||||||
didEndDrag=link.didEndDrag
|
didEndDrag=link.didEndDrag
|
||||||
dragMove=link.dragMove
|
dragMove=link.dragMove
|
||||||
)
|
}}
|
||||||
)}}
|
|
||||||
/>
|
/>
|
||||||
{{else}}
|
{{else}}
|
||||||
<Sidebar::SectionLink
|
<Sidebar::SectionLink
|
||||||
|
@ -37,15 +33,11 @@
|
||||||
@prefixType="icon"
|
@prefixType="icon"
|
||||||
@prefixValue={{link.icon}}
|
@prefixValue={{link.icon}}
|
||||||
@class={{link.linkDragCss}}
|
@class={{link.linkDragCss}}
|
||||||
{{(if
|
{{draggable
|
||||||
this.canReorder
|
|
||||||
(modifier
|
|
||||||
"draggable"
|
|
||||||
didStartDrag=link.didStartDrag
|
didStartDrag=link.didStartDrag
|
||||||
didEndDrag=link.didEndDrag
|
didEndDrag=link.didEndDrag
|
||||||
dragMove=link.dragMove
|
dragMove=link.dragMove
|
||||||
)
|
}}
|
||||||
)}}
|
|
||||||
/>
|
/>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -28,12 +28,6 @@ export default class SidebarUserCustomSections extends Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get canReorder() {
|
|
||||||
return document
|
|
||||||
.getElementsByTagName("html")[0]
|
|
||||||
.classList.contains("no-touch");
|
|
||||||
}
|
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
_refresh() {
|
_refresh() {
|
||||||
return ajax("/sidebar_sections.json", {}).then((json) => {
|
return ajax("/sidebar_sections.json", {}).then((json) => {
|
||||||
|
|
|
@ -25,7 +25,8 @@ export default class SectionLink {
|
||||||
@bind
|
@bind
|
||||||
didStartDrag(event) {
|
didStartDrag(event) {
|
||||||
// 0 represents left button of the mouse
|
// 0 represents left button of the mouse
|
||||||
if (event.button === 0) {
|
if (event.button === 0 || event.targetTouches) {
|
||||||
|
this.startMouseY = this.#calcMouseY(event);
|
||||||
this.willDrag = true;
|
this.willDrag = true;
|
||||||
discourseLater(() => {
|
discourseLater(() => {
|
||||||
this.delayedStart(event);
|
this.delayedStart(event);
|
||||||
|
@ -34,12 +35,17 @@ export default class SectionLink {
|
||||||
}
|
}
|
||||||
delayedStart(event) {
|
delayedStart(event) {
|
||||||
if (this.willDrag) {
|
if (this.willDrag) {
|
||||||
this.mouseY = event.y;
|
const currentMouseY = this.#calcMouseY(event);
|
||||||
|
if (currentMouseY === this.startMouseY) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
this.mouseY = this.#calcMouseY(event);
|
||||||
this.linkDragCss = "drag";
|
this.linkDragCss = "drag";
|
||||||
this.section.disable();
|
this.section.disable();
|
||||||
this.drag = true;
|
this.drag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
didEndDrag() {
|
didEndDrag() {
|
||||||
|
@ -53,10 +59,13 @@ export default class SectionLink {
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
dragMove(event) {
|
dragMove(event) {
|
||||||
|
this.startMouseY = this.#calcMouseY(event);
|
||||||
if (!this.drag) {
|
if (!this.drag) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const currentMouseY = event.y;
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
const currentMouseY = this.#calcMouseY(event);
|
||||||
const distance = currentMouseY - this.mouseY;
|
const distance = currentMouseY - this.mouseY;
|
||||||
if (!this.linkHeight) {
|
if (!this.linkHeight) {
|
||||||
this.linkHeight = document.getElementsByClassName(
|
this.linkHeight = document.getElementsByClassName(
|
||||||
|
@ -76,4 +85,10 @@ export default class SectionLink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#calcMouseY(event) {
|
||||||
|
return Math.round(
|
||||||
|
event.targetTouches ? event.targetTouches[0].clientY : event.y
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,8 +287,10 @@ export default class TopicTimelineScrollArea extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
dragMove(e) {
|
dragMove(event) {
|
||||||
this.updatePercentage(e);
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
this.updatePercentage(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
|
|
|
@ -29,8 +29,6 @@ export default class DraggableModifier extends Modifier {
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
dragMove(e) {
|
dragMove(e) {
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
if (!this.hasStarted) {
|
if (!this.hasStarted) {
|
||||||
this.hasStarted = true;
|
this.hasStarted = true;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,15 @@
|
||||||
cursor: move;
|
cursor: move;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
-webkit-touch-callout: none !important;
|
||||||
|
-webkit-user-select: none !important;
|
||||||
|
-moz-user-select: none !important;
|
||||||
|
-ms-user-select: none !important;
|
||||||
|
-o-user-select: none !important;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar-section-wrapper.disabled {
|
.sidebar-section-wrapper.disabled {
|
||||||
a {
|
a {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
@ -38,3 +47,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.discourse-touch {
|
||||||
|
.sidebar-custom-sections {
|
||||||
|
a:hover {
|
||||||
|
background: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user