Просмотр исходного кода

change api for registering drag listeners

Adam Shaw 8 лет назад
Родитель
Сommit
3e6e7e8896

+ 22 - 36
src/component/CoordChronoComponentMixin.js

@@ -1,6 +1,18 @@
 
 var CoordChronoComponentMixin = {
 
+	eventPointingClass: EventPointing,
+	eventDraggingClass: EventDragging,
+	eventResizingClass: EventResizing,
+	externalDroppingClass: ExternalDropping,
+
+	dateClicking: null,
+	dateSelecting: null,
+	eventPointing: null,
+	eventDragging: null,
+	eventResizing: null,
+	externalDropping: null,
+
 	// self-config, overridable by subclasses
 	segSelector: '.fc-event-container > *', // what constitutes an event element?
 
@@ -11,23 +23,8 @@ var CoordChronoComponentMixin = {
 
 	hitsNeededDepth: 0, // necessary because multiple callers might need the same hits
 
-	dragListeners: null,
-
-	eventPointingClass: EventPointing,
-	eventPointing: null,
-
-	eventDraggingClass: EventDragging,
-	eventDragging: null,
-
-	eventResizingClass: EventResizing,
-	eventResizing: null,
-
-	externalDroppingClass: ExternalDropping,
-	externalDropping: null,
-
 
 	initCoordChronoComponent: function() {
-		this.dragListeners = [];
 		this.externalDropping = new this.externalDroppingClass(this);
 	},
 
@@ -47,13 +44,12 @@ var CoordChronoComponentMixin = {
 	// Kills all in-progress dragging.
 	// Useful for when public API methods that result in re-rendering are invoked during a drag.
 	// Also useful for when touch devices misbehave and don't fire their touchend.
-	clearDragListeners: function() {
-		var dragListeners = this.dragListeners;
-		var i;
-
-		for (i = 0; i < dragListeners.length; i++) {
-			dragListeners[i].endInteraction();
-		}
+	endInteractions: function() {
+		this.dateClicking.end();
+		this.dateSelecting.end();
+		this.eventPointing.end();
+		this.eventDragging.end();
+		this.eventResizing.end();
 	},
 
 
@@ -66,8 +62,8 @@ var CoordChronoComponentMixin = {
 	setElement: function(el) {
 		ChronoComponent.prototype.setElement.apply(this, arguments);
 
-		new DateClicking(this).bindToEl(this.el);
-		new DateSelecting(this).bindToEl(this.el);
+		(this.dateClicking = new DateClicking(this)).bindToEl(this.el);
+		(this.dateSelecting = new DateSelecting(this)).bindToEl(this.el);
 
 		this.eventPointing = new this.eventPointingClass(this);
 		this.eventDragging = new this.eventDraggingClass(this);
@@ -82,14 +78,14 @@ var CoordChronoComponentMixin = {
 	removeElement: function() {
 		ChronoComponent.prototype.removeElement.apply(this, arguments);
 
-		this.clearDragListeners();
+		this.endInteractions();
 	},
 
 
 	unrenderEvents: function() {
 		ChronoComponent.prototype.unrenderEvents.apply(this, arguments);
 
-		this.clearDragListeners(); // we wanted to add this action to event rendering teardown
+		this.endInteractions(); // we wanted to add this action to event rendering teardown
 	},
 
 
@@ -201,16 +197,6 @@ var CoordChronoComponentMixin = {
 	},
 
 
-	registerDragListener: function(dragListener) {
-		this.dragListeners.push(dragListener);
-	},
-
-
-	unregisterDragListener: function(dragListener) {
-		removeExact(this.dragListeners, dragListener);
-	},
-
-
 	/* Misc
 	------------------------------------------------------------------------------------------------------------------*/
 

+ 5 - 2
src/component/interaction/DateClicking.js

@@ -7,7 +7,6 @@ var DateClicking = Interaction.extend({
 	/*
 	component must implement:
 		- bindDateHandlerToEl
-		- registerDragListener
 		- getSafeHitFootprint
 		- getHitEl
 	*/
@@ -15,7 +14,11 @@ var DateClicking = Interaction.extend({
 		Interaction.call(this, component);
 
 		this.dragListener = this.buildDragListener();
-		component.registerDragListener(this.dragListener);
+	},
+
+
+	end: function() {
+		this.dragListener.endInteraction();
 	},
 
 

+ 5 - 2
src/component/interaction/DateSelecting.js

@@ -7,7 +7,6 @@ var DateSelecting = Interaction.extend({
 	/*
 	component must implement:
 		- bindDateHandlerToEl
-		- registerDragListener
 		- getSafeHitFootprint
 		- renderHighlight
 		- unrenderHighlight
@@ -16,7 +15,11 @@ var DateSelecting = Interaction.extend({
 		Interaction.call(this, component);
 
 		this.dragListener = this.buildDragListener();
-		component.registerDragListener(this.dragListener);
+	},
+
+
+	end: function() {
+		this.dragListener.endInteraction();
 	},
 
 

+ 7 - 8
src/component/interaction/EventDragging.js

@@ -8,8 +8,6 @@ var EventDragging = Interaction.extend({
 	/*
 	component impements:
 		- bindSegHandlerToEl
-		- registerDragListener
-		- unregisterDragListener
 		- publiclyTrigger
 		- diffDates
 		- eventRangesToEventFootprints
@@ -18,6 +16,13 @@ var EventDragging = Interaction.extend({
 	*/
 
 
+	end: function() {
+		if (this.dragListener) {
+			this.dragListener.endInteraction();
+		}
+	},
+
+
 	getSelectionDelay: function() {
 		var delay = this.opt('eventLongPressDelay');
 
@@ -86,12 +91,9 @@ var EventDragging = Interaction.extend({
 			},
 			interactionEnd: function(ev) {
 				_this.dragListener = null;
-				_this.component.unregisterDragListener(dragListener);
 			}
 		});
 
-		this.component.registerDragListener(dragListener);
-
 		return dragListener;
 	},
 
@@ -246,12 +248,9 @@ var EventDragging = Interaction.extend({
 				});
 
 				_this.dragListener = null;
-				component.unregisterDragListener(dragListener);
 			}
 		});
 
-		component.registerDragListener(dragListener);
-
 		return dragListener;
 	},
 

+ 7 - 5
src/component/interaction/EventResizing.js

@@ -8,8 +8,6 @@ var EventResizing = Interaction.extend({
 	/*
 	component impements:
 		- bindSegHandlerToEl
-		- registerDragListener
-		- unregisterDragListener
 		- publiclyTrigger
 		- diffDates
 		- eventRangesToEventFootprints
@@ -19,6 +17,13 @@ var EventResizing = Interaction.extend({
 	*/
 
 
+	end: function() {
+		if (this.dragListener) {
+			this.dragListener.endInteraction();
+		}
+	},
+
+
 	bindToEl: function(el) {
 		var component = this.component;
 
@@ -141,12 +146,9 @@ var EventResizing = Interaction.extend({
 				}
 
 				_this.dragListener = null;
-				component.unregisterDragListener(dragListener);
 			}
 		});
 
-		component.registerDragListener(dragListener);
-
 		return dragListener;
 	},
 

+ 7 - 5
src/component/interaction/ExternalDropping.js

@@ -7,8 +7,6 @@ var ExternalDropping = Interaction.extend(ListenerMixin, {
 
 	/*
 	component impements:
-		- registerDragListener
-		- unregisterDragListener
 		- eventRangesToEventFootprints
 		- isEventInstanceGroupAllowed
 		- isExternalInstanceGroupAllowed
@@ -17,6 +15,13 @@ var ExternalDropping = Interaction.extend(ListenerMixin, {
 	*/
 
 
+	end: function() {
+		if (this.dragListener) {
+			this.dragListener.endInteraction();
+		}
+	},
+
+
 	bindToDocument: function() {
 		this.listenTo($(document), {
 			dragstart: this.handleDragStart, // jqui
@@ -120,12 +125,9 @@ var ExternalDropping = Interaction.extend(ListenerMixin, {
 
 				_this.isDragging = false;
 				_this.dragListener = null;
-				component.unregisterDragListener(dragListener);
 			}
 		});
 
-		component.registerDragListener(dragListener);
-
 		dragListener.startDrag(ev); // start listening immediately
 	},