From 681b90c17955d7342a48afb1228703203b30aac0 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 8 Mar 2012 14:03:45 +0100 Subject: move javascript code out of html file. --- munia.html | 229 +------------------------------------------------------- proto.js | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/http.cc | 9 +++ 3 files changed, 255 insertions(+), 228 deletions(-) create mode 100644 proto.js diff --git a/munia.html b/munia.html index 2a833eb..2dc3099 100644 --- a/munia.html +++ b/munia.html @@ -35,234 +35,7 @@ background-color:yellow;
- - + diff --git a/proto.js b/proto.js new file mode 100644 index 0000000..2d5e9c0 --- /dev/null +++ b/proto.js @@ -0,0 +1,245 @@ +/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ + +var BrowserDetect = { + init: function () { + this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; + this.version = this.searchVersion(navigator.userAgent) + || this.searchVersion(navigator.appVersion) + || "an unknown version"; + this.OS = this.searchString(this.dataOS) || "an unknown OS"; + }, + searchString: function (data) { + for (var i=0;iError' + exception + '

'); +} + +var canvas = document.createElement('canvas'); +canvas.height = 600; +canvas.width = 800; +ctx = canvas.getContext("2d"); + +document.addEventListener('mousemove', ev_mousemove, false); +document.addEventListener('mouseup', ev_mouseup, false); +/* +canvas.addEventListener('mousedown', ev_mousedown, false); +//cancas.addEventListener('dragend', ev_mousemove, false); +*/ + +offsetX = offsetY = 0; +element = canvas; +if (element.offsetParent) { + do { + offsetX += element.offsetLeft; + offsetY += element.offsetTop; + } while ((element = element.offsetParent)); +} + +function update_color() { + color = document.getElementById("color").value; +} + +function ev_mouseup(ev) { + dragged = ''; +} + +function ev_mousemove (ev) +{ + if(dragged == '') return; + + var x, y; + x = ev.clientX; + y = ev.clientY; + + socket_lm.send("move " + dragged + " " + x + " " + y); +} + +function submit() { + var data = document.getElementById("input_data").value; + socket_lm.send(data); +} + +function clear() { + document.getElementById("input_data").value = ""; +} + +function deleteTask(id) { + socket_lm.send("del " + id + ";"); +} diff --git a/src/http.cc b/src/http.cc index 3dff64e..c755442 100644 --- a/src/http.cc +++ b/src/http.cc @@ -51,6 +51,15 @@ int callback_http(struct libwebsocket_context * context, break; } + // script + if(in && strcmp((const char *)in, "/proto.js") == 0) { + if(libwebsockets_serve_http_file(wsi, + LOCAL_RESOURCE_PATH"/proto.js", + "text/javascript")) + fprintf(stderr, "Failed to send javascript\n"); + break; + } + /* send the script... when it runs it'll start websockets */ if(libwebsockets_serve_http_file(wsi, -- cgit v1.2.3