Skip to content

Instantly share code, notes, and snippets.

@ottsch
Last active August 30, 2020 12:38
Show Gist options
  • Save ottsch/cf8e89bf0838bb13580de5194c7350e2 to your computer and use it in GitHub Desktop.
Save ottsch/cf8e89bf0838bb13580de5194c7350e2 to your computer and use it in GitHub Desktop.
Sortable items in Roam's right sidebar
let sortableSidebar = null;
(function(d, script) {
script = d.createElement('script');
script.type = 'text/javascript';
script.src = 'https://raw.githack.com/SortableJS/Sortable/master/Sortable.js';
script.async = true;
script.onload = function() {
const observer = new MutationObserver(() => {
if (document.body.contains(document.getElementById("roam-right-sidebar-content"))) {
sortableSidebar = sortableSidebar || Sortable.create(
document.getElementById("roam-right-sidebar-content"), {
handle: ".bp3-button"
});
} else if (sortableSidebar) {
sortableSidebar.destroy();
sortableSidebar = null;
}
});
observer.observe(document.querySelector('.roam-body-main'), {
childList: true,
subtree: true
});
};
d.getElementsByTagName('head')[0].appendChild(script);
}(document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment