Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
128 lines (100 sloc) 2.57 KB
<style>
body {margin-left:100px; width:90%}
</style>
<title>Generic</title>
<script type="text/javascript" src="./jquery-1.5.min.js"></script>
<script>
svg_ns = 'http://www.w3.org/2000/svg';
// var wsUri = "ws://localhost:1234/connect";
var wsUri = "ws://127.0.0.1:1234/connect";
var websocket;
var output;
var c;
var glob = new Array();
$(document).ready(function(){
output = document.getElementById("output");
});
function svg_event(x) {
log("event" + x.type);
}
function onClose(evt) {
$("body").css({'background-color':'red'});
}
function onMessage(evt) {
try
{
// alert(evt.data);
eval(evt.data);
}
catch(e)
{
alert("oops:"+evt.data);
}
}
function onError(evt) {
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message) {
writeToScreen("SENT: " + message);
websocket.send(message);
}
function send(msg) {
websocket.send(msg);
}
function logit(x) {
$("#log").append(x);
}
function log(x) {
writeToScreen(x);
}
start = function(){
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.attr({opacity: 1});
}
move = function (dx, dy) {
// move will be called with dx and dy
this.attr({cx: this.ox + dx, cy: this.oy + dy});
},
up = function () {
// alert('stop');
// restoring state
this.attr({opacity: .5});
};
function writeToScreen(message) {
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}
function start_any(){
// read the form
var mod=$("input[name=mod]").val();
start_session(mod);
return(false);
}
function start_session(mod){
writeToScreen("connecting");
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt, mod) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
return(false);
}
function onOpen(evt, mod) {
writeToScreen("connected" + mod);
doSend("start:" + mod + ":");
}
</script>
<h2>Generic</h2>
<p>To start the demo click on
<a href="#" onclick="start_session('svg_demo')">start simulation</a>
or enter <b>svg_demo</b> into the entry below and hit enter.
<form id="n1" onsubmit="return start_any()">
<P>Name of module: <INPUT NAME="mod" size ="42" value="svg_demo">
</form>
<div id="a1"></div>
<div id="output"></div>
<div id="log"></div>
</html>