| 1 | <!doctype html> |
| 2 | <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" > |
| 3 | <head> |
| 4 | <title>Testing Bubbling events</title> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 | <style type="text/css"> |
| 7 | @import "../../../dojo/resources/dojo.css"; |
| 8 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 9 | </style> |
| 10 | <script type="text/javascript"> |
| 11 | var dojoConfig = { |
| 12 | isDebug: true, |
| 13 | gfxRenderer: 'canvas' |
| 14 | } |
| 15 | </script> |
| 16 | <script type="text/javascript" src="../../../dojo/dojo.js"></script> |
| 17 | <script type="text/javascript"> |
| 18 | |
| 19 | require([ |
| 20 | "dojo/_base/array", |
| 21 | "dojox/gfx", |
| 22 | "dojo/touch", |
| 23 | "dojo/dom", |
| 24 | "dojo/on", |
| 25 | "dojo/sniff", |
| 26 | "dojo/ready" |
| 27 | ], function(array, gfx, touch, dom, on, has, ready){ |
| 28 | |
| 29 | var touchMaps = { |
| 30 | "press" : touch.press, |
| 31 | "release" : touch.release, |
| 32 | "move" : touch.move, |
| 33 | "over" : touch.over, |
| 34 | "out": touch.out |
| 35 | }, nativeMaps = has("touch") ? { |
| 36 | "press" : "touchstart", |
| 37 | "release" : "touchend", |
| 38 | "move" : "touchmove" |
| 39 | } : { |
| 40 | "press" : "mousedown", |
| 41 | "release":"mouseup", |
| 42 | "move" : "mousemove", |
| 43 | "over" : "mouseover", |
| 44 | "out" : "mouseout" |
| 45 | }, surfaces; |
| 46 | |
| 47 | function log(msg) { |
| 48 | var elt = document.createTextNode(msg); |
| 49 | var div = dom.byId('log'); |
| 50 | div.insertBefore(elt, div.firstChild); |
| 51 | div.insertBefore(document.createElement('br'), elt.nextSibling); |
| 52 | } |
| 53 | |
| 54 | function wireEvents(shape, events, dojoTouch){ |
| 55 | var maps = dojoTouch ? touchMaps : nativeMaps; |
| 56 | array.forEach(events, function(evt){ |
| 57 | var event = maps[evt]; |
| 58 | if(!event){ return; } |
| 59 | shape.on(maps[evt], function(e){ |
| 60 | e.preventDefault(); |
| 61 | var m = dojoTouch ? "touch." + evt : maps[evt]; |
| 62 | log(m +" received on " + shape.id + ". gfxTarget:" + (e.gfxTarget ? e.gfxTarget.id : "null")); |
| 63 | }); |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | function makeShapes(surface, useDojoTouch){ |
| 68 | var g = surface.createGroup(); |
| 69 | g.id = "g"; |
| 70 | var rect = g.createRect({x:50,y:10,width:180,height:220}).setFill('red'); |
| 71 | rect.id='rect1'; |
| 72 | var rect2 = g.createRect({x:10,y:150,width:110,height:175}).setFill('blue'); |
| 73 | rect2.id='rect2'; |
| 74 | var rect3 = g.createRect({x:50,y:360,width:50,height:50}).setFill('green'); |
| 75 | rect3.id='rect3'; |
| 76 | |
| 77 | wireEvents(rect, ["press", "release", "move", "over", "out"], useDojoTouch); |
| 78 | wireEvents(rect2, ["move", "over", "out"], useDojoTouch); |
| 79 | wireEvents(rect3, ["over", "out"], useDojoTouch); |
| 80 | wireEvents(rect3, ["over", "out"], useDojoTouch); |
| 81 | wireEvents(g, ["press","out"], useDojoTouch); |
| 82 | wireEvents(surface, ["press","move"], useDojoTouch); |
| 83 | } |
| 84 | |
| 85 | function buildScenes(){ |
| 86 | surfaces = []; |
| 87 | var surface = gfx.createSurface("testDojoTouch", 300, 400); |
| 88 | surface.id = "surface"; |
| 89 | surfaces.push(surface); |
| 90 | makeShapes(surface, true); |
| 91 | surface = gfx.createSurface("testNative", 300, 400); |
| 92 | surface.id = "surface"; |
| 93 | surfaces.push(surface); |
| 94 | makeShapes(surface, false); |
| 95 | log("renderer:"+gfx.renderer); |
| 96 | } |
| 97 | |
| 98 | var switchRenderer = function(){ |
| 99 | var select = dom.byId("selectGfx"); |
| 100 | var r = select.options[select.selectedIndex].value; |
| 101 | require(["dojox/gfx/"+r], function(r){ |
| 102 | for(var i=0; i<surfaces.length; ++i){ |
| 103 | surfaces[i].destroy(); |
| 104 | } |
| 105 | gfx.switchTo(r); |
| 106 | buildScenes(); |
| 107 | }); |
| 108 | }; |
| 109 | |
| 110 | ready(function(){ |
| 111 | buildScenes(); |
| 112 | var select = dom.byId("selectGfx"); |
| 113 | on(select,"change",function(e){ |
| 114 | switchRenderer(); |
| 115 | }); |
| 116 | array.forEach(select.options, function(opt,i){ |
| 117 | if (gfx.renderer.indexOf(opt.value) !== -1){ |
| 118 | select.selectedIndex = i; |
| 119 | } |
| 120 | }); |
| 121 | }); |
| 122 | }); |
| 123 | |
| 124 | </script> |
| 125 | <style> |
| 126 | .drawing { |
| 127 | width: 300px; |
| 128 | height: 400px; |
| 129 | display:inline-block; |
| 130 | border-color: black; |
| 131 | border-width: 2; |
| 132 | border-style: solid; |
| 133 | } |
| 134 | </style> |
| 135 | </head> |
| 136 | <body> |
| 137 | <h1>Test bubbling with canvas.</h1> |
| 138 | <p>This page shows two canvas-based gfx surfaces: the surface on the left connects its shapes to input events via the dojo/touch API. |
| 139 | The surface on the right connects its shapes using native input event types (e.g. 'touchstart' or 'mousedown' depending |
| 140 | on the device).</p> |
| 141 | GFX Renderer: <select id="selectGfx"> |
| 142 | <option value="svg">SVG</option> |
| 143 | <option value="canvasWithEvents">Canvas</option> |
| 144 | </select> |
| 145 | </p> |
| 146 | <div id="testDojoTouch" class="drawing"></div> |
| 147 | <div id="testNative" class="drawing"></div> |
| 148 | <div id="log" style="width: 500px; height: 100px;overflow:scroll;"></div> |
| 149 | </body> |
| 150 | </html> |