Bläddra i källkod

get height freezing/unfreezing right

Adam Shaw 9 år sedan
förälder
incheckning
0a3c106c6f
2 ändrade filer med 49 tillägg och 25 borttagningar
  1. 27 17
      src/Calendar.js
  2. 22 8
      src/common/View.js

+ 27 - 17
src/Calendar.js

@@ -630,8 +630,10 @@ function Calendar_constructor(element, overrides) {
 	function renderView(viewType, forcedScroll) {
 		ignoreWindowResize++;
 
+		var needsClearView = currentView && viewType && currentView.type !== viewType;
+
 		// if viewType is changing, remove the old view's rendering
-		if (currentView && viewType && currentView.type !== viewType) {
+		if (needsClearView) {
 			freezeContentHeight(); // prevent a scroll jump when view element is removed
 			clearView();
 		}
@@ -664,7 +666,6 @@ function Calendar_constructor(element, overrides) {
 				if (elementVisible()) {
 
 					currentView.setDate(date, forcedScroll); // will call freezeContentHeight
-					unfreezeContentHeight(); // immediately unfreeze regardless of whether display is async
 
 					// need to do this after View::render, so dates are calculated
 					// NOTE: view updates title text proactively
@@ -673,7 +674,10 @@ function Calendar_constructor(element, overrides) {
 			}
 		}
 
-		unfreezeContentHeight(); // undo any lone freezeContentHeight calls
+		if (needsClearView) {
+			thawContentHeight();
+		}
+
 		ignoreWindowResize--;
 	}
 
@@ -700,7 +704,7 @@ function Calendar_constructor(element, overrides) {
 		calcSize();
 		renderView(viewType, scrollState);
 
-		unfreezeContentHeight();
+		thawContentHeight();
 		ignoreWindowResize--;
 	}
 
@@ -958,27 +962,33 @@ function Calendar_constructor(element, overrides) {
 
 	/* Height "Freezing"
 	-----------------------------------------------------------------------------*/
-	// TODO: move this into the view
+
 
 	t.freezeContentHeight = freezeContentHeight;
-	t.unfreezeContentHeight = unfreezeContentHeight;
+	t.thawContentHeight = thawContentHeight;
+
+	var freezeContentHeightDepth = 0;
 
 
 	function freezeContentHeight() {
-		content.css({
-			width: '100%',
-			height: content.height(),
-			overflow: 'hidden'
-		});
+		if (!(freezeContentHeightDepth++)) {
+			content.css({
+				width: '100%',
+				height: content.height(),
+				overflow: 'hidden'
+			});
+		}
 	}
 
 
-	function unfreezeContentHeight() {
-		content.css({
-			width: '',
-			height: '',
-			overflow: ''
-		});
+	function thawContentHeight() {
+		if (!(--freezeContentHeightDepth)) {
+			content.css({
+				width: '',
+				height: '',
+				overflow: ''
+			});
+		}
 	}
 
 

+ 22 - 8
src/common/View.js

@@ -347,7 +347,7 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 
 		// do this before unsetDate, which is destructive
 		this.captureScroll();
-		this.calendar.freezeContentHeight();
+		this.freezeHeight();
 
 		this.unsetDate();
 		this.isDateSet = true;
@@ -356,7 +356,7 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 			_this.setRange(_this.computeRange(date));
 			_this.displayDateVisuals();
 
-			_this.calendar.unfreezeContentHeight();
+			_this.thawHeight();
 			_this.releaseScroll(true, forcedScroll); // isInitial=true
 
 			_this.triggerDateVisualsRendered();
@@ -364,7 +364,7 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 			return _this.displayEvents();
 		}, function() {
 			// failure. TODO: implement in RunQueue
-			_this.calendar.unfreezeContentHeight();
+			_this.thawHeight();
 			_this.discardScroll();
 		});
 	},
@@ -587,7 +587,7 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 		var scrollState;
 
 		if (isResize) {
-			this.capturedScroll();
+			this.captureScroll();
 		}
 
 		this.updateHeight(isResize);
@@ -682,6 +682,20 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 	},
 
 
+	/* Height Freezing
+	------------------------------------------------------------------------------------------------------------------*/
+
+
+	freezeHeight: function() {
+		this.calendar.freezeContentHeight();
+	},
+
+
+	thawHeight: function() {
+		this.calendar.thawContentHeight();
+	},
+
+
 	/* Event Elements / Segments
 	------------------------------------------------------------------------------------------------------------------*/
 
@@ -735,13 +749,13 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 
 		// do this before unsetEvents, a destructive action
 		this.captureScroll();
-		this.calendar.freezeContentHeight();
+		this.freezeHeight();
 
 		this.unsetEvents();
 
 		return this.setEvents(events).then(function() {
 			_this.releaseScroll();
-			_this.calendar.freezeContentHeight();
+			_this.thawHeight();
 		});
 	},
 
@@ -758,11 +772,11 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 
 			return this.eventRenderQueue.push(function() {
 				_this.captureScroll();
-				_this.calendar.freezeContentHeight();
+				_this.freezeHeight();
 
 				_this.renderEvents(events);
 
-				_this.calendar.unfreezeContentHeight();
+				_this.thawHeight();
 				_this.releaseScroll();
 
 				_this.triggerEventRender();