jekyll-hover-popup 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3879f84fe0d069980162be1c9fd4f17487b8fc5042cc66fc79b21275846df9b
4
- data.tar.gz: e4b68417074e6323c07116488f023716a02e64bf0c8e15f6433ab1f380256349
3
+ metadata.gz: '093a8fdc8081648557c5767ccda5e569f65755d513df938c8c96b02bf8653348'
4
+ data.tar.gz: 293393bc00ed5a9e096fb670b6c1468cf83450403db44f1cdd74258e1e1684c5
5
5
  SHA512:
6
- metadata.gz: 8dc8ec185e717401dc9d995e20e88f25f59d59e4a08e0dd95e09938ca6c689bef253a30bf5df656e173379054fe5265375c6969747307dd2ab1b5d8afbf826db
7
- data.tar.gz: 005116b6f088deb3f00ebbae788e8db22aee7074393f7232dd5e451e7e03e5d82d9e156b448f2e55e6fffc5bde7bd2bc34528240395c03729d77132a82e8fb92
6
+ metadata.gz: 258b38b8e03cdb86f0f1c1ac7c62dc3b56e6046463a28128dd3c7049c0681bd1f0bc609e4a8f357cf3d66c4ca1c8312a6cbc4b72f019fe8392f56ac8c27ff2e6
7
+ data.tar.gz: '09ab116eea32d0d8f310ea74b75466a19dc6c279ea4b551d22f4cedb8c8574f30c139305433c54283cd131b5291dafa10aea3458abe4165fd8a36ca21ac5dedf'
@@ -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);
@@ -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 (position && position.isPreventFlicker && position.bcr) {
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(contentEl);
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;
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module HoverPopup
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-hover-popup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - directsun