Use STACK equation preview box in other question types?

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

{$a->নাম} - {$a->তারিখ} দ্বারা
Number of replies: 8
Core developers এর ছবি Particularly helpful Moodlers এর ছবি Plugin developers এর ছবি 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>
In reply to Daniel Thies

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

{$a->নাম} - {$a->তারিখ} দ্বারা

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. 

হাসি

In reply to Daniel Thies

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

{$a->নাম} - {$a->তারিখ} দ্বারা

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?

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Particularly helpful Moodlers এর ছবি Plugin developers এর ছবি 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?

{$a->নাম} - {$a->তারিখ} দ্বারা

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?

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Particularly helpful Moodlers এর ছবি Plugin developers এর ছবি 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?

{$a->নাম} - {$a->তারিখ} দ্বারা
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?

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Particularly helpful Moodlers এর ছবি Plugin developers এর ছবি 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?

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Particularly helpful Moodlers এর ছবি Plugin developers এর ছবি 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>