www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 6dd6032ebcf7fed1e5277ee7ed03f6e078ad05d9
parent a66d285532d269372f8e91dd6d274544fd309bed
Author: Ben Alpert <spicyjalapeno@gmail.com>
Date:   Wed, 23 Jul 2014 20:23:50 -0700

Add permalink button to test page

Auditors: emily

Diffstat:
Mstatic/index.html | 3++-
Mstatic/main.css | 2+-
Mstatic/main.js | 16++++++++++++++--
3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/static/index.html b/static/index.html @@ -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> diff --git a/static/main.css b/static/main.css @@ -4,7 +4,7 @@ body { font-size: 72px; } -input { +#input { margin: 0px; font-size: 100%; width: 100%; diff --git a/static/main.js b/static/main.js @@ -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();