forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for breadcrumb-config-outline
- Loading branch information
1 parent
cc05b74
commit b166f01
Showing
5 changed files
with
74 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
core/src/main/resources/lib/form/breadcrumb-config-outline/init.css
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
core/src/main/resources/lib/form/breadcrumb-config-outline/init.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import tippy from "tippy.js"; | ||
import Templates from "@/components/dropdowns/templates"; | ||
import makeKeyboardNavigable from "@/util/keyboard"; | ||
import { toId } from "@/util/dom"; | ||
|
||
/* | ||
* Generates a jump list for the active breadcrumb to jump to | ||
* sections on the page (if using <f:breadcrumb-config-outline />) | ||
*/ | ||
function init() { | ||
const inpageNavigationBreadcrumb = document.querySelector("#inpage-nav"); | ||
if (inpageNavigationBreadcrumb) { | ||
const chevron = document.createElement("li"); | ||
chevron.classList.add("children"); | ||
inpageNavigationBreadcrumb.after(chevron); | ||
|
||
tippy(chevron, generateDropdown()); | ||
} | ||
} | ||
|
||
/* | ||
* Generates the Tippy dropdown for the in-page jump list | ||
*/ | ||
function generateDropdown() { | ||
return { | ||
...Templates.dropdown(), | ||
onShow(instance) { | ||
instance.popper.addEventListener("click", () => { | ||
instance.hide(); | ||
}); | ||
const items = []; | ||
document | ||
.querySelectorAll( | ||
"form > div > div > .jenkins-section > .jenkins-section__title" | ||
) | ||
.forEach((section) => { | ||
const id = toId(section.textContent); | ||
section.id = id; | ||
items.push({ label: section.textContent, id: id }); | ||
}); | ||
instance.setContent(generateDropdownItems(items)); | ||
}, | ||
}; | ||
} | ||
|
||
/* | ||
* Generates the contents for the dropdown | ||
*/ | ||
function generateDropdownItems(items) { | ||
const menuItems = document.createElement("div"); | ||
|
||
menuItems.classList.add("jenkins-dropdown"); | ||
menuItems.append( | ||
...items.map((item) => { | ||
const menuItemOptions = { | ||
url: "#" + item.id, | ||
label: item.label, | ||
}; | ||
return Templates.item(menuItemOptions); | ||
}) | ||
); | ||
|
||
makeKeyboardNavigable( | ||
menuItems, | ||
() => menuItems.querySelectorAll(".jenkins-dropdown__item"), | ||
Templates.SELECTED_ITEM_CLASS | ||
); | ||
|
||
return menuItems; | ||
} | ||
|
||
export default { init }; |