mathjax / MathJax-website

The MathJax website
https://www.mathjax.org
22 stars 21 forks source link

Fix output switcher #19

Closed pkra closed 9 years ago

pkra commented 9 years ago

Reported on the User Group: after switching to MathML, switching back does not work.

Possibly due to the Fast Preview? (Which is deactivated by default on mathjax.org)

pkra commented 9 years ago

Ok, seems reproducible enough

Bad workaround:

dpvc commented 9 years ago

Note: this is issue mathjax/MathJax#745. The cause is described there.

pkra commented 9 years ago

Thanks -- I had forgotten about that one.

saf-itpro commented 9 years ago

I tested about an hour ago on my Work Desktop (Windows 7, IE 11, Chrome latest ver.). I see some improvements now. The issue does not appear if I clear the cache. But the problem exists if the cache is not cleared. Moreover, when it’s working and if you change back and forth the rendering mode in the dropdown from “HTML-CSS” to “MathML” it works (warning in MathML mode and correct display in the “HTML-CSS” mode) as long as you don’t close the browser. But if you close the browser and re-open it without clearing the cache, the problem is re-surfaced. Thanks..Saf.

pkra commented 9 years ago

@dpvc I don't really understand how the current code works. For now, I'd be happy if the button worked like the menu iself (i.e., simply set the cookie). However, I fail at this -- all I can come up with is something along the lines of

MathJax.Hub.Queue(
  ["setRenderer",MathJax.Hub,"HTML-CSS"],
  ["Rerender",MathJax.Hub]
);

which disables the various warnings. What's the right way to approach this?

dpvc commented 9 years ago

Here is a replacement for the setMode() function:

  window.setMode = function (renderer) {
    var MENU = MathJax.Menu,
        original = MENU.cookie.renderer;           // the original renderer
    //
    //  Wait for the menu to update before posting the dialog for 
    //  switching to MathML
    //
    setTimeout(function () {
      MENU.config.settings.renderer = renderer;    // Set the new renderer 
      MENU.Renderer.call(this);                    // Change it using the menu action
      if (MENU.cookie.renderer != original) {      // If the cookie changed,
        if (original == null) {delete MENU.cookie.renderer}
          else {MENU.cookie.renderer = original}   // Put back the original renderer
        MENU.saveCookie();                         //  and save the cookie
      }
      HUB.Queue(function () {   // Update the menu in case the user cancelled the change
        document.getElementById("Renderer").value = HUB.outputJax["jax/mml"][0].id;
      });
    },10);
  };

This takes care of this issue, and also makes sure the menu is displayed properly when the user gets the warning dialog about switching to MathML, and if the user cancels the switch.

dpvc commented 9 years ago

Alternatively, if you want the menu selection to be sticky, then you can do

  window.setMode = function (renderer) {
    var MENU = MathJax.Menu;
    setTimeout(function () {
      MENU.cookie.renderer = MENU.config.settings.renderer = renderer;
      MENU.saveCookie();
      MENU.Renderer.call(this);
      HUB.Queue(function () {
        document.getElementById("Renderer").value = HUB.outputJax["jax/mml"][0].id;
      });
    },10);
  };
pkra commented 9 years ago

Thanks! (I used the first one.)

saf-itpro commented 9 years ago

Peter,

I tested on work desktop(Windows 7, IE10), home laptops (Windows 8.1, IE11 and VISTA, IE8). It's working now.

Thanks..Saf

On Wed, Feb 18, 2015 at 3:58 PM, Peter Krautzberger < notifications@github.com> wrote:

Thanks! (I used the first one.)

— Reply to this email directly or view it on GitHub https://github.com/mathjax/MathJax-website/issues/19#issuecomment-74946381 .

pkra commented 9 years ago

Thanks for confirming, @saf-itpro