Verified isSingleTouch and isMultiTouch functions.

This commit is contained in:
ahocevar
2012-06-20 16:02:41 +02:00
parent 66a5a8ad7a
commit f74d265dec
2 changed files with 17 additions and 5 deletions

View File

@@ -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);
};

View File

@@ -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);
});
});