Преглед на файлове

hitsNeeded/hitsNotNeeded for dueling HitDragListeners

Adam Shaw преди 9 години
родител
ревизия
618b9e10ba
променени са 5 файла, в които са добавени 52 реда и са изтрити 13 реда
  1. 16 0
      src/agenda/AgendaView.js
  2. 10 0
      src/basic/BasicView.js
  3. 2 2
      src/common/DayGrid.limit.js
  4. 14 0
      src/common/Grid.js
  5. 10 11
      src/common/HitDragListener.js

+ 16 - 0
src/agenda/AgendaView.js

@@ -309,6 +309,22 @@ var AgendaView = FC.AgendaView = View.extend({
 	// forward all hit-related method calls to the grids (dayGrid might not be defined)
 
 
+	hitsNeeded: function() {
+		this.timeGrid.hitsNeeded();
+		if (this.dayGrid) {
+			this.dayGrid.hitsNeeded();
+		}
+	},
+
+
+	hitsNotNeeded: function() {
+		this.timeGrid.hitsNotNeeded();
+		if (this.dayGrid) {
+			this.dayGrid.hitsNotNeeded();
+		}
+	},
+
+
 	prepareHits: function() {
 		this.timeGrid.prepareHits();
 		if (this.dayGrid) {

+ 10 - 0
src/basic/BasicView.js

@@ -268,6 +268,16 @@ var BasicView = FC.BasicView = View.extend({
 	// forward all hit-related method calls to dayGrid
 
 
+	hitsNeeded: function() {
+		this.dayGrid.hitsNeeded();
+	},
+
+
+	hitsNotNeeded: function() {
+		this.dayGrid.hitsNotNeeded();
+	},
+
+
 	prepareHits: function() {
 		this.dayGrid.prepareHits();
 	},

+ 2 - 2
src/common/DayGrid.limit.js

@@ -309,9 +309,9 @@ DayGrid.mixin({
 
 			// because segments in the popover are not part of a grid coordinate system, provide a hint to any
 			// grids that want to do drag-n-drop about which cell it came from
-			this.prepareHits();
+			this.hitsNeeded();
 			segs[i].hit = this.getCellHit(row, col);
-			this.releaseHits();
+			this.hitsNotNeeded();
 
 			segContainer.append(segs[i].el);
 		}

+ 14 - 0
src/common/Grid.js

@@ -136,6 +136,20 @@ var Grid = FC.Grid = Class.extend(ListenerMixin, {
 	/* Hit Area
 	------------------------------------------------------------------------------------------------------------------*/
 
+	hitsNeededDepth: 0, // necessary because multiple callers might need the same hits
+
+	hitsNeeded: function() {
+		if (!(this.hitsNeededDepth++)) {
+			this.prepareHits();
+		}
+	},
+
+	hitsNotNeeded: function() {
+		if (this.hitsNeededDepth && !(--this.hitsNeededDepth)) {
+			this.releaseHits();
+		}
+	},
+
 
 	// Called before one or more queryHit calls might happen. Should prepare any cached coordinates for queryHit
 	prepareHits: function() {

+ 10 - 11
src/common/HitDragListener.js

@@ -9,7 +9,7 @@ options:
 var HitDragListener = DragListener.extend({
 
 	component: null, // converts coordinates to hits
-		// methods: prepareHits, releaseHits, queryHit
+		// methods: hitsNeeded, hitsNotNeeded, queryHit
 
 	origHit: null, // the hit the mouse was over when listening started
 	hit: null, // the hit the mouse is over
@@ -31,7 +31,8 @@ var HitDragListener = DragListener.extend({
 		var origPoint;
 		var point;
 
-		this.computeCoords();
+		this.component.hitsNeeded();
+		this.computeScrollBounds(); // for autoscroll
 
 		if (ev) {
 			origPoint = { left: getEvX(ev), top: getEvY(ev) };
@@ -70,13 +71,6 @@ var HitDragListener = DragListener.extend({
 	},
 
 
-	// Recomputes the drag-critical positions of elements
-	computeCoords: function() {
-		this.component.prepareHits();
-		this.computeScrollBounds(); // why is this here??????
-	},
-
-
 	// Called when the actual drag has started
 	handleDragStart: function(ev) {
 		var hit;
@@ -155,7 +149,7 @@ var HitDragListener = DragListener.extend({
 		this.origHit = null;
 		this.hit = null;
 
-		this.component.releaseHits();
+		this.component.hitsNotNeeded();
 	},
 
 
@@ -163,7 +157,12 @@ var HitDragListener = DragListener.extend({
 	handleScrollEnd: function() {
 		DragListener.prototype.handleScrollEnd.apply(this, arguments); // call the super-method
 
-		this.computeCoords(); // hits' absolute positions will be in new places. recompute
+		// hits' absolute positions will be in new places after a user's scroll.
+		// HACK for recomputing.
+		if (this.isDragging) {
+			this.component.releaseHits();
+			this.component.prepareHits();
+		}
 	},