Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'touchclickfix'

  • Loading branch information...
commit 0ede7677f36fdc4c22effe5d367f752a30ae934d 2 parents cd3f355 + b26ae2d
@davidaurelio davidaurelio authored
Showing with 47 additions and 3 deletions.
  1. +20 −3 example/library/movies/event-click.js
  2. +27 −0 test/renderer/svg-spec.js
View
23 example/library/movies/event-click.js
@@ -1,9 +1,7 @@
/**
- * event click
- *
* Path w/ events.
*/
-var rectPath = new Rect(150, 150, 150, 150).attr({fillColor: 'red'});
+var rectPath = bonsai.Path.rect(150, 150, 150, 150).attr({fillColor: 'red'});
var colors = [
'green',
'blue',
@@ -14,7 +12,26 @@ var index = 0;
stage.addChild(rectPath);
+
rectPath.on('click', function(data){
+ counts.click++; updateCountsText();
if (++index == colors.length) index = 0;
rectPath.attr({fillColor: colors[index]});
});
+rectPath.on('pointerdown', function(data){
+ counts.pointerdown++; updateCountsText();
+});
+rectPath.on('pointerup', function(data){
+ counts.pointerup++; updateCountsText();
+});
+
+var t = new Text().attr({x: 100, y: 10});
+t.addTo(stage);
+var counts = {
+ click: 0, pointerdown: 0, pointerup: 0
+};
+
+
+function updateCountsText() {
+ t.attr({text: 'counts: ' + JSON.stringify(counts)});
+}
View
27 test/renderer/svg-spec.js
@@ -181,5 +181,32 @@ define([
expect(frameTimes).toEqual([]);
});
});
+
+ function createTouchEvent(which) {
+ var evt = document.createEvent('UIEvent');
+ evt.initEvent(which, true, true);
+ evt.view = window;
+ evt.altKey = false;
+ evt.ctrlKey = false;
+ evt.shiftKey = false;
+ evt.metaKey = false;
+ evt.touches = [{identifier:1}];
+ evt.changedTouches = evt.touches;
+ return evt;
+ }
+
+ describe('handleEvent', function() {
+ it('should only fire one `click` for touchstart+touchend', function() {
+ var numCalls = 0;
+ var listener = function(e) { if (e.type=='click') numCalls++; };
+ var renderer = createSvgRenderer();
+ renderer.on('userevent', listener);
+ renderer.svg.root.dispatchEvent(createTouchEvent('touchstart'));
+ renderer.svg.root.dispatchEvent(createTouchEvent('touchend'));
+ expect(numCalls)
+ .toBe(1);
+ renderer.removeListener('userevent', listener);
+ });
+ });
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.