Permalink
Browse files

manager should re-dispatch touch event to views

  • Loading branch information...
1 parent 4efbccb commit e412fa954428a78745716ac3261e6ceca0832f5b @ppcano committed Feb 10, 2012
@@ -90,6 +90,11 @@ Em.GestureManager = Em.Object.extend({
, handler
, result = true;
+ // view could response directly to touch events
+ handler = this.view[eventName];
+ if (Em.typeOf(handler) === 'function') {
+ handler.call(this.view, eventObject);
+ }
for (var i=0, l=gestures.length; i < l; i++) {
gesture = gestures[i];
@@ -4,117 +4,91 @@
// License: Licensed under MIT license (see license.js)
// ==========================================================================
-var set = Em.set;
-var get = Em.get;
+var application, view, touchEvent;
-var application;
-var manager;
-var numStart, numMove, numEnd, numCancel;
-
-var view = Em.View.create();
-var manager = Em.GestureManager.create()
-
-var gesture = Em.Object.extend({
- touchStart: function(evt, view, manager) {
- numStart++;
- if (view) manager.redispatchEventToView(view, 'touchstart')
- },
- touchMove: function(evt, view, manager) {
- numMove++;
- if (view) manager.redispatchEventToView(view, 'touchmove')
- },
- touchEnd: function(evt, view, manager) {
- numEnd++;
- if (view) manager.redispatchEventToView(view, 'touchend')
- },
- touchCancel: function(evt, view, manager) {
- numCancel++;
- if (view) manager.redispatchEventToView(view, 'touchcancel')
- }
-});
module("Gesture Manager",{
setup: function() {
- numStart = numMove = numEnd = numCancel = 0;
-
application = Em.Application.create();
-
- manager = Em.GestureManager.create({
- gestures: [
- gesture.create(),
- gesture.create()
- ]
- });
},
teardown: function() {
- manager.destroy();
application.destroy();
}
});
-test("UNUSED: manager should re-dispatch events to all gestures", function() {
-/*
- Em.run( function() {
+test("manager should re-dispatch event to view", function() {
- view.append();
-
- });
- var evt = {};
- manager.touchStart(evt, view);
- equals(numStart,2,"dispatch start event to all gestures");
-
- manager.touchMove(evt, view);
- equals(numMove,2,"dispatch move event to all gestures");
-
- manager.touchEnd(evt, view);
- equals(numEnd,2,"dispatch end event to all gestures");
-
- manager.touchCancel(evt, view);
- equals(numCancel,2,"dispatch cancel event to all gestures");
-*/
-});
-
-test("UNUSED:manager should re-dispatch event to view", function() {
-/*
- var numViewStart = numViewMove = numViewEnd = numViewCancel = 0;
+ var numViewStart = numViewMove = numViewEnd = numViewCancel = 0;
var view = Em.View.create({
- eventManager: manager,
-
- touchStart: function(evt, view, manager) {
+ touchStart: function(evt) {
numViewStart++;
},
- touchMove: function(evt, view, manager) {
+ touchMove: function(evt) {
numViewMove++;
},
- touchEnd: function(evt, view, manager) {
+ touchEnd: function(evt) {
numViewEnd++;
},
- touchCancel: function(evt, view, manager) {
+ touchCancel: function(evt) {
numViewCancel++;
}
});
- Em.run(function() {
- view.append();
+ Em.run( function() {
+ view.append();
});
- view.$().trigger('touchstart');
- equals(numStart,2,"start event goes to event manager");
- equals(numViewStart,1,"redispatch start event back to view");
+ touchEvent = new jQuery.Event('touchstart');
+ view.$().trigger(touchEvent);
- view.$().trigger('touchmove');
- equals(numMove,2,"move event goes to event manager");
- equals(numViewMove,1,"redispatch move event back to view");
+ touchEvent = new jQuery.Event('touchmove');
+ view.$().trigger(touchEvent);
- view.$().trigger('touchend');
- equals(numEnd,2,"end event goes to event manager");
- equals(numViewEnd,1,"redispatch end event back to view");
+ touchEvent = new jQuery.Event('touchend');
+ view.$().trigger(touchEvent);
- view.$().trigger('touchcancel');
- equals(numCancel,2,"cancel event goes to event manager");
- equals(numViewCancel,1,"redispatch cancel event back to view");
-*/
+ touchEvent = new jQuery.Event('touchcancel');
+ view.$().trigger(touchEvent);
+
+ equals(numViewStart,1,"dispatch start event to the view");
+ equals(numViewMove,1,"dispatch move event to the view");
+ equals(numViewEnd,1,"dispatch end event to the view");
+ equals(numViewCancel,1,"dispatch cancel event to the view");
+
+});
+
+test("TODO: manager should re-dispatch events to all gestures", function() {
+/*
+ manager = Em.GestureManager.create({
+ gestures: [
+ gesture.create(),
+ gesture.create()
+ ]
+ });
+var numStart, numMove, numEnd, numCancel;
+numStart = numMove = numEnd = numCancel = 0;
+var manager = Em.GestureManager.create()
+
+var gesture = Em.Object.extend({
+ touchStart: function(evt, view, manager) {
+ numStart++;
+ if (view) manager.redispatchEventToView(view, 'touchstart')
+ },
+ touchMove: function(evt, view, manager) {
+ numMove++;
+ if (view) manager.redispatchEventToView(view, 'touchmove')
+ },
+ touchEnd: function(evt, view, manager) {
+ numEnd++;
+ if (view) manager.redispatchEventToView(view, 'touchend')
+ },
+ touchCancel: function(evt, view, manager) {
+ numCancel++;
+ if (view) manager.redispatchEventToView(view, 'touchcancel')
+ }
});
+*/
+});

0 comments on commit e412fa9

Please sign in to comment.