Use STACK equation preview box in other question types?

Re: Use STACK equation preview box in other question types?

by Daniel Thies -
Number of replies: 8
Picture of Core developers Picture of Plugin developers Picture of Testers

Andrew,

Here is another fix that takes care of the MC bug. It is better to post responses here rather than PM so that others understand the thread later.

<script>
  window.MathJax = {
    AuthorInit: function() {
      MathJax.Hub.Register.StartupHook('End', function() {
        var preview = document.createElement('span');
        preview.setAttribute('class', 'filter_mathjaxloader_equation')
        preview.innerHTML = ' ``';
        MathJax.Hub.processSectionDelay = 0;
        MathJax.Hub.Queue(['Typeset', MathJax.Hub, preview]);
        var inputs = document.querySelectorAll('.subquestion input, .shortanswer .answer input');
        for (var i = 0; i < inputs.length; i++) {
          var source = inputs[i];
          if (source.getAttribute('type') === 'text') {
            source.parentNode.appendChild(preview.cloneNode(true));
            MathJax.Hub.Queue(['Typeset', MathJax.Hub, source.nextSibling]);
            source.addEventListener('input', function() {
              var math = MathJax.Hub.getAllJax(this.nextSibling)[0];
              MathJax.Hub.Queue(['Text', math, this.value]);
            });
          } 
        }  
      });                                       
    }   
  }
</script>
Average of ratings: Useful (1)
In reply to Daniel Thies

Re: Use STACK equation preview box in other question types?

by Andrew Barrett -

This is so GREAT! Thank you Daniel for all your help with this. Deeply appreciated.

It works perfectly and our learners are already enjoying the benefits. 

smile

In reply to Daniel Thies

Re: Use STACK equation preview box in other question types?

by Andrew Barrett -

Hi Daniel,

Firstly, this is working so well for us. Thank you again. 

Secondly, I wanted ask something. When we have the question behaviour set to "interactive with multiple tries" and the student gets their first attempt wrong, it no longer renders the equation on the second attempt. 

Do you have any suggestions for how to overcome this?

Many thanks

Andrew

In reply to Andrew Barrett

Re: Use STACK equation preview box in other question types?

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

I have not been able to reproduce this. Can you turn on the browser console and see if an error is reported?

In reply to Daniel Thies

Re: Use STACK equation preview box in other question types?

by Andrew Barrett -

Oh, I am getting a few error notices. Would it be one of the below?



Thanks

Andrew

In reply to Andrew Barrett

Re: Use STACK equation preview box in other question types?

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

It looks like you have a security program called Rapport installed on your client that is blocking MathJax because it thinks it is a cross site scripting threat.

In reply to Daniel Thies

Re: Use STACK equation preview box in other question types?

by Seth Mengal -
Its not Rapport, also happening with me Daniel.


Uncaught Error: Can't make callback from given data

    at USING (cdn.mathjax.org/mathjax/latest/MathJax.js?delayStartupUntil=configured:19)

    at Object.Push (cdn.mathjax.org/mathjax/latest/MathJax.js?delayStartupUntil=configured:19)

    at Object.Queue (cdn.mathjax.org/mathjax/latest/MathJax.js?delayStartupUntil=configured:19)

    at HTMLInputElement.<anonymous> (attempt.php:39)


Seems if the textbox has a value at 'second try' - the renderer is not able to point to the HTML input box? 

In reply to Seth Mengal

Re: Use STACK equation preview box in other question types?

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

Are you loading MathJax in the header or are you using the Moodle MathJax filter?

In reply to Seth Mengal

Re: Use STACK equation preview box in other question types?

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

Andrew and I found that certain review options change the DOM structure so I had to update the script

<script>
  window.MathJax = {
    AuthorInit: function() {
      MathJax.Hub.Register.StartupHook('End', function() {
        var preview = document.createElement('span');
        preview.setAttribute('class', 'filter_mathjaxloader_equation')
        preview.innerHTML = ' ``';
        MathJax.Hub.processSectionDelay = 0;
        MathJax.Hub.Queue(['Typeset', MathJax.Hub, preview]);
        var inputs = document.querySelectorAll('.subquestion input, .shortanswer .answer input');
        for (var i = 0; i < inputs.length; i++) {
          var source = inputs[i];
          if (source.getAttribute('type') === 'text') {
            source.parentNode.appendChild(preview.cloneNode(true));
            MathJax.Hub.Queue(['Typeset', MathJax.Hub, source.parentNode.lastChild]);
source.parentNode.lastChild.innerHTML = '`' + source.value + '`'; source.addEventListener('input', function() { var math = MathJax.Hub.getAllJax(this.parentNode)[0]; MathJax.Hub.Queue(['Text', math, this.value]); }); } } }); } } </script>

Average of ratings: Useful (1)