Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions assets/js/sidebar-load-width.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function () {
try {
var leftWidth = parseInt(localStorage.getItem("left-sidebar-width"), 10);
var tocWidth = parseInt(localStorage.getItem("toc-width"), 10);
var cssStyles = "";

if (!isNaN(leftWidth)) cssStyles += "--left-sidebar-width: " + leftWidth + "px;";
if (!isNaN(tocWidth)) cssStyles += "--toc-width: " + tocWidth + "px;";

if (cssStyles) {
var styleTag = document.createElement("style");
styleTag.innerHTML = ".td-resizable-grid .td-main > .row.flex-xl-nowrap {" + cssStyles + "}";
document.head.appendChild(styleTag);
}
} catch (e) {
console.warn("LocalStorage blocked or unavailable:", e);
}
})();
115 changes: 115 additions & 0 deletions assets/js/sidebar-resizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
(function () {
document.addEventListener("DOMContentLoaded", () => {
const gridContainer = document.querySelector(".td-resizable-grid .td-main > .row.flex-xl-nowrap");
const leftResizer = document.getElementById("left-resizer");
const rightResizer = document.getElementById("right-resizer");

if (!gridContainer) return;

const LEFT_SIDEBAR_KEY = "left-sidebar-width";
const TOC_KEY = "toc-width";

const storage = {
get: (key) => {
try { return localStorage.getItem(key); }
catch (e) { return null; }
},
set: (key, value) => {
try { localStorage.setItem(key, value); }
catch (e) { return null; }
}
};

function setupResizer(resizer, type) {
resizer.addEventListener("pointerdown", (e) => {
e.preventDefault();

resizer.setPointerCapture(e.pointerId);
resizer.classList.add("is-dragging");

document.body.style.cursor = "col-resize";
document.body.style.userSelect = "none";

const startX = e.clientX;
const styles = window.getComputedStyle(gridContainer);
const gridColumns = styles.gridTemplateColumns ? styles.gridTemplateColumns.split(" ") : [];

/*
grid-template-columns over in _styles_project.scss has the following structure:

min(768px)
--left-sidebar-width --sidebar-resize-width 1fr

min(1200px)
--left-sidebar-width --sidebar-resize-width 1fr --sidebar-resize-width --toc-width;

so gridcolumns[0] targets the left sidebar and gridcolumns[4] targets the toc
*/

let initialLeftSidebarWidth, initialTocWidth;
if (gridColumns.length >= 5 && gridColumns[0] !== "none") {
initialLeftSidebarWidth = parseInt(gridColumns[0], 10);
initialTocWidth = parseInt(gridColumns[4], 10);
} else {
initialLeftSidebarWidth = parseInt(styles.getPropertyValue('--left-sidebar-width'), 10);
initialTocWidth = parseInt(styles.getPropertyValue('--toc-width'), 10);
}

const minWidth = parseInt(styles.getPropertyValue(type === "left" ? '--left-sidebar-min-width' : '--toc-min-width'), 10);

const maxWidth = parseInt(styles.getPropertyValue(type === "left" ? '--left-sidebar-max-width' : '--toc-max-width'), 10);

let currentWidth = type === "left" ? initialLeftSidebarWidth : initialTocWidth;
let ticking = false;
let animationFrameId = null;

function onPointerMove(moveEvent) {
const deltaX = moveEvent.clientX - startX;

if (type === "left") {
currentWidth = Math.max(minWidth, Math.min(maxWidth, initialLeftSidebarWidth + deltaX));
} else if (type === "right") {
currentWidth = Math.max(minWidth, Math.min(maxWidth, initialTocWidth - deltaX));
}

if (!ticking) {
animationFrameId = window.requestAnimationFrame(() => {
const varName = type === "left" ? "--left-sidebar-width" : "--toc-width";
gridContainer.style.setProperty(varName, `${currentWidth}px`);
ticking = false;
});
ticking = true;
}
}

function onPointerUp(upEvent) {
if (animationFrameId) {
window.cancelAnimationFrame(animationFrameId);
animationFrameId = null;
ticking = false;
}

resizer.releasePointerCapture(upEvent.pointerId);
resizer.classList.remove("is-dragging");

document.body.style.cursor = "";
document.body.style.userSelect = "";

const storageKey = type === "left" ? LEFT_SIDEBAR_KEY : TOC_KEY;
storage.set(storageKey, currentWidth);

document.removeEventListener("pointermove", onPointerMove);
document.removeEventListener("pointerup", onPointerUp);
document.removeEventListener("pointercancel", onPointerUp);
}

document.addEventListener("pointermove", onPointerMove);
document.addEventListener("pointerup", onPointerUp);
document.addEventListener("pointercancel", onPointerUp);
});
}

if (leftResizer) setupResizer(leftResizer, "left");
if (rightResizer) setupResizer(rightResizer, "right");
});
})();
86 changes: 86 additions & 0 deletions assets/scss/_styles_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,92 @@ a:not([href]):not([class]):hover {
}
}

