diff options
author | David Lamparter <equinox@diac24.net> | 2013-06-28 22:05:37 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2013-06-28 22:05:37 +0200 |
commit | 637d9c9e245d222d42390494751c9e7c0bcddb00 (patch) | |
tree | 33e2d581ea65ab20fd20d79a43c5bd74b8475f36 | |
parent | 5f7a729e53bb84a190b67031769458898783552c (diff) |
svg: add clicking
-rw-r--r-- | svg/subcan.js | 56 | ||||
-rw-r--r-- | 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" /> <script xlink:href="jquery.jsonrpc.js" - id="script9227" /> + id="script4" /> <script xlink:href="subcan.js" - id="script9227" /> + id="script6" /> <defs id="defs4"> <clipPath @@ -172,7 +172,7 @@ inkscape:cx="680.17135" inkscape:cy="386.87652" inkscape:document-units="px" - inkscape:current-layer="layer1" + inkscape:current-layer="layer9" showgrid="true" width="1052.36px" inkscape:window-width="1600" @@ -4387,4 +4387,41 @@ inkscape:connector-curvature="0" sodipodi:nodetypes="cczcc" /> </g> + <g + inkscape:groupmode="layer" + id="layer9" + inkscape:label="events"> + <rect + style="fill:#000000;fill-opacity:0.00392157;stroke:none" + id="evt_dali.lounge_durchreiche" + width="112" + height="120" + x="280.5" + y="271.5" + inkscape:label="#rect3791" /> + <rect + style="fill:#000000;fill-opacity:0.00392157;stroke:none" + id="evt_dali.lounge_bar" + width="112" + height="120" + x="400.5" + y="271.5" + inkscape:label="#rect3791" /> + <rect + style="fill:#000000;fill-opacity:0.00392157;stroke:none" + id="evt_dali.lounge_buero" + width="112" + height="120" + x="224.5" + y="79.5" + inkscape:label="#rect3791" /> + <rect + style="fill:#000000;fill-opacity:0.00392157;stroke:none" + id="evt_dali.lounge_buehne" + width="112" + height="120" + x="104.5" + y="79.5" + inkscape:label="#rect3791" /> + </g> </svg> |