From 1228bb89ad5c9ffb307dee22ed0d1814e378a4d5 Mon Sep 17 00:00:00 2001 From: zorkow Date: Wed, 26 Aug 2015 13:38:44 +0100 Subject: [PATCH] Introduces accessor function for cached MathJax nodes. --- unpacked/extensions/MathMenu.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/unpacked/extensions/MathMenu.js b/unpacked/extensions/MathMenu.js index ced9b8a30..0bbf3c6ae 100644 --- a/unpacked/extensions/MathMenu.js +++ b/unpacked/extensions/MathMenu.js @@ -485,10 +485,15 @@ posted: false, // Is a menu open? GetJaxs: function() { + if (MENU.hasJaxs) { + return MENU.jaxs; + } var nodes = document.getElementsByClassName('MathJax'); for (var i = 0, node; node = nodes[i]; i++) { MENU.jaxs.push(node); } + MENU.hasJaxs = true; + return MENU.jaxs; }, GetNode: function() { return MENU.node; @@ -517,13 +522,10 @@ MENU.GetActive().focus(); }, Activate: function(event, menu) { - if (!MENU.hasJaxs) { - MENU.GetJaxs(); - } if (!MENU.GetNode()) { MENU.SetNode(document.getElementById(MENU.jax.inputID + '-Frame')); } - for (var j = 0, jax; jax = MENU.jaxs[j]; j++) { + for (var j = 0, jax; jax = MENU.GetJaxs()[j]; j++) { jax.tabIndex = -1; } MENU.posted = true; @@ -531,7 +533,8 @@ Unfocus: function() { MENU.GetActive().tabIndex = -1; MENU.SetActive(null); - for (var j = 0, jax; jax = MENU.jaxs[j]; j++) { + var jaxs = MENU.GetJaxs(); + for (var j = 0, jax; jax = jaxs[j]; j++) { jax.tabIndex = 0; } MENU.GetNode().focus(); @@ -541,11 +544,12 @@ //TODO: A toggle focus method on the top level would avoid having to //tabIndex all the Jaxs. Move: function(event, menu, move) { - var len = MENU.jaxs.length; + var jaxs = MENU.GetJaxs(); + var len = jaxs.length; if (len === 0) { return; } - var next = MENU.jaxs[MENU.Mod(move(MENU.jaxs.indexOf(MENU.GetNode())), len)]; + var next = jaxs[MENU.Mod(move(jaxs.indexOf(MENU.GetNode())), len)]; if (next === MENU.GetNode()) { return; }