// Left sidebar & Right sidebar Resize
:root {
--left-sidebar-width: 240px;
--toc-width: 240px;

--left-sidebar-min-width: 180px;
--left-sidebar-max-width: 500px;

--toc-min-width: 180px;
--toc-max-width: 400px;

--sidebar-resize-width: 5px;
}

.layout-resizer {
width: var(--sidebar-resize-width);
cursor: col-resize;
background-color: rgba(0, 0, 0, 0.03);
transition: background-color 0.15s ease;
z-index: 1; //Must be lower than the sticky header
}

.layout-resizer:hover,
.layout-resizer.is-dragging {
background-color: $primary;
}

.td-resizable-grid .td-sidebar,
.td-resizable-grid .td-sidebar-toc,
.td-resizable-grid main[role="main"] {
width: auto;
}

@media (min-width: 768px) {
.td-resizable-grid .td-main > .row.flex-xl-nowrap {
display: grid;
grid-template-columns:
var(--left-sidebar-width)
var(--sidebar-resize-width)
1fr;
}

.td-sidebar {
grid-column: 1;
grid-row: 1;
}

#left-resizer {
grid-column: 2;
grid-row: 1;
padding-left: 0 !important;
padding-right: 0 !important;
box-sizing: border-box;
}

main[role="main"] {
grid-column: 3;
grid-row: 1;
}
}

@media (min-width: 1200px) {
.td-resizable-grid .td-main > .row.flex-xl-nowrap {
display: grid;
grid-template-columns:
var(--left-sidebar-width)
var(--sidebar-resize-width)
1fr
var(--sidebar-resize-width)
var(--toc-width);
}

#right-resizer {
grid-column: 4;
grid-row: 1;
padding-left: 0 !important;
padding-right: 0 !important;
box-sizing: border-box;
}

.td-sidebar-toc {
grid-column: 5;
grid-row: 1;
}
}

