From f74d265dec1a557f7622b219c4e43953c62bdaf1 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 20 Jun 2012 16:02:41 +0200 Subject: [PATCH] Verified isSingleTouch and isMultiTouch functions. --- src/ol/event/Events.js | 8 ++++---- test/spec/ol/Events.test.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ol/event/Events.js b/src/ol/event/Events.js index 9b1702e466..981c03b119 100644 --- a/src/ol/event/Events.js +++ b/src/ol/event/Events.js @@ -11,21 +11,21 @@ goog.require('goog.style'); /** * Determine whether event was caused by a single touch * - * @param {Event} evt + * @param {!Event} evt * @return {boolean} */ ol.event.isSingleTouch = function(evt) { - return evt.touches && evt.touches.length == 1; + return !!(evt.touches && evt.touches.length == 1); }; /** * Determine whether event was caused by a multi touch * - * @param {Event} evt + * @param {!Event} evt * @return {boolean} */ ol.event.isMultiTouch = function(evt) { - return evt.touches && evt.touches.length > 1; + return !!(evt.touches && evt.touches.length > 1); }; diff --git a/test/spec/ol/Events.test.js b/test/spec/ol/Events.test.js index 198dc61109..53a7f86e93 100644 --- a/test/spec/ol/Events.test.js +++ b/test/spec/ol/Events.test.js @@ -122,7 +122,7 @@ describe("ol.Events", function() { events.destroy(); }); - it("has working on() and un() convenience methods", function() { + it("has on() and un() convenience methods", function() { var scope = {}, events = new ol.event.Events("foo"); log = []; @@ -149,4 +149,16 @@ describe("ol.Events", function() { events.destroy(); }); + it("provides an isSingleTouch() function", function() { + expect(ol.event.isSingleTouch({touches: [{}, {}]})).toBe(false); + expect(ol.event.isSingleTouch({touches: [{}]})).toBe(true); + expect(ol.event.isSingleTouch({})).toBe(false); + }); + + it("provides an isMultiTouch() function", function() { + expect(ol.event.isMultiTouch({touches: [{}, {}]})).toBe(true); + expect(ol.event.isMultiTouch({touches: [{}]})).toBe(false); + expect(ol.event.isMultiTouch({})).toBe(false); + }); + });