Removes all caching of MathJax nodes.

This commit is contained in:
zorkow 2015-08-26 14:17:08 +01:00
parent 39109bf88a
commit 1c07cf3189

View File

@ -297,7 +297,7 @@
if (event) { if (event) {
var x = event.pageX, y = event.pageY; var x = event.pageX, y = event.pageY;
} }
var node = MENU.GetNode() || event.target; var node = MENU.CurrentNode() || event.target;
if (!x && !y && node) { if (!x && !y && node) {
var rect = node.getBoundingClientRect(); var rect = node.getBoundingClientRect();
x = rect.right; x = rect.right;
@ -477,26 +477,24 @@
/* /*
* Keyboard navigation of menu. * Keyboard navigation of menu.
*/ */
node: null, // The node the menu was activated on. HTML!
active: null, // The currently focused item. There can only be one! HTML! active: null, // The currently focused item. There can only be one! HTML!
posted: false, // Is a menu open? posted: false, // Is a menu open?
GetJaxs: function() { GetNode: function(jax) {
var node = document.getElementById(jax.inputID + '-Frame');
return node.isMathJax ? node : node.firstChild;
},
CurrentNode: function() {
return MENU.GetNode(MENU.jax);
},
AllNodes: function() {
var jaxs = MathJax.Hub.getAllJax(); var jaxs = MathJax.Hub.getAllJax();
var nodes = []; var nodes = [];
for (var i = 0, jax; jax = jaxs[i]; i++) { for (var i = 0, jax; jax = jaxs[i]; i++) {
var node = document.getElementById(jax.inputID + "-Frame"); nodes.push(MENU.GetNode(jax));
nodes.push(node.isMathJax ? node : node.firstChild);
} }
return nodes; return nodes;
}, },
GetNode: function() {
return document.getElementById(MENU.jax.inputID + '-Frame');
// return MENU.node;
},
SetNode: function(node) {
MENU.node = node;
},
GetActive: function() { GetActive: function() {
return MENU.active; return MENU.active;
}, },
@ -518,10 +516,7 @@
MENU.GetActive().focus(); MENU.GetActive().focus();
}, },
Activate: function(event, menu) { Activate: function(event, menu) {
if (!MENU.GetNode()) { var jaxs = MENU.AllNodes();
MENU.SetNode(document.getElementById(MENU.jax.inputID + '-Frame'));
}
var jaxs = MENU.GetJaxs();
for (var j = 0, jax; jax = jaxs[j]; j++) { for (var j = 0, jax; jax = jaxs[j]; j++) {
jax.tabIndex = -1; jax.tabIndex = -1;
} }
@ -530,29 +525,27 @@
Unfocus: function() { Unfocus: function() {
MENU.GetActive().tabIndex = -1; MENU.GetActive().tabIndex = -1;
MENU.SetActive(null); MENU.SetActive(null);
var jaxs = MENU.GetJaxs(); var jaxs = MENU.AllNodes();
for (var j = 0, jax; jax = jaxs[j]; j++) { for (var j = 0, jax; jax = jaxs[j]; j++) {
jax.tabIndex = 0; jax.tabIndex = 0;
} }
MENU.GetNode().focus(); MENU.CurrentNode().focus();
MENU.SetNode(null);
MENU.posted = false; MENU.posted = false;
}, },
//TODO: A toggle focus method on the top level would avoid having to //TODO: A toggle focus method on the top level would avoid having to
//tabIndex all the Jaxs. //tabIndex all the Jaxs.
Move: function(event, menu, move) { Move: function(event, menu, move) {
var jaxs = MENU.GetJaxs(); var jaxs = MENU.AllNodes();
var len = jaxs.length; var len = jaxs.length;
if (len === 0) { if (len === 0) {
return; return;
} }
var next = jaxs[MENU.Mod(move(jaxs.indexOf(MENU.GetNode())), len)]; var next = jaxs[MENU.Mod(move(jaxs.indexOf(MENU.CurrentNode())), len)];
if (next === MENU.GetNode()) { if (next === MENU.CurrentNode()) {
return; return;
} }
MENU.menu.Remove(event, menu); MENU.menu.Remove(event, menu);
MENU.jax = MathJax.Hub.getJaxFor(next); MENU.jax = MathJax.Hub.getJaxFor(next);
MENU.SetNode(next);
MENU.menu.Post(null); MENU.menu.Post(null);
}, },
Right: function(event, menu) { Right: function(event, menu) {