mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-17 13:27:50 +08:00
e755ff8122
* Force menu items into a single line * Add shortcut for saving the notebook * Make the disk icon always show file dialog * Split runtime and file settings into separate modals * Add ctrl+s to the shortcuts list * Add togglable menu to the session page * Make sure newly saved file appears in the file selector * Fix path seletor force reloading * Remove notebook generated in tests * Add test for file list refresh after save
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
/**
|
|
* A hook controlling a toggleable menu.
|
|
*
|
|
* The element should have two children:
|
|
*
|
|
* * one annotated with `data-toggle` being a clickable element
|
|
*
|
|
* * one annotated with `data-content` with menu content
|
|
*/
|
|
const Menu = {
|
|
mounted() {
|
|
const toggleElement = this.el.querySelector("[data-toggle]");
|
|
|
|
if (!toggleElement) {
|
|
throw new Error("Menu must have a child with data-toggle attribute");
|
|
}
|
|
|
|
const contentElement = this.el.querySelector("[data-content]");
|
|
|
|
if (!contentElement) {
|
|
throw new Error("Menu must have a child with data-content attribute");
|
|
}
|
|
|
|
toggleElement.addEventListener("click", (event) => {
|
|
if (this.el.hasAttribute("data-js-open")) {
|
|
this.el.removeAttribute("data-js-open");
|
|
} else {
|
|
this.el.setAttribute("data-js-open", "true");
|
|
// Postpone callback registration until the current click finishes bubbling.
|
|
setTimeout(() => {
|
|
document.addEventListener(
|
|
"click",
|
|
(event) => {
|
|
this.el.removeAttribute("data-js-open");
|
|
},
|
|
{ once: true }
|
|
);
|
|
}, 0);
|
|
}
|
|
});
|
|
},
|
|
};
|
|
|
|
export default Menu;
|