| 1 |
<html> |
| 2 |
<head> |
| 3 |
<title>JSXGraph example</title> |
| 4 |
<link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" /> |
| 5 |
|
| 6 |
<!--script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/MathJax/MathJax.js"></script--> |
| 7 |
<script type="text/javascript" src="../distrib/jsxgraphcore.js"></script> |
| 8 |
<script type="text/javascript" src="../src/reader/geonext.js"></script> |
| 9 |
|
| 10 |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.js"></script> |
| 11 |
</head> |
| 12 |
<body> |
| 13 |
|
| 14 |
<h2>WRP Playground</h2> |
| 15 |
|
| 16 |
<input type="radio" name="export" id="type-js" /> JavaScript <input type="radio" name="export" id="type-jc" checked="checked" /> JessieCode |
| 17 |
<div style="width:800px"> |
| 18 |
<div id="jxgbox" class="jxgbox" style="width:800px; height:800px; float: left;"></div> |
| 19 |
</div> |
| 20 |
|
| 21 |
<textarea id="debug" style="display:block;" cols="100" rows="50">DEBUG</textarea> |
| 22 |
<button onclick="exec();">Execute</button> |
| 23 |
<div id="jxgbox2" class="jxgbox" style="width:800px; height:800px; float: left;"></div> |
| 24 |
<script type="text/javascript"> |
| 25 |
/* <![CDATA[ */ |
| 26 |
|
| 27 |
var board, test, |
| 28 |
wrp = (function() { |
| 29 |
board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 5, 5, -5], axis: true, keepaspectratio: true}); |
| 30 |
var p = board.create('point', [1, 2], {strokeColor: 'blue'}); |
| 31 |
|
| 32 |
if ($('#type-jc').is(':checked')) { |
| 33 |
console.log('dumping jessie'); |
| 34 |
$('#debug').html(JXG.Dump.toJessie(board)); |
| 35 |
} else { |
| 36 |
console.log('dumping js'); |
| 37 |
$('#debug').html(JXG.Dump.toJavaScript(board)); |
| 38 |
} |
| 39 |
})(); |
| 40 |
|
| 41 |
function exec() { |
| 42 |
var code = document.getElementById('debug').value, |
| 43 |
p; |
| 44 |
test = JXG.JSXGraph.initBoard('jxgbox2', {boundingbox: [-5, 5, 5, -5], axis: false, keepaspectratio: true}); |
| 45 |
|
| 46 |
code = 'use jxgbox2;\n' + code; |
| 47 |
|
| 48 |
p = new JXG.JessieCode(); |
| 49 |
p.parse(code); |
| 50 |
} |
| 51 |
|
| 52 |
(function () { |
| 53 |
var file_drop = document.getElementById('jxgbox'); |
| 54 |
|
| 55 |
function supportsFileAPI() { |
| 56 |
return window.File && window.FileReader && window.FileList && window.Blob; |
| 57 |
} |
| 58 |
|
| 59 |
function playFile(f) { |
| 60 |
var freader = new FileReader(); |
| 61 |
|
| 62 |
freader.onload = function(e) { |
| 63 |
if (board) { |
| 64 |
JXG.JSXGraph.freeBoard(board); |
| 65 |
} |
| 66 |
|
| 67 |
board = JXG.JSXGraph.loadBoardFromString('jxgbox', e.target.result, 'geonext'); |
| 68 |
if ($('#type-jc').is(':checked')) { |
| 69 |
console.log('dumping jessie'); |
| 70 |
$('#debug').html(JXG.Dump.toJessie(board)); |
| 71 |
} else { |
| 72 |
console.log('dumping js'); |
| 73 |
$('#debug').html(JXG.Dump.toJavaScript(board)); |
| 74 |
} |
| 75 |
}; |
| 76 |
freader.readAsText(f); |
| 77 |
} |
| 78 |
|
| 79 |
function handleDrop(e) { |
| 80 |
e.stopPropagation(); |
| 81 |
e.preventDefault(); |
| 82 |
|
| 83 |
var files = e.dataTransfer.files, // file list object |
| 84 |
output = [], i, f; |
| 85 |
|
| 86 |
if (files.length > 0) { |
| 87 |
f = files[0]; |
| 88 |
|
| 89 |
playFile(f); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
function handleDragOver(e) { |
| 94 |
e.stopPropagation(); |
| 95 |
e.preventDefault(); |
| 96 |
} |
| 97 |
|
| 98 |
file_drop.addEventListener('dragover', handleDragOver, false); |
| 99 |
file_drop.addEventListener('drop', handleDrop, false); |
| 100 |
})(); |
| 101 |
|
| 102 |
/* ]]> */ |
| 103 |
</script> |
| 104 |
</body> |
| 105 |
</html> |