ソースを参照

touch bugfixes

Adam Shaw 9 年 前
コミット
f46979e090
3 ファイル変更26 行追加9 行削除
  1. 19 1
      src/common/DragListener.js
  2. 2 0
      src/common/Grid.events.js
  3. 5 8
      src/common/Grid.js

+ 19 - 1
src/common/DragListener.js

@@ -22,6 +22,7 @@ var DragListener = FC.DragListener = Class.extend(ListenerMixin, {
 	isDelayEnded: false,
 	isDragging: false,
 	isTouch: false,
+	isIgnoringMouse: false,
 
 	delay: null,
 	delayTimeoutId: null,
@@ -41,7 +42,10 @@ var DragListener = FC.DragListener = Class.extend(ListenerMixin, {
 		var isTouch = getEvIsTouch(ev);
 
 		if (ev.type === 'mousedown') {
-			if (!isPrimaryMouseButton(ev)) {
+			if (this.isIgnoringMouse) {
+				return;
+			}
+			else if (!isPrimaryMouseButton(ev)) {
 				return;
 			}
 			else {
@@ -97,6 +101,20 @@ var DragListener = FC.DragListener = Class.extend(ListenerMixin, {
 
 			this.isInteracting = false;
 			this.handleInteractionEnd(ev);
+
+			// a touchstart+touchend on the same element will result in the following addition simulated events:
+			// +mouseover
+			// +mouseout
+			// +click
+			//
+			// let's ignore these bogus events
+			if (this.isTouch) {
+				var _this = this;
+				this.isIgnoringMouse = true;
+				setTimeout(function() {
+					_this.isIgnoringMouse = false;
+				}, 500);
+			}
 		}
 	},
 

+ 2 - 0
src/common/Grid.events.js

@@ -285,6 +285,7 @@ Grid.mixin({
 
 	// Builds a listener that will track user-dragging on an event segment.
 	// Generic enough to work with any type of Grid.
+	// Has side effect of setting/unsetting `segDragListener`
 	buildSegDragListener: function(seg) {
 		var _this = this;
 		var view = this.view;
@@ -395,6 +396,7 @@ Grid.mixin({
 
 	// seg isn't draggable, but let's use a generic DragListener
 	// simply for the delay, so it can be selected.
+	// Has side effect of setting/unsetting `segDragListener`
 	buildSegSelectListener: function(seg) {
 		var _this = this;
 		var view = this.view;

+ 5 - 8
src/common/Grid.js

@@ -35,6 +35,8 @@ var Grid = FC.Grid = Class.extend(ListenerMixin, {
 		this.view = view;
 		this.isRTL = view.opt('isRTL');
 		this.elsByFill = {};
+
+		this.dayDragListener = this.buildDayDragListener();
 	},
 
 
@@ -249,14 +251,14 @@ var Grid = FC.Grid = Class.extend(ListenerMixin, {
 
 	// Process a mousedown on an element that represents a day. For day clicking and selecting.
 	dayMousedown: function(ev) {
-		this.buildDayDragListener().startInteraction(ev, {
+		this.dayDragListener.startInteraction(ev, {
 			//distance: 5, // needs more work if we want dayClick to fire correctly
 		});
 	},
 
 
 	dayTouchStart: function(ev) {
-		this.buildDayDragListener().startInteraction(ev, {
+		this.dayDragListener.startInteraction(ev, {
 			delay: this.view.opt('longPressDelay')
 		});
 	},
@@ -271,14 +273,10 @@ var Grid = FC.Grid = Class.extend(ListenerMixin, {
 		var dayClickHit; // null if invalid dayClick
 		var selectionSpan; // null if invalid selection
 
-		if (this.dayDragListener) {
-			return this.dayDragListener;
-		}
-
 		// this listener tracks a mousedown on a day element, and a subsequent drag.
 		// if the drag ends on the same day, it is a 'dayClick'.
 		// if 'selectable' is enabled, this listener also detects selections.
-		var dragListener = this.dayDragListener = new HitDragListener(this, {
+		var dragListener = new HitDragListener(this, {
 			scroll: view.opt('dragScroll'),
 			interactionStart: function() {
 				dayClickHit = dragListener.origHit;
@@ -327,7 +325,6 @@ var Grid = FC.Grid = Class.extend(ListenerMixin, {
 					view.reportSelection(selectionSpan, ev);
 				}
 				enableCursor();
-				_this.dayDragListener = null;
 			}
 		});