Skip to content

Commit

Permalink
reverse the version list and always highlight the latest version
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 committed May 21, 2024
1 parent d32ae16 commit 27209b4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 45 deletions.
73 changes: 33 additions & 40 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@
this[globalName] = mainExports;
}
}
})({"4iZu9":[function(require,module,exports) {
})({"40yvg":[function(require,module,exports) {
var global = arguments[3];
var HMR_HOST = null;
var HMR_PORT = 62230;
var HMR_PORT = 52109;
var HMR_SECURE = false;
var HMR_ENV_HASH = "42036d7a98ade5a7";
module.bundle.HMR_BUNDLE_ID = "2a29ff2311f401cb";
Expand Down Expand Up @@ -1107,50 +1107,38 @@ const addCopyButtons = (clipboard)=>{
pre.appendChild(button);
});
};
const addAnchorLinks = () => {
const addAnchorLinks = ()=>{
const elementsToProcess = document.querySelectorAll(".content h1, .content h2, .content h3, .content h4, .content tr");

elementsToProcess.forEach(element => {
elementsToProcess.forEach((element)=>{
let uniqueId;
if (element.tagName.toLowerCase() === 'tr') {
let closestHeading = element.closest('table').previousElementSibling;
while(closestHeading && !closestHeading.matches('h1, h2, h3, h4')) {
closestHeading = closestHeading.previousElementSibling;
}
const firstColumnName = element.cells[0].textContent.trim().toLowerCase().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-');

if (element.tagName.toLowerCase() === "tr") {
let closestHeading = element.closest("table").previousElementSibling;
while(closestHeading && !closestHeading.matches("h1, h2, h3, h4"))closestHeading = closestHeading.previousElementSibling;
const firstColumnName = element.cells[0].textContent.trim().toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
if (closestHeading) {
const headingId = closestHeading.getAttribute('id');
const headingId = closestHeading.getAttribute("id");
uniqueId = `${headingId}-${firstColumnName}`;
} else {
uniqueId = firstColumnName;
}
} else {
uniqueId = element.textContent.trim().toLowerCase().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-');
}

} else uniqueId = firstColumnName;
} else uniqueId = element.textContent.trim().toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
element.classList.add("heading-anchor");
element.setAttribute('id', uniqueId);
let anchor = document.createElement('a');
anchor.className = 'anchor-link';
anchor.href = '#' + uniqueId;
element.setAttribute("id", uniqueId);
let anchor = document.createElement("a");
anchor.className = "anchor-link";
anchor.href = "#" + uniqueId;
anchor.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width=16 height=16 viewBox="0 0 640 512"><!--! Font Awesome Pro 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l-1.1-1.6c-10.3-14.4-6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l-1.6 1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l-1.1 1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>';
element.append(anchor);
anchor.addEventListener("click", (e) => {
anchor.addEventListener("click", (e)=>{
e.preventDefault();
window.location = anchor.href;
let targetId = anchor.getAttribute('href').substring(1);
let targetId = anchor.getAttribute("href").substring(1);
let targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
})
}

})
})
}
if (targetElement) targetElement.scrollIntoView({
behavior: "smooth",
block: "start"
});
});
});
};
function removeExpiredEvents() {
let events = document.querySelectorAll(".community-highlight .carousel-cell");
let eventsNumber = events.length;
Expand Down Expand Up @@ -1249,17 +1237,22 @@ class multiTabBlockHandler {
constructor(nodes, tabClass, activeValue, parentCallback){
this.tabClass = tabClass;
this.parentCallback = parentCallback;
// this.active = 0
this.nodes = Array.from(nodes);
this.langs = this.nodes.map((k)=>{
return k.dataset.title;
});
this.active = this.langs.indexOf(activeValue);
this.active = this.active > 0 ? this.active : 0;
if (tabClass != "spin-version") this.active = this.active > 0 ? this.active : 0;
else this.active = this.active > 0 ? this.active : this.nodes.length - 1;
this.tabs = list("ul", codeblockLanguageTab, null, this.ChildEventHandler.bind(this));
this.el = el("div.tabs.is-boxed", this.tabs);
// If the tabClass is `spin-version` reverse the order of the list
if (tabClass === "spin-version") setStyle(this.tabs, {
display: "flex",
"flex-direction": "row-reverse"
});
this.tabs.update(this.langs, {
active: 0
active: this.active
});
this.updateTabContent(this.active);
}
Expand Down Expand Up @@ -1496,5 +1489,5 @@ function createFeedbackElement(handle) {
mount(handle, feedback);
}

},{"@parcel/transformer-js/src/esmodule-helpers.js":"j7FRh"}]},["4iZu9","e9rxa"], "e9rxa", "parcelRequire252c")
},{"@parcel/transformer-js/src/esmodule-helpers.js":"j7FRh"}]},["40yvg","e9rxa"], "e9rxa", "parcelRequire252c")

18 changes: 13 additions & 5 deletions static/js/src/modules/multiTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ class multiTabBlockHandler {
constructor(nodes, tabClass, activeValue, parentCallback) {
this.tabClass = tabClass
this.parentCallback = parentCallback
// this.active = 0
this.nodes = Array.from(nodes)
this.langs = this.nodes.map(k => { return k.dataset.title })
this.active = this.langs.indexOf(activeValue)
this.active = this.active > 0 ? this.active : 0
if (tabClass != "spin-version") {
this.active = this.active > 0 ? this.active : 0
} else {
this.active = this.active > 0 ? this.active : this.nodes.length - 1
}
this.tabs = list("ul", codeblockLanguageTab, null, this.ChildEventHandler.bind(this))
this.el = el("div.tabs.is-boxed", this.tabs)

this.tabs.update(this.langs, { active: 0 })
// If the tabClass is `spin-version` reverse the order of the list
if (tabClass === "spin-version") {
setStyle(this.tabs, { display: "flex", "flex-direction": "row-reverse" })
}

this.tabs.update(this.langs, { active: this.active })
this.updateTabContent(this.active)
}
ChildEventHandler(data, element) {
Expand Down Expand Up @@ -67,7 +75,7 @@ class multiTabContentHandler {
})

// If no OS preference set, try detect the user OS
if (this.selectedTab.os == null ) {
if (this.selectedTab.os == null) {
this.selectedTab.os = detectOS()
}
this.handler = []
Expand Down Expand Up @@ -147,7 +155,7 @@ function filterMultitabQuery() {
}).reduce((obj, key) => {
obj[key.replace("multitab_", "")] = query[key];
return obj;
}, {});
}, {});
return multitabQuery
}

Expand Down

0 comments on commit 27209b4

Please sign in to comment.