From 5516665db1590e4af211cd59ce6f756433c7a68f Mon Sep 17 00:00:00 2001 From: Lewis Hemens Date: Sat, 11 Jan 2014 21:02:14 +0000 Subject: [PATCH] Added basic mobile touch support. Needs a library. --- js-lib/controller.js | 24 ++++++++++++++++++++++++ root.html | 1 + 2 files changed, 25 insertions(+) diff --git a/js-lib/controller.js b/js-lib/controller.js index 9414379..6927d5c 100644 --- a/js-lib/controller.js +++ b/js-lib/controller.js @@ -26,6 +26,7 @@ ascii.Controller = function(view, state) { // TODO: Setup different bindings for tablet/mobile. this.installDesktopBindings(); + this.installTouchBindings(); }; ascii.Controller.prototype.handlePress = function(x, y) { @@ -92,6 +93,7 @@ ascii.Controller.prototype.handleZoom = function(delta) { ascii.Controller.prototype.installDesktopBindings = function() { var controller = this; $(this.view.canvas).bind('mousewheel', function(e) { + controller.handleZoom(e.originalEvent.wheelDelta); }); $(this.view.canvas).mousedown(function(e) { @@ -105,3 +107,25 @@ ascii.Controller.prototype.installDesktopBindings = function() { }); $(window).resize(function(e) { controller.view.resizeCanvas() }); }; + +ascii.Controller.prototype.installTouchBindings = function() { + var controller = this; + $(this.view.canvas).bind("touchstart", function(e) { + e.stopPropagation(); + controller.handlePress( + e.originalEvent.touches[0].clientX, + e.originalEvent.touches[0].clientY); + }); + $(this.view.canvas).bind("touchend", function(e) { + e.stopPropagation(); + controller.handleRelease( + e.originalEvent.touches[0].clientX, + e.originalEvent.touches[0].clientY); + }); + $(this.view.canvas).bind("touchmove", function(e) { + e.stopPropagation(); + controller.handleMove( + e.originalEvent.touches[0].clientX, + e.originalEvent.touches[0].clientY); + }); +}; diff --git a/root.html b/root.html index 5fda18f..394acd9 100644 --- a/root.html +++ b/root.html @@ -2,6 +2,7 @@ + asciiflow-2.0