mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-28 22:30:49 +08:00
fix(custom.js): fix to correctly deal with when...
...JSON file contains 1 or more objects, but no actual content.
This commit is contained in:
committed by
Gabor Kiss-Vamosi
parent
4c6624b79f
commit
45e4041d09
@@ -124,7 +124,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
|||||||
})
|
})
|
||||||
/* JSON file was fetched successfully.... */
|
/* JSON file was fetched successfully.... */
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if (!typeof json === "array") {
|
if (json.constructor !== Array) {
|
||||||
/* Data structure not recognized. */
|
/* Data structure not recognized. */
|
||||||
} else {
|
} else {
|
||||||
/* console.log('JSON is an array.'); */
|
/* console.log('JSON is an array.'); */
|
||||||
@@ -133,13 +133,11 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
|||||||
console.log('JSON has no banners -- nothing to do.');
|
console.log('JSON has no banners -- nothing to do.');
|
||||||
} else {
|
} else {
|
||||||
/* Note: `div.page` is unique to Furo theme. */
|
/* Note: `div.page` is unique to Furo theme. */
|
||||||
const page = document.querySelector('div.page');
|
|
||||||
const pgParent = page.parentElement;
|
|
||||||
|
|
||||||
/* Create and insert banner container. */
|
/* Create and insert banner container. */
|
||||||
const newDiv = document.createElement('div');
|
const newDiv = document.createElement('div');
|
||||||
newDiv.classList.add(bannerContainerClass);
|
newDiv.classList.add(bannerContainerClass);
|
||||||
pgParent.insertBefore(newDiv, page);
|
let bannerCount = 0;
|
||||||
|
|
||||||
/* Create a <p> or an <a> element for each banner.
|
/* Create a <p> or an <a> element for each banner.
|
||||||
* First, sort them in priority order with "highest-priority" being
|
* First, sort them in priority order with "highest-priority" being
|
||||||
@@ -156,6 +154,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
|||||||
let banner = json[i];
|
let banner = json[i];
|
||||||
|
|
||||||
if (banner.hasOwnProperty('label')) {
|
if (banner.hasOwnProperty('label')) {
|
||||||
|
bannerCount++;
|
||||||
let priorityClass = '';
|
let priorityClass = '';
|
||||||
let newElement = null;
|
let newElement = null;
|
||||||
|
|
||||||
@@ -179,20 +178,26 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally, we need to tell the page element that its `min-hight`
|
if (bannerCount > 0) {
|
||||||
* is 100% minus the hight of all the banners, including the one
|
const page = document.querySelector('div.page');
|
||||||
* supplied by `conf.py` in `conf.html_theme_options.announcement`
|
const pgParent = page.parentElement;
|
||||||
* if one is present === var(--header-height).
|
pgParent.insertBefore(newDiv, page);
|
||||||
*
|
|
||||||
* This extends short pages by just enough to place [PREV] and [NEXT]
|
/* Finally, we need to tell the page element that its `min-hight`
|
||||||
* buttoms and footer at bottom of page without scrolling.
|
* is 100% minus the hight of all the banners, including the one
|
||||||
*
|
* supplied by `conf.py` in `conf.html_theme_options.announcement`
|
||||||
* Note: this overrides the `min-height` property set for this
|
* if one is present === var(--header-height).
|
||||||
* element in `furo.css`, which is: calc(100% - var(--header-height)).
|
*
|
||||||
* It additionally subtracts height of banner list.
|
* This extends short pages by just enough to place [PREV] and [NEXT]
|
||||||
* */
|
* buttoms and footer at bottom of page without scrolling.
|
||||||
let height = newDiv.offsetHeight;
|
*
|
||||||
page.style['min-height'] = `calc(100% - var(--header-height) - ${height}px)`;
|
* Note: this overrides the `min-height` property set for this
|
||||||
|
* element in `furo.css`, which is: calc(100% - var(--header-height)).
|
||||||
|
* It additionally subtracts height of banner list.
|
||||||
|
* */
|
||||||
|
let height = newDiv.offsetHeight;
|
||||||
|
page.style['min-height'] = `calc(100% - var(--header-height) - ${height}px)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) .catch(error => {
|
}) .catch(error => {
|
||||||
|
|||||||
Reference in New Issue
Block a user