// pageinfo
.pageinfo {
font-weight: $font-weight-medium;
Expand Down
12 changes: 11 additions & 1 deletion layouts/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
<header>
{{ partial "navbar.html" . }}
</header>
<div class="container-fluid td-outer">
<div class="container-fluid td-outer td-resizable-grid">
<div class="td-main">
<div class="row flex-xl-nowrap">
<aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
{{ partial "sidebar.html" . }}
</aside>

<div class="layout-resizer d-none d-md-block" id="left-resizer"></div>

<div class="layout-resizer d-none d-xl-block" id="right-resizer"></div>


<aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none">
{{ partial "page-meta-links.html" . }}
{{ partial "toc.html" . }}
{{ partial "taxonomy_terms_clouds.html" . }}
</aside>

<main class="col-12 col-md-9 col-xl-8" role="main">
{{ partial "version-banner.html" . }}
{{ if not .Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" . }}{{ end }}
Expand All @@ -27,11 +34,14 @@ <h1>Not found</h1>
<p>Please let us know about <a href="https://github.com/layer5io/docs/issues/new/choose">this issue</a> and return to the <a href="{{ "" | relURL }}">home page</a>.</p>
{{ end }}
</main>

{{ partial "load-sidebars-width.html" . }}
</div>
</div>
{{ partial "footer.html" . }}
</div>
{{ partial "scripts.html" . }}
{{ partial "sidebar-resize-script.html" }}
</body>
</html>

15 changes: 12 additions & 3 deletions layouts/docs/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@

<body class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}">
<header>{{ partial "navbar.html" . }}</header>
<div class="container-fluid td-outer">
<div class="container-fluid td-outer td-resizable-grid">
<div class="td-main">
<div class="row flex-xl-nowrap">
<aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
{{ partial "sidebar.html" . }}
</aside>

<div class="layout-resizer d-none d-md-block" id="left-resizer"></div>

<div class="layout-resizer d-none d-xl-block" id="right-resizer"></div>

<aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none">
{{ partial "page-meta-links.html" . }}
{{ partial "toc.html" . }}
{{ partial "page-meta-links.html" . }}
{{ partial "toc.html" . }}
{{ partial "taxonomy_terms_clouds.html" . }}
</aside>

<main class="col-12 col-md-9 col-xl-8" role="main">
{{ partial "version-banner.html" . }}
<div class="page-header d-flex justify-content-between align-items-center">
Expand All @@ -32,11 +38,14 @@
</div>
{{ block "main" . }}{{ end }}
</main>

{{ partial "load-sidebars-width.html" . }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This partial should be removed from the body and placed inside the <head> element (e.g., right after {{ partial "head.html" . }}) to ensure the saved sidebar widths are loaded and applied before the page is rendered, preventing layout shift.

</div>
</div>
{{ partial "footer.html" . }}
</div>
{{ partial "scripts.html" . }}
{{ partial "sidebar-resize-script.html" }}
{{ partial "image-modal.html" . }}
</body>

Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/load-sidebars-width.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- load-sidebars should be called after the HTML for the grid has been defined -->
{{ $resizerScript := resources.Get "js/sidebar-load-width.js" | minify | fingerprint }}
<script src="{{ $resizerScript.RelPermalink }}"></script>
2 changes: 2 additions & 0 deletions layouts/partials/sidebar-resize-script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ $resizerScript := resources.Get "js/sidebar-resizer.js" | minify | fingerprint }}
<script src="{{ $resizerScript.RelPermalink }}" defer></script>
11 changes: 9 additions & 2 deletions layouts/release/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}"
>
<header>{{ partial "navbar.html" . }}</header>
<div class="container-fluid td-outer">
<div class="container-fluid td-outer td-resizable-grid">
<div class="td-main">
<div class="row flex-xl-nowrap">
<aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
{{ partial "sidebar.html" . }}
</aside>

<div class="layout-resizer d-none d-md-block" id="left-resizer"></div>

<div class="layout-resizer d-none d-xl-block" id="right-resizer"></div>

<aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none">
{{ partial "page-meta-links.html" . }} {{ partial "toc.html" . }} {{
partial "taxonomy_terms_clouds.html" . }}
Expand All @@ -28,10 +33,12 @@
.Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" .
}}{{ end }} {{ block "main" . }}{{ end }}
</main>

{{ partial "load-sidebars-width.html" . }}
</div>
</div>
{{ partial "footer.html" . }}
</div>
{{ partial "scripts.html" . }} {{ partial "image-modal.html" . }}
{{ partial "scripts.html" . }} {{ partial "sidebar-resize-script.html" }} {{ partial "image-modal.html" . }}
</body>
</html>
17 changes: 13 additions & 4 deletions layouts/video/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,35 @@
class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}"
>
<header>{{ partial "navbar.html" . }}</header>
<div class="container-fluid td-outer">
<div class="container-fluid td-outer td-resizable-grid">
<div class="td-main">
<div class="row flex-xl-nowrap">
<aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
{{ partial "sidebar.html" . }}
</aside>

<div class="layout-resizer d-none d-md-block" id="left-resizer"></div>

<div class="layout-resizer d-none d-xl-block" id="right-resizer"></div>

<aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none">
{{ partial "page-meta-links.html" . }} {{ partial "toc.html" . }} {{
partial "taxonomy_terms_clouds.html" . }}
{{ partial "page-meta-links.html" . }}
{{ partial "toc.html" . }}
{{ partial "taxonomy_terms_clouds.html" . }}
</aside>

<main class="col-12 col-md-9 col-xl-8" role="main">
{{ partial "version-banner.html" . }} {{ if not
.Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" .
}}{{ end }} {{ block "main" . }}{{ end }}
</main>

{{ partial "load-sidebars-width.html" . }}
</div>
</div>
{{ partial "footer.html" . }}
</div>
{{partial "video-category-navigation.html" .}}
{{ partial "scripts.html" . }} {{ partial "image-modal.html" . }}
{{ partial "scripts.html" . }} {{ partial "image-modal.html" . }} {{ partial "sidebar-resize-script.html" }}
</body>
</html>
Loading
Loading