jekyll-hover-popup 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -11
- data/assets/jekyll-hover-popup/hover_popup.css +20 -0
- data/assets/jekyll-hover-popup/hover_popup.js +90 -5
- data/lib/jekyll/hover_popup/hooks.rb +2 -2
- data/lib/jekyll/hover_popup/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cdae0cb64015858986ffe6c6dc11d44947b4e172dee08bccd68d191230416b26
|
|
4
|
+
data.tar.gz: af148150f8a1890b082adbccc2c4665a56dacbad3eea581608dd02c0cbee8f36
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3192b0edd3563b6b267740ca86eff70b040b269d30aff9005366902be46d6f11026644757ea3f010296aa610f91f4969426e82c0bb1860ed473b7ed0cd07f44
|
|
7
|
+
data.tar.gz: 203ad982a1a4dd62680ee9798179a224835fca23322b2744e1239d09dfcce0ac8a63e63e574f90a58acf893a43cd69204015160ba37d229b2d5d1a9f40076d30
|
data/README.md
CHANGED
|
@@ -6,14 +6,15 @@ Inspired by the hover window behavior in [5etools](https://github.com/5etools/5e
|
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- Hover an internal link to
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
9
|
+
- Hover over an internal link to see a reference preview
|
|
10
|
+
- Persist windows by holding the SHIFT key
|
|
11
|
+
- Close all windows by holding CTRL while closing one
|
|
12
|
+
- Minimize windows by double clicking the title bar
|
|
13
|
+
- Navigate to an entry later by clicking the link in the title bar
|
|
14
|
+
- Eight point window resize
|
|
15
|
+
- Exposes `window.JekyllHoverPopup` for other plugins
|
|
16
|
+
|
|
17
|
+
<img width="640" height="360" alt="window-preview-demo-2" src="https://github.com/user-attachments/assets/1f8f60ad-ad2a-4418-ad0f-0494f4e43faf" />
|
|
17
18
|
|
|
18
19
|
## Install
|
|
19
20
|
|
|
@@ -41,10 +42,12 @@ hover_popup:
|
|
|
41
42
|
enabled: true
|
|
42
43
|
assets_path: /assets/jekyll-hover-popup
|
|
43
44
|
hover_delay_ms: 0
|
|
44
|
-
nav_hover_preview:
|
|
45
|
+
nav_hover_preview: false
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
Add a `hover_delay_ms` to delay the preview window creation
|
|
49
|
+
|
|
50
|
+
Set `nav_hover_preview: true` to enable hover previews for links inside navigation elements (`.site-nav`, `nav`, `[role="navigation"]`, etc.).
|
|
48
51
|
|
|
49
52
|
## JavaScript API
|
|
50
53
|
|
|
@@ -72,4 +75,4 @@ window.JekyllHoverPopup.openContent({
|
|
|
72
75
|
|
|
73
76
|
## License
|
|
74
77
|
|
|
75
|
-
MIT
|
|
78
|
+
[MIT](LICENSE)
|
|
@@ -72,6 +72,26 @@
|
|
|
72
72
|
cursor: move;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
.jhp-hwin__rollup {
|
|
76
|
+
display: grid;
|
|
77
|
+
grid-template-rows: 1fr;
|
|
78
|
+
transition: grid-template-rows 220ms ease;
|
|
79
|
+
min-height: 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.jhp-hwin--rolled-up .jhp-hwin__rollup {
|
|
83
|
+
grid-template-rows: 0fr;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.jhp-hwin__rollup-inner {
|
|
87
|
+
overflow: hidden;
|
|
88
|
+
min-height: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.jhp-hwin--rolled-up .jhp-resize {
|
|
92
|
+
display: none;
|
|
93
|
+
}
|
|
94
|
+
|
|
75
95
|
.jhp-border--bottom {
|
|
76
96
|
min-height: 3px;
|
|
77
97
|
border-top: 1px solid var(--jhp-border-color);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const config = window.__JHP_CONFIG__ || {};
|
|
5
5
|
const HOVER_DELAY_MS = Number(config.hoverDelayMs) || 0;
|
|
6
|
-
const NAV_HOVER_PREVIEW = config.navHoverPreview
|
|
6
|
+
const NAV_HOVER_PREVIEW = config.navHoverPreview === true;
|
|
7
7
|
const TRANSIENT_TITLE_HINT = "SHIFT to persist";
|
|
8
8
|
const MAX_VIEWPORT_WIDTH = 0.92;
|
|
9
9
|
const MAX_VIEWPORT_HEIGHT = 0.92;
|
|
@@ -103,11 +103,17 @@
|
|
|
103
103
|
return new URL(href, base);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
function isDiceTrayLink(anchor) {
|
|
107
|
+
if (!anchor) return false;
|
|
108
|
+
return anchor.classList.contains("dice-tray-roll") || anchor.hasAttribute("data-dice");
|
|
109
|
+
}
|
|
110
|
+
|
|
106
111
|
function rewriteContentLinks(content, basePageUrl) {
|
|
107
112
|
if (!content || !basePageUrl) return;
|
|
108
113
|
|
|
109
114
|
content.querySelectorAll("a[href]").forEach((anchor) => {
|
|
110
115
|
if (anchor.closest(".jhp-hwin__actions")) return;
|
|
116
|
+
if (isDiceTrayLink(anchor)) return;
|
|
111
117
|
|
|
112
118
|
const href = anchor.getAttribute("href");
|
|
113
119
|
if (!href || href.startsWith("mailto:") || href.startsWith("javascript:")) return;
|
|
@@ -165,6 +171,7 @@
|
|
|
165
171
|
|
|
166
172
|
function isInternalPageLink(anchor) {
|
|
167
173
|
if (!anchor || anchor.closest(".jhp-hwin__actions")) return false;
|
|
174
|
+
if (isDiceTrayLink(anchor)) return false;
|
|
168
175
|
if (isHeadingPermalink(anchor)) return false;
|
|
169
176
|
if (!NAV_HOVER_PREVIEW && isNavLink(anchor)) return false;
|
|
170
177
|
|
|
@@ -419,7 +426,12 @@
|
|
|
419
426
|
winEl.style.top = `${Math.max(0, screenH - rect.height - 8)}px`;
|
|
420
427
|
}
|
|
421
428
|
|
|
422
|
-
if (
|
|
429
|
+
if (
|
|
430
|
+
!winEl.classList.contains("jhp-hwin--rolled-up") &&
|
|
431
|
+
position &&
|
|
432
|
+
position.isPreventFlicker &&
|
|
433
|
+
position.bcr
|
|
434
|
+
) {
|
|
423
435
|
rect = winEl.getBoundingClientRect();
|
|
424
436
|
const overlap =
|
|
425
437
|
rect.left < position.bcr.right &&
|
|
@@ -475,6 +487,8 @@
|
|
|
475
487
|
}
|
|
476
488
|
|
|
477
489
|
function setupWindowInteraction(winEl, header, contentEl, windowMeta) {
|
|
490
|
+
let suppressDragUntil = 0;
|
|
491
|
+
|
|
478
492
|
const drag = {
|
|
479
493
|
type: DRAG_NONE,
|
|
480
494
|
startX: 0,
|
|
@@ -486,6 +500,8 @@
|
|
|
486
500
|
};
|
|
487
501
|
|
|
488
502
|
function beginInteraction(evt, type) {
|
|
503
|
+
if (winEl.classList.contains("jhp-hwin--rolled-up") && type !== DRAG_MOVE) return;
|
|
504
|
+
|
|
489
505
|
drag.type = type;
|
|
490
506
|
drag.startX = getClientX(evt);
|
|
491
507
|
drag.startY = getClientY(evt);
|
|
@@ -601,10 +617,21 @@
|
|
|
601
617
|
if (winEl.dataset.perm !== "true") return;
|
|
602
618
|
if (evt.button !== 0) return;
|
|
603
619
|
if (evt.target.closest(".jhp-hwin__btn")) return;
|
|
620
|
+
if (Date.now() < suppressDragUntil) return;
|
|
604
621
|
evt.preventDefault();
|
|
605
622
|
beginInteraction(evt, DRAG_MOVE);
|
|
606
623
|
});
|
|
607
624
|
|
|
625
|
+
header.addEventListener("dblclick", (evt) => {
|
|
626
|
+
if (winEl.dataset.perm !== "true") return;
|
|
627
|
+
if (evt.target.closest(".jhp-hwin__btn")) return;
|
|
628
|
+
evt.preventDefault();
|
|
629
|
+
evt.stopPropagation();
|
|
630
|
+
suppressDragUntil = Date.now() + 300;
|
|
631
|
+
if (windowMeta.endInteraction) windowMeta.endInteraction();
|
|
632
|
+
windowMeta.toggleRollup();
|
|
633
|
+
});
|
|
634
|
+
|
|
608
635
|
addResizeHandle(winEl, "jhp-resize-n", DRAG_N, beginInteraction);
|
|
609
636
|
addResizeHandle(winEl, "jhp-resize-ne", DRAG_NE, beginInteraction);
|
|
610
637
|
addResizeHandle(winEl, "jhp-resize-e", DRAG_E, beginInteraction);
|
|
@@ -644,6 +671,7 @@
|
|
|
644
671
|
}
|
|
645
672
|
|
|
646
673
|
updateTitleDisplay();
|
|
674
|
+
if (isPermanent) topBorder.title = "Double-click to roll up or down";
|
|
647
675
|
|
|
648
676
|
const actions = document.createElement("div");
|
|
649
677
|
actions.className = "jhp-hwin__actions";
|
|
@@ -673,20 +701,72 @@
|
|
|
673
701
|
const bottomBorder = document.createElement("div");
|
|
674
702
|
bottomBorder.className = "jhp-border jhp-border--bottom";
|
|
675
703
|
|
|
704
|
+
const rollupInner = document.createElement("div");
|
|
705
|
+
rollupInner.className = "jhp-hwin__rollup-inner";
|
|
706
|
+
rollupInner.appendChild(contentEl);
|
|
707
|
+
rollupInner.appendChild(bottomBorder);
|
|
708
|
+
|
|
709
|
+
const rollupEl = document.createElement("div");
|
|
710
|
+
rollupEl.className = "jhp-hwin__rollup";
|
|
711
|
+
rollupEl.appendChild(rollupInner);
|
|
712
|
+
|
|
676
713
|
winEl.appendChild(topBorder);
|
|
677
|
-
winEl.appendChild(
|
|
678
|
-
winEl.appendChild(bottomBorder);
|
|
714
|
+
winEl.appendChild(rollupEl);
|
|
679
715
|
document.body.appendChild(winEl);
|
|
680
716
|
|
|
717
|
+
let rolledUp = false;
|
|
718
|
+
let savedRollupStyles = null;
|
|
719
|
+
|
|
720
|
+
function captureRollupStyles() {
|
|
721
|
+
return {
|
|
722
|
+
contentHeight: contentEl.style.height,
|
|
723
|
+
contentMaxHeight: contentEl.style.maxHeight,
|
|
724
|
+
winWidth: winEl.style.width,
|
|
725
|
+
winMaxWidth: winEl.style.maxWidth,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function restoreRollupStyles() {
|
|
730
|
+
if (!savedRollupStyles) return;
|
|
731
|
+
contentEl.style.height = savedRollupStyles.contentHeight;
|
|
732
|
+
contentEl.style.maxHeight = savedRollupStyles.contentMaxHeight;
|
|
733
|
+
winEl.style.width = savedRollupStyles.winWidth;
|
|
734
|
+
winEl.style.maxWidth = savedRollupStyles.winMaxWidth;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function setRolledUp(value) {
|
|
738
|
+
rolledUp = value;
|
|
739
|
+
winEl.classList.toggle("jhp-hwin--rolled-up", rolledUp);
|
|
740
|
+
winEl.dataset.rolledUp = rolledUp ? "true" : "false";
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function toggleRollup() {
|
|
744
|
+
if (winEl.dataset.perm !== "true") return;
|
|
745
|
+
|
|
746
|
+
if (!rolledUp) {
|
|
747
|
+
savedRollupStyles = captureRollupStyles();
|
|
748
|
+
setRolledUp(true);
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
setRolledUp(false);
|
|
753
|
+
restoreRollupStyles();
|
|
754
|
+
adjustWindowToViewport(winEl, contentEl, null);
|
|
755
|
+
}
|
|
756
|
+
|
|
681
757
|
const windowMeta = {
|
|
682
758
|
id,
|
|
683
759
|
el: winEl,
|
|
684
760
|
contentEl,
|
|
685
761
|
endInteraction: null,
|
|
762
|
+
toggleRollup,
|
|
763
|
+
isRolledUp() {
|
|
764
|
+
return rolledUp;
|
|
765
|
+
},
|
|
686
766
|
setContent(node) {
|
|
687
767
|
contentEl.innerHTML = "";
|
|
688
768
|
contentEl.appendChild(node);
|
|
689
|
-
fitWindowToContent(winEl, contentEl);
|
|
769
|
+
if (!rolledUp) fitWindowToContent(winEl, contentEl);
|
|
690
770
|
},
|
|
691
771
|
setLoading() {
|
|
692
772
|
contentEl.innerHTML = '<div class="jhp-hwin__loading">Loading…</div>';
|
|
@@ -700,6 +780,11 @@
|
|
|
700
780
|
setPermanent(value) {
|
|
701
781
|
winEl.dataset.perm = value ? "true" : "false";
|
|
702
782
|
updateTitleDisplay();
|
|
783
|
+
topBorder.title = value ? "Double-click to roll up or down" : "";
|
|
784
|
+
if (!value && rolledUp) {
|
|
785
|
+
setRolledUp(false);
|
|
786
|
+
restoreRollupStyles();
|
|
787
|
+
}
|
|
703
788
|
},
|
|
704
789
|
setPageTitle(value) {
|
|
705
790
|
pageTitle = value;
|
|
@@ -11,7 +11,7 @@ module Jekyll
|
|
|
11
11
|
assets_path = cfg["assets_path"] || "/assets/jekyll-hover-popup"
|
|
12
12
|
assets_path = "/#{assets_path}" unless assets_path.start_with?("/")
|
|
13
13
|
hover_delay_ms = cfg["hover_delay_ms"] || 0
|
|
14
|
-
nav_hover_preview = cfg.fetch("nav_hover_preview",
|
|
14
|
+
nav_hover_preview = cfg.fetch("nav_hover_preview", false)
|
|
15
15
|
|
|
16
16
|
begin
|
|
17
17
|
doc.output = inject_assets(doc.output.to_s, assets_path: assets_path, hover_delay_ms: hover_delay_ms, nav_hover_preview: nav_hover_preview)
|
|
@@ -21,7 +21,7 @@ module Jekyll
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
def self.inject_assets(html, assets_path:, hover_delay_ms:, nav_hover_preview:
|
|
24
|
+
def self.inject_assets(html, assets_path:, hover_delay_ms:, nav_hover_preview: false)
|
|
25
25
|
return html if html.include?('data-hover-popup-root="true"')
|
|
26
26
|
|
|
27
27
|
tags = <<~HTML
|