frac/index.html

87 lines
2.8 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
2017-04-29 17:30:52 +00:00
<!-- frac.js (C) 2012-present SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html>
2017-04-29 17:30:52 +00:00
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Fraction Live Demo</title>
<style>
a { text-decoration: none }
</style>
</head>
<body>
<pre>
<b><a href="http://sheetjs.com">SheetJS Fraction Live Demo</a></b>
<a href="https://github.com/SheetJS/frac">Source Code Repo</a>
<a href="https://github.com/SheetJS/frac/issues">Issues? Something look weird? Click here and report an issue</a>
</pre>
<table>
<tr><td><b>Number:</b></td><td><input type="text" id="val" value="1.3"></td></tr>
<tr><td><b>Denominator Digits:</b></td><td><input type="text" id="fmt" value="1"></td></tr>
<tr><td><b>Use Mixed Fraction:</b></td><td><input type="checkbox" id="mix" name="mixd" checked></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td><b>Mediant Fraction:</b></td><td><pre id="frm"></pre></td></tr>
<tr><td><b>Aberth Fraction:</b></td><td><pre id="fra"></pre></td></tr>
</table>
2017-04-29 17:30:52 +00:00
<script src="frac.js"></script>
<script>
/*jshint browser:true */
/*global frac */
var V = document.getElementById('val');
var F = document.getElementById('fmt');
var X = document.getElementById('mix');
var M = document.getElementById('frm');
var A = document.getElementById('fra');
2017-04-29 17:30:52 +00:00
function update() {
var x, D, mixed, oM, oA;
x = Number(V.value);
D = Math.pow(10, Number(F.value))-1;
mixed = X.checked;
if(x !== x) { M.innerHTML=A.innerHTML = V.value + " not valid"; return; }
if(D !== D) { M.innerHTML=A.innerHTML = F.value + " not valid"; return; }
try {
oM = frac(x, D, mixed);
M.innerHTML = oM[0] + " " + oM[1] + "/" + oM[2];
} catch(e) { M.innerHTML = e.message; }
try {
oA = frac.cont(x, D, mixed);
A.innerHTML = oA[0] + " " + oA[1] + "/" + oA[2];
} catch(e) { A.innerHTML = e.message; }
}
2017-04-29 17:30:52 +00:00
/* Bind to relevant events */
if(F.addEventListener) {
F.addEventListener('keyup', update);
V.addEventListener('keyup', update);
M.addEventListener('change', update);
X.addEventListener('change', update);
} else if(F.attachEvent) {
F.attachEvent('onkeyup', update);
V.attachEvent('onkeyup', update);
M.attachEvent('onchange', update);
X.attachEvent('onchange', update);
} else {
F.oninput = update;
V.oninput = update;
M.onchange = update;
X.onchange = update;
}
2017-04-29 17:30:52 +00:00
update();
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36810333-1']);
_gaq.push(['_trackPageview']);
2017-04-29 17:30:52 +00:00
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>