Modify Rich Content Editor - Remove Icons

Jump to solution
GideonWilliams
Community Coach
Community Coach

We have hybrid devices for staff and the Wiris Maths and Chemistry LTIs now provide amazing handwriting functionality so much that the built-in Maths Editor is redundant.

Is there anyway of removing it from the list?

Thanks

1 Solution
James
Community Champion

If you're self-hosting, you could remove it from the list in the source code.

If you're having Instructure host your instance, then it's a bit more difficult. Using custom JavaScript would be one way.

$('[aria-label="Insert Math Equation"]').hide();

That sounds simple enough, but here are some problems that I anticipate or have verified.

  • You need to do this on every page that loads the Rich Content Editor (RCE) and you want the item removed. That's a lot of different places, so it almost makes sense to run it on every page. However ...
  • You need to wait for the button to appear on the page before you can hide it. This can be done with a Mutation Observer, but you'll have to know the right element to watch, which may or may not be the same on every page. The content id seems like a good candidate, but you'll have to watch the subtree since the button is not a direct child of it
  • If the RCE is loaded inside an iframe and the iframe is delivered from a different domain (in security terms that includes the hostname) than the script running it, you may not have access to the contents of the iframe to make the change.
  • This may not work on mobile.
  • Removing the equation editor icon does not make other LTI tools, which may be under the V, appear. That is controlled by the INST.maxVisibleEditorButtons property, but that needs modified before the rich content editor is loaded.

This code is not thoroughly tested. I tested this code when adding a new page, when editing an existing page, when editing a quiz, and when taking a quiz with just one essay question on it. I did not test it in other places.

(function() {
    'use strict';
    var observer = new MutationObserver(function() {
        $('[aria-label="Insert Math Equation"]').hide();
    });
    var src = document.getElementById('content');
    observer.observe(src,{'childList': true, 'subtree': true});
})();‍‍‍‍‍‍‍‍

It's dumb in the sense that it tries to hide the equation editor button every time a node is added or removed from anywhere in the content of a page. The jQuery hide() command will silently fail if it's not there, but it uses a sledgehammer rather than a scalpel to accomplish it's task.

You may be able to add an observer.disconnect() inside the observer if there's no chance that Canvas will render() the page again and create a new RCE. You're probably safer to leave it without it.

Of course, you'll need to make sure that WIRIS doesn't use "Insert Math Equation" as their aria-label. If they do, you could get the first appearance.  But you may have more than one RCE on the page as well, so you'll most likely have to play around with the selectors.

It may be easier to just tell people not to use that button -- just like they probably won't use the left-to-right or right-to-left buttons.

View solution in original post