From 637d9c9e245d222d42390494751c9e7c0bcddb00 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 28 Jun 2013 22:05:37 +0200 Subject: svg: add clicking --- svg/subcan.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ svg/subcan_dxf.svg | 43 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 96 insertions(+), 3 deletions(-) diff --git a/svg/subcan.js b/svg/subcan.js index 9a48321..c1cee69 100644 --- a/svg/subcan.js +++ b/svg/subcan.js @@ -13,6 +13,34 @@ function simple_xpath(expr) { return nodes; } +function on_evt_click(node) { + var id = node.id.substring(4); + console.log("clicked", id); + + $.jsonRPC.request('light_get', { + params: [id], + error: function(result) { + console.log('light_get error', result); + }, + success: function(result) { + /* <<< */ + console.log('light_get', result['result']); + var set = result['result']['set']; + var newset = set ? 0 : 255; + $.jsonRPC.request('light_set', { + params: [id, newset], + error: function(result) { + console.log('light_set error', result); + }, + success: function(result) { + console.log('light_set ', id, ' => ', newset, ' OK: ', result['result']); + } + }); + /* >>> */ + } + }); +} + function prepare_cliprects() { var nodes = simple_xpath('//svg:rect[contains(@inkscape:label, "=")]'); console.log('setup'); @@ -25,6 +53,33 @@ function prepare_cliprects() { } } +function prepare_evts() { + $.jsonRPC.setup({ + endPoint: '/jsonrpc', + namespace: '' + }); + $.jsonRPC.request('ping', { + success: function(result) { + console.log('ping', result['result']); + }, + error: function(result) { + console.log('ping error', result); + } + }); + + var nodes = simple_xpath('//svg:g[@inkscape:label="events"]/svg:rect'); + console.log('setup events', nodes); + for (i in nodes) { + var node = nodes[i]; + var id = node.id; + console.log('event node', i, " => ", node); + node.onclick = (function() { + var current_node = node; + return function() { on_evt_click(current_node); } + })(); + } +} + function update_cliprect(node, dir, val) { //var cliprect = document.getElementById("cliprect-dali.lounge_buero-0"); //var t = new Date().getTime() / 2000 * Math.PI; @@ -99,5 +154,6 @@ function timer() { function doload() { prepare_cliprects(); + prepare_evts(); timer(); } diff --git a/svg/subcan_dxf.svg b/svg/subcan_dxf.svg index dd18259..f1c8343 100644 --- a/svg/subcan_dxf.svg +++ b/svg/subcan_dxf.svg @@ -22,10 +22,10 @@ id="script9227" />