Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active November 11, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/46f92ff0a889aa80be27863e41bb21af to your computer and use it in GitHub Desktop.
Save bjoerntx/46f92ff0a889aa80be27863e41bb21af to your computer and use it in GitHub Desktop.
window.addEventListener("load", () => {
TXTextControl.addEventListener("ribbonTabsLoaded", () => {
// Obtain "Paragraph" ribbon group element (get further ribbon group element ids
// by using the browser developer tools)
const ribbonGroupParagraph = document.getElementById("ribbonGroupParagraph");
const observer = new MutationObserver(mutations => {
for (mutation of mutations) {
switch (mutation.type) {
case "attributes":
switch (mutation.attributeName) {
case "class":
// The "class" attribute of an element has been changed.
// Get the affected element and figure out which button
// was pressed via the element id.
const button = mutation.target;
switch (button.id) {
case "ribbonTabHome_drpDnBtnBulletList":
// "Bulleted list" button.
// The "toggled" state can be determined via the CSS class
// "ribbon-button-selected".
if (button.classList.contains("ribbon-button-selected")) {
console.info("'Bulleted list' button toggled.")
}
else {
console.info("'Bulleted list' button un-toggled.")
}
break;
case "ribbonTabHome_drpDnBtnNumberedList":
// "Numbered list" button.
// ...
break;
// Get further button ids by browsing the html structure
// using the browser developer tools.
}
break;
}
break;
}
}
});
// Observer configuration (We want to observe changes in the whole sub-tree of the
// "Paragraph" group root element).
const config = { attributes: true, subtree: true };
// Pass in the target node (in this case the "Paragraph" group root element) and
// the observer options.
observer.observe(ribbonGroupParagraph, config);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment