Skip to content

Commit d084f22

Browse files
committed
Updated page pointer to use a fixed positioning system
Avoids interferance with elements that have their own overflow behaviour such as table cells. Related to #3774
1 parent ff3fb2e commit d084f22

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

resources/js/components/pointer.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ class Pointer {
1616
this.pointerModeLink = true;
1717
this.pointerSectionId = '';
1818

19-
this.init();
2019
this.setupListeners();
21-
}
22-
23-
init() {
24-
// Set up pointer by removing it
25-
this.container.parentNode.removeChild(this.container);
2620

2721
// Set up clipboard
2822
new Clipboard(this.container.querySelector('button'));
@@ -52,8 +46,7 @@ class Pointer {
5246
// Hide pointer when clicking away
5347
DOM.onEvents(document.body, ['click', 'focus'], event => {
5448
if (!this.showing || this.isSelection) return;
55-
this.container.parentElement.removeChild(this.container);
56-
this.showing = false;
49+
this.hidePointer();
5750
});
5851

5952
// Show pointer when selecting a single block of tagged content
@@ -67,6 +60,11 @@ class Pointer {
6760
});
6861
}
6962

63+
hidePointer() {
64+
this.container.style.display = null;
65+
this.showing = false;
66+
}
67+
7068
/**
7169
* Move and display the pointer at the given element, targeting the given screen x-position if possible.
7270
* @param {Element} element
@@ -80,23 +78,29 @@ class Pointer {
8078
this.pointerSectionId = element.id;
8179
this.updateForTarget(element);
8280

83-
element.parentNode.insertBefore(this.container, element);
8481
this.container.style.display = 'block';
82+
const targetBounds = element.getBoundingClientRect();
83+
const pointerBounds = this.container.getBoundingClientRect();
84+
85+
const xTarget = Math.min(Math.max(xPosition, targetBounds.left), targetBounds.right);
86+
const xOffset = xTarget - (pointerBounds.width / 2);
87+
const yOffset = (targetBounds.top - pointerBounds.height) - 16;
88+
89+
this.container.style.left = `${xOffset}px`;
90+
this.container.style.top = `${yOffset}px`;
91+
8592
this.showing = true;
8693
this.isSelection = true;
8794

88-
// Set pointer to sit near mouse-up position
89-
requestAnimationFrame(() => {
90-
const bookMarkBounds = element.getBoundingClientRect();
91-
const pointerLeftOffset = Math.max((xPosition - bookMarkBounds.left - 164), 0);
92-
const pointerLeftOffsetPercent = (pointerLeftOffset / bookMarkBounds.width) * 100;
95+
setTimeout(() => {
96+
this.isSelection = false;
97+
}, 100);
9398

94-
this.container.children[0].style.left = pointerLeftOffsetPercent + '%';
95-
96-
setTimeout(() => {
97-
this.isSelection = false;
98-
}, 100);
99-
});
99+
const scrollListener = () => {
100+
this.hidePointer();
101+
window.removeEventListener('scroll', scrollListener, {passive: true});
102+
};
103+
window.addEventListener('scroll', scrollListener, {passive: true});
100104
}
101105

102106
/**

resources/sass/_pages.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ body.tox-fullscreen, body.markdown-fullscreen {
182182

183183
// Page content pointers
184184
.pointer-container {
185-
position: relative;
185+
position: fixed;
186186
display: none;
187187
left: 0;
188188
z-index: 10;
@@ -196,11 +196,8 @@ body.tox-fullscreen, body.markdown-fullscreen {
196196
padding: $-s $-s;
197197
border-radius: 4px;
198198
box-shadow: 0 0 12px 1px rgba(0, 0, 0, 0.1);
199-
position: absolute;
200-
top: -60px;
201199
@include lightDark(background-color, #fff, #333);
202200
width: 275px;
203-
z-index: 55;
204201

205202
&.is-page-editable {
206203
width: 328px;

resources/views/pages/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
<main class="content-wrap card">
2020
<div class="page-content clearfix" page-display="{{ $page->id }}">
21-
@include('pages.parts.pointer', ['page' => $page])
2221
@include('pages.parts.page-display')
2322
</div>
23+
@include('pages.parts.pointer', ['page' => $page])
2424
</main>
2525

2626
@include('entities.sibling-navigation', ['next' => $next, 'previous' => $previous])

0 commit comments

Comments
 (0)