livebook/assets/js/morphdom_callbacks.js
Jonatan Kłosko 90e7941fe4
Redesign (#80)
* Update cell actions

* Add new focus indicator

* Update headings typography

* Update cell actions and insert buttons

* Add sidebar menu

* Add settings modal

* Update homepage

* Update settings dialog

* Rename classes

* Add floating menu

* Update icon colors on hover

* Fix homepage tests

* Format assets source

* Update monaco editor

* Fix editor width on resize

* Add more padding to the notebook content

* Update settings dialog title

* Show reevaluate button when the cell is in evaluated state

* Show section actions on focus or hover only

* Pre-fill runtime selector with the current configuration

* Ignore cmd + enter in Markdown cells
2021-03-20 14:10:15 +01:00

45 lines
1.2 KiB
JavaScript

const callbacks = {
onBeforeElUpdated(from, to) {
// Keep element attributes starting with data-js-
// which we set on the client.
for (const attr of from.attributes) {
if (attr.name.startsWith("data-js-")) {
to.setAttribute(attr.name, attr.value);
}
}
},
onNodeAdded(node) {
if (node.nodeType === Node.ELEMENT_NODE) {
if (node.getAttribute("data-element") === "menu-toggle") {
initializeMenuToggle(node);
}
}
},
};
function initializeMenuToggle(element) {
element.addEventListener("click", (event) => {
const menu = element.nextElementSibling;
if (menu.getAttribute("data-element") === "menu") {
if (menu.hasAttribute("data-js-shown")) {
menu.removeAttribute("data-js-shown");
} else {
menu.setAttribute("data-js-shown", "true");
// Postpone callback registration until the current click finishes bubbling.
setTimeout(() => {
document.addEventListener(
"click",
(event) => {
menu.removeAttribute("data-js-shown");
},
{ once: true }
);
}, 0);
}
}
});
}
export default callbacks;