diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-09-11 15:42:42 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-09-11 15:42:42 -0400 |
| commit | 5d18cc7380a076a0b02dff6ef47c85685d317d7e (patch) | |
| tree | dc388a06c5ac65418712559e73963c2bad66c432 /env.js | |
| parent | d88f2d2d8234f38d7f7bab51bd0222143db187e4 (diff) | |
touch events
Diffstat (limited to 'env.js')
| -rw-r--r-- | env.js | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -7,6 +7,7 @@ var environment = (function(){ var strided_wires = [], wires = [] var scale = [], root, tet, interval, duration var dot_color = "#333" + var drawing = true var palette = [ "#ff0000", @@ -87,7 +88,6 @@ var environment = (function(){ environment.bind = function(){ $(window).focus(environment.focus) $(window).blur(environment.blur) - $(window).mousemove(environment.mousemove) window.addEventListener("keydown", environment.keydown, true) $("#waveform").on("input", environment.setWaveform) $("#x").on("keydown", environment.stride) @@ -98,8 +98,17 @@ var environment = (function(){ $("#interval").on("input", environment.scale) $("#duration").on("input", environment.duration) $("#use_scale").on("change", environment.use_scale) - $(snap.node).on("mousedown", dot_grid.mousedown.bind(dot_grid)) - $(window).on("mouseup", dot_grid.mouseup.bind(dot_grid)) + if (is_mobile) { + snap.node.addEventListener("touchstart", getFirstTouch( dot_grid.mousedown.bind(dot_grid) )) + document.addEventListener("touchmove", getFirstTouch( environment.mousemove)) + document.addEventListener("touchend", dot_grid.mouseup.bind(dot_grid) ) + $("#draw").on("change", environment.check_drawing) + } + else { + $(snap.node).on("mousedown", dot_grid.mousedown.bind(dot_grid)) + $(window).mousemove(environment.mousemove) + $(window).on("mouseup", dot_grid.mouseup.bind(dot_grid)) + } } environment.blur = function(){ last_p = null @@ -109,6 +118,9 @@ var environment = (function(){ environment.use_scale = function(){ use_scale = $("#use_scale").get(0).checked } + environment.check_drawing = function(){ + drawing = $("#draw").get(0).checked + } environment.duration = function(){ duration = parseInt( $("#duration").val() ) || 1000 duration /= 1000 @@ -314,8 +326,9 @@ var environment = (function(){ } } } - DotGrid.prototype.mousedown = function(e){ - var p = environment.positionFromEvent(e) + DotGrid.prototype.mousedown = function(touch, e){ + if (! drawing) return + var p = environment.positionFromEvent(touch) var q = this.quantize(p) if (! this.active) { this.active = new Wire ({ @@ -326,7 +339,7 @@ var environment = (function(){ return } else if (this.active) { - e.preventDefault() + (e || touch).preventDefault() this.active.setTail(q) this.active = null } |
