Thanks a lot for pointing that out! It is a typo. There should be a ;
after the first "return". Opera happily parsed it without complaining so
I never spotted this even after staring at/modifying the code for a good
2 hours!
> Another thing I would recommend is that you push your script onto the
> MathJax queue to be sure that it runs after everything else is done.
> With the StartupHook call, that probably isn't 100% necessary, but it
> is still good form.
I will have to read up on how to add to the queue.
> I'm not familiar with the Dragonfly/Opera combination, so I'm not sure
> how your breakpoint works, but you should try to get your code working
> cross-browser. For this reason, I'm also concerned about your code
> insisting on the HTML-CSS output jax. It should be possible to write
> it more generally (but that does mean catching double-click events for
> all browsers).
In Dragonfly you need to load the scripts for debugging and then select
DOM -> dblclick. Then a double-click anywhere on the webpage will walk
you through all the function calls step by step.
>
> Once you get this working (and again, I will take a closer look later
> to see if I can work out your bug), I would like to see you submit
> this to the contributed extensions repository that we maintain on
> Github.
Thanks for your comments. I will fix the typo tomorrow when I have
access to the machine (already past midnight here). I suspect that
fixing that typo might make the code "just work."
The real problem is the if-then that includes the first return.
if (!HTMLCSS.noContextMenuBug) return
It says that if HTMLCSS.noContextMenuBug is NOT set, then return right
away. That means the call to ContextMenu() only is made if
noContextMenuBug is set. But that is only true for Konqueror (unless
you have set it yourself somewhere). So your
return HTMLCSS.ContextMenu.call(this,event,true);
call is never actually being reached. (It may have LOOKED like it
was, but that might be because of the missing semi-colon. I don't use
Dragonfly, so I don't know its quirks, but it might have highlighted
the wrong source line. Debuggers have been known to do that.)
If you put an alert() before the if-then and one after it, I bet you
will see that the ContextMenu() call is never being reached.
The real question is, what are you trying to accomplish, and why? Why
is using the contextual menu a problem and why do you want to link it
to the equations in another way? Perhaps we can suggest an
alternative approach.
> My questions are:
> 1. Is this the right function to call for showing the menu?
No. There is no API for accessing the menu from javascript, and you
are dealing with the undocumented internals of MathJax. There is no
guarantee that this will stay the same from version to version, and in
fact version 2.0 has a completely revamped event-processing
subsystem. Your changes here will not work with the new version.
> 2. Is there something fundamentally wrong in the way I am trying to
> add this functionality?
Well, I suppose the incorrect use of noContextMenuBug is fundamental.
Removing that should make it work in v1.1 of MathJax, but I suspect it
won't in v2.0.
> Just FYI: I am very new to javascript (a whole 1 day of "experience"
> from reading the MathJax code!), and I am also aware that this might
> clash with the zoom setting in Accessibility.js.
Note that users can use the MathJax menu to set the zoom trigger, so
it is not just the Accessible configuration that might be a problem.
Your changes will actually override the zoom trigger, so that menu
will appear to no longer work.
MathJax is probably not the best place to learn JavaScript, but it
appears that you are able to pick it up pretty well.
Good luck.
Davide
Thanks a lot for your explanation. Indeed, I had misunderstood this
variable. Removing this if statement made the code work right away.
> The real question is, what are you trying to accomplish, and why? Why is
> using the contextual menu a problem and why do you want to link it to
> the equations in another way? Perhaps we can suggest an alternative
> approach.
The main request originated in a Sage mailing list:
https://groups.google.com/d/msg/sage-devel/OvdxfORM46w/XfPhDiTMgogJ
>> My questions are:
>> 1. Is this the right function to call for showing the menu?
>
> No. There is no API for accessing the menu from javascript, and you are
> dealing with the undocumented internals of MathJax. There is no
> guarantee that this will stay the same from version to version, and in
> fact version 2.0 has a completely revamped event-processing subsystem.
> Your changes here will not work with the new version.
Yes. I am aware that this might not work in the future versions of
MathJax. However, the extension is short enough that it can be rewritten
when we move to MathJax-2.0 (MathJax will be distributed with the Sage
web interface so that one can work completely offline).
> MathJax is probably not the best place to learn JavaScript, but it
> appears that you are able to pick it up pretty well.
>
> Good luck.
>
> Davide
Thanks again. The MathJax code seems very well written and well
commented, and so I had minimal trouble in figuring out how to add an
extension.
Great. Glad it worked out for you.
>> The real question is, what are you trying to accomplish, and why?
>> Why is
>> using the contextual menu a problem and why do you want to link it to
>> the equations in another way? Perhaps we can suggest an alternative
>> approach.
>
> The main request originated in a Sage mailing list:
> https://groups.google.com/d/msg/sage-devel/OvdxfORM46w/XfPhDiTMgogJ
OK, I've glanced through this briefly, and I should tell you that a
number of the problems cited are resolved in MathJax v2.0. That
includes the STIX font problem in OS X Lion. The "[Math Processing
Error]" message now also has the MathJax contextual menu so that you
can change the renderer again if you hit that. (In the past, you had
to remove the MathJax cookie for the site to reset the renderer.) The
image fonts selection is disabled in the font submenu if image fonts
have been disabled for MathJax. So I think most of the menu problems
that were reported have been taken care of.
> Thanks again. The MathJax code seems very well written and well
> commented, and so I had minimal trouble in figuring out how to add
> an extension.
You are very kind. There is much more that could be done in terms of
comments and documentation, but I'm glad you have been able to make
your way through it.
Davide
I am not sure. It depends on whether MJ-2 or MJ-1.1 will be included in
the next version of the Sage notebook.
> 2) Does the code posted earlier in this thread for making the menu
> appear on double-click still work in v2.0? (Davide said "There is no
> guarantee that this will stay the same from version to version, and in
> fact version 2.0 has a completely revamped event-processing subsystem.
> Your changes here will not work with the new version." Is the code in
> fact broken in v2.0? I have not tested it yet.)
Yes, I had a look at the v2.0 sources, and the code posted earlier will
not work.
> 3) Is there still a demand for the menu to appear on a double-click?
> (This might appear to repeat question 1, but I think it is a separate
> issue -- it came up in a specific context, but there may be a broader
> use case which could still use this double-click capability.)
The demand stemmed from I believe two reasons:
1. One of the lead developers felt that the right-click in macs wasn't
too reliable.
2. In the current notebook, users already use double-click to get to the
latex source code, so user-interface wise, there won't be much of a
change in the new notebook (once this extension is used).
> Overall, what I am trying to determine is if there is any reason to
> rework, clean up, and document the code to prepare it for the
> contributed extensions repository.
If I modify it for v2.0, then I will post here. For v1.1, I already have
a pull request to the Sage Notebook, with a working version of this
extension (only for HTML-CSS): https://github.com/jasongrout/sagenb/pull/2
If Mathjax is included, it will (very hopefully) be 2.0. That said, the
patch hasn't been written or tested yet. We may not even get to upgrade
to mathjax in Sage 5.0---it depends on the timing, testing on the
mathjax branch, etc. The first goal is to get the jsmath version of the
new notebook into Sage 5.0. The next goal is to finish testing and
merging the mathjax branch (and upgrading to 2.0 in the process).
Thanks for your help in this!
Jason
The version for MathJax-2.0 is here: http://goo.gl/cnjeN
Overall, what I am trying to determine is if there is any reason torework, clean up, and document the code to prepare it for thecontributed extensions repository.If I modify it for v2.0, then I will post here. For v1.1, I already havea pull request to the Sage Notebook, with a working version of thisextension (only for HTML-CSS): https://github.com/jasongrout/sagenb/pull/2
The version for MathJax-2.0 is here: http://goo.gl/cnjeN
MathJax.Hub.Register.StartupHook("MathEvents Ready", function () {/**************************************************************************** ** DoubleClickEvent.js ** ** This makes the menu pop up on Double Click with left mouse. To do this, ** we redefine the DblClick object inside MathEvents to send a fake call as** "ContextMenu" to MathEvents.Handler. This is defined only for a browser ** that is not on a mobile device. ** ** Since this interferes with the zoom setting in Accessibility.js, that ** zoom setting will no longer work. ** *****************************************************************************/
var EVENT = MathJax.Extension.MathEvents.Event;var HUB = MathJax.Hub;//// Redefine DblClick only if it is not a mobile device. For a mobile// device MathJax-2.0 has double tap and hold for ContextMenu.//if (!HUB.Browser.isMobile) {
//EVENT.DblClick = function(event){return EVENT.Handler(event,"ContextMenu",this);}
var MENU = MathJax.Menu, MENUSETTINGS = HUB.config.menuSettings;// Disable the DblClick option from the menu. This is taken mostly// from MathMenu.js//
if (MENUSETTINGS.zoom === "Double-Click") {MENUSETTINGS.zoom = "None"}MENU.menu.Find("Math Settings", "Zoom Trigger","Double-Click").disabled = true;
});MathJax.Ajax.loadComplete("[MathJax]/../sage/js/DoubleClickEvent.js");
Thanks a lot for your thorough review! This is very helpful.