Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Navbar will hide when iframed and send its size to its parent #7744

Merged
merged 1 commit into from
Jan 25, 2022
Merged
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
1 change: 0 additions & 1 deletion doc/!templates/uno/styles/docfx.js

This file was deleted.

2 changes: 2 additions & 0 deletions doc/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ exports.build = build;

exports.default = series(build, run);

exports.clean = series(clean);

exports.debug = series(useDebug, build, run);

exports.strict = series(useDebug, useStrict, build, run);
73 changes: 73 additions & 0 deletions doc/templates/uno/component/navbar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
/**
* Remove the content of the navbar.
*
* Note: For styling reasons its more convenient to keep the navbar. And just empty the content.
*/
function removeNavbar() {
const navBar = document.querySelector("header > nav");
navBar.innerHTML="";
}

/**
* Load the navbar from the uno website
*/
function initializeNavbar() {

const navbar = document.querySelector("header > .navbar");
if (document.body.classList.contains("front-page")) {
let last_known_scroll_position = 0;
let ticking = false;

function doSomething(scroll_pos) {
if (scroll_pos >= 100) navbar.classList.add("scrolled");
else navbar.classList.remove("scrolled");
}

window.addEventListener("scroll", function () {
last_known_scroll_position = window.scrollY;

if (!ticking) {
window.requestAnimationFrame(function () {
doSomething(last_known_scroll_position);
ticking = false;
});

ticking = true;
}
});
}

const unoMenuReq = new XMLHttpRequest();
const unoMenuEndpoint = "https://platform.uno/wp-json/wp/v2/menu";
const $navbar = document.getElementById("navbar");
let wordpressMenuHasLoaded = false;

unoMenuReq.open("get", unoMenuEndpoint, true);

if (typeof navbar !== "undefined") {
unoMenuReq.onload = function () {
if (unoMenuReq.status === 200 && unoMenuReq.responseText) {
$navbar.innerHTML = JSON.parse(
unoMenuReq.responseText
);
wordpressMenuHasLoaded = true;
$(document).trigger("wordpressMenuHasLoaded");
}
};
unoMenuReq.onerror = function (e) {
};
unoMenuReq.send();
}

$(document).ajaxComplete(function (event, xhr, settings) {
const docFxNavbarHasLoaded = settings.url === "toc.html";

if (docFxNavbarHasLoaded && wordpressMenuHasLoaded) {
const $docfxNavbar = $navbar.getElementsByClassName("navbar-nav");
$docfxNavbar[0].className += " hidden";

}
});

}

/**
* Changes the logo on resize
*/
Expand Down
1 change: 1 addition & 0 deletions doc/templates/uno/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ const filtered = 'filtered';
const show = 'show';
const hide = 'hide';
const collapsed = 'collapsed';
const iframed = window.self !== window.top;
59 changes: 6 additions & 53 deletions doc/templates/uno/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,14 @@
document.addEventListener(
"DOMContentLoaded",
function () {
resizeObserver.observe(document.getElementsByClassName("body-content")[0]);

const navbar = document.querySelector("header > .navbar");
if (document.body.classList.contains("front-page")) {
let last_known_scroll_position = 0;
let ticking = false;

function doSomething(scroll_pos) {
if (scroll_pos >= 100) navbar.classList.add("scrolled");
else navbar.classList.remove("scrolled");
}

window.addEventListener("scroll", function () {
last_known_scroll_position = window.scrollY;

if (!ticking) {
window.requestAnimationFrame(function () {
doSomething(last_known_scroll_position);
ticking = false;
});

ticking = true;
}
});
}

const unoMenuReq = new XMLHttpRequest();
const unoMenuEndpoint = "https://platform.uno/wp-json/wp/v2/menu";
const $navbar = document.getElementById("navbar");
let wordpressMenuHasLoaded = false;

unoMenuReq.open("get", unoMenuEndpoint, true);

if (typeof navbar !== "undefined") {
unoMenuReq.onload = function () {
if (unoMenuReq.status === 200 && unoMenuReq.responseText) {
$navbar.innerHTML = JSON.parse(
unoMenuReq.responseText
);
wordpressMenuHasLoaded = true;
$(document).trigger("wordpressMenuHasLoaded");
}
};
unoMenuReq.onerror = function (e) {};
unoMenuReq.send();
if (iframed) {
removeNavbar();
} else {
initializeNavbar();
}

$( document ).ajaxComplete(function( event, xhr, settings ) {
const docFxNavbarHasLoaded = settings.url === "toc.html";

if (docFxNavbarHasLoaded && wordpressMenuHasLoaded) {
const $docfxNavbar = $navbar.getElementsByClassName("navbar-nav");
$docfxNavbar[0].className += " hidden";

}
});

document.addEventListener(
"click",
function (e) {
Expand All @@ -76,3 +28,4 @@ document.addEventListener(
},
false
);

9 changes: 6 additions & 3 deletions doc/templates/uno/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ enableSearch();
renderTables();
renderAlerts();
renderLinks();
renderNavbar();
renderSidebar();
renderAffix();
renderFooter();
renderLogo();

if (!iframed) {
renderNavbar();
renderLogo();
renderFooter();
}

breakText();
renderTabs();
Expand Down
2 changes: 1 addition & 1 deletion doc/templates/uno/service/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function enableSearch() {

postSearchQuery(worker, query);

}).then(r => r.resolve());
});
}

/**
Expand Down
17 changes: 17 additions & 0 deletions doc/templates/uno/service/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,20 @@ function breakText() {
$(this).breakWord();
});
}

/**
* This observer will post a message containing the new height every time it changes.
*
* @type {ResizeObserver}
*/
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
let height = 0;
if (entry.contentBoxSize) {
height = entry.contentBoxSize[0].blockSize;
} else {
height = entry.contentRect.height;
}
window.parent.postMessage(["setHeight", height], "*");
}
});
2 changes: 1 addition & 1 deletion doc/templates/uno/styles/docfx.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/templates/uno/styles/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.