Add permalink button to test page

Auditors: emily
This commit is contained in:
Ben Alpert 2014-07-23 20:23:50 -07:00
parent a66d285532
commit 6dd6032ebc
3 changed files with 17 additions and 4 deletions

View File

@ -3,7 +3,6 @@
<head>
<title>KaTeX Test</title>
<script src="katex.js" type="text/javascript"></script>
<script src="main.js" type="text/javascript"></script>
<link href="fonts/fonts.css" rel="stylesheet" type="text/css">
<link href="katex.css" rel="stylesheet" type="text/css">
<link href="main.css" rel="stylesheet" type="text/css">
@ -11,5 +10,7 @@
<body>
<input type="text" value="\blue\dfrac{\frac{\phi^2}{3}-G_a^{x^3}}{2\times3+4}+\orange\dfrac{(x^2+y^2)^\frac{1}{2}}{\tan\psi^\tau+2/3}" id="input" />
<div id="math"></div>
<input id="permalink" type="button" value="permalink">
<script src="main.js" type="text/javascript"></script>
</body>
</html>

View File

@ -4,7 +4,7 @@ body {
font-size: 72px;
}
input {
#input {
margin: 0px;
font-size: 100%;
width: 100%;

View File

@ -1,6 +1,7 @@
window.onload = function() {
function init() {
var input = document.getElementById("input");
var math = document.getElementById("math");
var permalink = document.getElementById("permalink");
if ("oninput" in input) {
input.addEventListener("input", reprocess, false);
@ -8,9 +9,20 @@ window.onload = function() {
input.attachEvent("onkeyup", reprocess);
}
permalink.addEventListener("click", function() {
window.location.search = "?text=" + encodeURIComponent(input.value);
});
var match = (/(?:^\?|&)text=([^&]+)/).exec(window.location.search);
if (match) {
input.value = decodeURIComponent(match[1]);
}
reprocess();
function reprocess() {
katex.process(input.value, math);
}
};
}
init();