Improve example to avoid some flickering of the box when the math changes
This commit is contained in:
parent
951c14298a
commit
8f8c4453cf
|
@ -2,7 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>MathJax Dynamic Math Test Page</title>
|
<title>MathJax Dynamic Math Test Page</title>
|
||||||
<!-- Copyright (c) 2010 Design Science, Inc. -->
|
<!-- Copyright (c) 2010-2011 Design Science, Inc. -->
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
|
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ input {margin-top: .7em}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
//
|
//
|
||||||
// Use a closure to hide the local variables from the
|
// Use a closure to hide the local variables from the
|
||||||
|
@ -36,13 +35,21 @@ input {margin-top: .7em}
|
||||||
//
|
//
|
||||||
(function () {
|
(function () {
|
||||||
var QUEUE = MathJax.Hub.queue; // shorthand for the queue
|
var QUEUE = MathJax.Hub.queue; // shorthand for the queue
|
||||||
var math = null; // the element jax for the math output.
|
var math = null, box = null; // the element jax for the math output, and the box it's in
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hide and show the box (so it doesn't flicker as much)
|
||||||
|
//
|
||||||
|
var HIDEBOX = function () {box.style.visibility = "hidden"}
|
||||||
|
var SHOWBOX = function () {box.style.visibility = "visible"}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get the element jax when MathJax has produced it.
|
// Get the element jax when MathJax has produced it.
|
||||||
//
|
//
|
||||||
QUEUE.Push(function () {
|
QUEUE.Push(function () {
|
||||||
math = MathJax.Hub.getAllJax("MathOutput")[0];
|
math = MathJax.Hub.getAllJax("MathOutput")[0];
|
||||||
|
box = document.getElementById("box");
|
||||||
|
SHOWBOX(); // box is initially hidden so the braces don't show
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -50,7 +57,18 @@ input {margin-top: .7em}
|
||||||
// math entered by the user
|
// math entered by the user
|
||||||
//
|
//
|
||||||
window.UpdateMath = function (TeX) {
|
window.UpdateMath = function (TeX) {
|
||||||
QUEUE.Push(["Text",math,"\\displaystyle{"+TeX+"}"]);
|
QUEUE.Push(HIDEBOX,["Text",math,"\\displaystyle{"+TeX+"}"],SHOWBOX);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// IE doesn't fire onchange events for RETURN, so
|
||||||
|
// use onkeypress to do a blur (and refocus) to
|
||||||
|
// force the onchange to occur
|
||||||
|
//
|
||||||
|
if (MathJax.Hub.Browser.isMSIE) {
|
||||||
|
window.MathInput.onkeypress = function () {
|
||||||
|
if (window.event && window.event.keyCode === 13) {this.blur(); this.focus()}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
@ -61,22 +79,9 @@ Type some $\rm\TeX$ code and press RETURN:<br />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>You typed:</p>
|
<p>You typed:</p>
|
||||||
<div class="box">
|
<div class="box" id="box" style="visibility:hidden">
|
||||||
<div id="MathOutput" class="output">$${}$$</div>
|
<div id="MathOutput" class="output">$${}$$</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
//
|
|
||||||
// IE doesn't fire onchange events for RETURN, so
|
|
||||||
// use onkeypress to do a blur (and refocus) to
|
|
||||||
// force the onchange to occur
|
|
||||||
//
|
|
||||||
if (MathJax.Hub.Browser.isMSIE) {
|
|
||||||
window.MathInput.onkeypress = function () {
|
|
||||||
if (window.event && window.event.keyCode === 13) {this.blur(); this.focus()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user