Parcourir la source

simplified resize scheme. comes down from top

Adam Shaw il y a 8 ans
Parent
commit
154249bdd5

+ 1 - 1
src/Calendar.options.js

@@ -59,7 +59,7 @@ Calendar.mixin({
 		// if only one option change, `optionName` will be its name.
 		if (optionCnt === 1) {
 			if (optionName === 'height' || optionName === 'contentHeight' || optionName === 'aspectRatio') {
-				this.updateSize(true); // true = allow recalculation of height
+				this.updateViewSize(true); // isResize=true
 				return;
 			}
 			else if (optionName === 'defaultDate') {

+ 18 - 4
src/Calendar.render.js

@@ -220,17 +220,31 @@ Calendar.mixin({
 	},
 
 
-	updateSize: function(shouldRecalc) {
+	updateViewSize: function(isResize) {
+		var view = this.view;
+		var scroll;
+
 		if (this.elementVisible()) {
 
-			if (shouldRecalc) {
+			if (isResize) {
 				this._calcSize();
+				scroll = view.queryScroll();
 			}
 
 			this.ignoreWindowResize++;
-			this.view.updateSize(true); // isResize=true. will poll getSuggestedViewHeight() and isHeightAuto()
+
+			view.updateSize(
+				this.getSuggestedViewHeight(),
+				this.isHeightAuto(),
+				isResize
+			);
+
 			this.ignoreWindowResize--;
 
+			if (isResize) {
+				view.applyScroll(scroll);
+			}
+
 			return true; // signal success
 		}
 	},
@@ -277,7 +291,7 @@ Calendar.mixin({
 			ev.target === window && // so we don't process jqui "resize" events that have bubbled up
 			this.view.isDatesRendered
 		) {
-			if (this.updateSize(true)) {
+			if (this.updateViewSize(true)) { // isResize=true
 				this.publiclyTrigger('windowResize', [ this.view ]);
 			}
 		}

+ 8 - 40
src/View.js

@@ -79,6 +79,7 @@ var View = FC.View = InteractiveDateComponent.extend({
 		});
 
 		renderQueue.on('stop', function() {
+			_this.calendar.updateViewSize();
 			_this.thawHeight();
 			_this.popScroll();
 		});
@@ -282,8 +283,7 @@ var View = FC.View = InteractiveDateComponent.extend({
 		}
 
 		this.renderDates(dateProfile);
-		this.updateSize(); // TODO: queue up somehow
-		this.startNowIndicator();
+		this.startNowIndicator(); // shouldn't render yet because updateSize will be called soon
 
 		if (!skipScroll) {
 			this.addScroll(this.computeInitialDateScroll());
@@ -445,48 +445,12 @@ var View = FC.View = InteractiveDateComponent.extend({
 
 	/* Dimensions
 	------------------------------------------------------------------------------------------------------------------*/
-	// TODO: move some of these to DateComponent
 
 
-	// Refreshes anything dependant upon sizing of the container element of the grid
-	updateSize: function(isResize) {
-		var scroll;
+	updateSize: function(totalHeight, isAuto, isResize) {
+		InteractiveDateComponent.prototype.updateSize.apply(this, arguments);
 
-		if (isResize) {
-			scroll = this.queryScroll();
-		}
-
-		this.updateHeight(isResize);
-		this.updateWidth(isResize);
 		this.updateNowIndicator();
-
-		if (isResize) {
-			this.applyScroll(scroll);
-		}
-	},
-
-
-	// Refreshes the horizontal dimensions of the calendar
-	updateWidth: function(isResize) {
-		// subclasses should implement
-	},
-
-
-	// Refreshes the vertical dimensions of the calendar
-	updateHeight: function(isResize) {
-		var calendar = this.calendar; // we poll the calendar for height information
-
-		this.setHeight(
-			calendar.getSuggestedViewHeight(),
-			calendar.isHeightAuto()
-		);
-	},
-
-
-	// Updates the vertical dimensions of the calendar to the specified height.
-	// if `isAuto` is set to true, height becomes merely a suggestion and the view should use its "natural" height.
-	setHeight: function(height, isAuto) {
-		// subclasses should implement
 	},
 
 
@@ -661,8 +625,12 @@ var View = FC.View = InteractiveDateComponent.extend({
 
 
 	applyScreenState: function() {
+
+		// bring to natural height, then freeze again
+		this.calendar.updateViewSize();
 		this.thawHeight();
 		this.freezeHeight();
+
 		this.applyQueuedScroll();
 	},
 

+ 3 - 23
src/agenda/AgendaView.js

@@ -164,22 +164,13 @@ var AgendaView = FC.AgendaView = View.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	updateSize: function(isResize) {
-		this.timeGrid.updateSize(isResize);
-
-		View.prototype.updateSize.call(this, isResize); // call the super-method
-	},
-
+	// Adjusts the vertical dimensions of the view to the specified values
+	updateSize: function(totalHeight, isAuto, isResize) {
+		View.prototype.updateSize.apply(this, arguments);
 
-	// Refreshes the horizontal dimensions of the view
-	updateWidth: function() {
 		// make all axis cells line up, and record the width so newly created axis cells will have it
 		this.axisWidth = matchCellWidths(this.el.find('.fc-axis'));
-	},
-
 
-	// Adjusts the vertical dimensions of the view to the specified values
-	setHeight: function(totalHeight, isAuto) {
 		var eventLimit;
 		var scrollerHeight;
 		var scrollbarWidths;
@@ -328,17 +319,6 @@ var AgendaView = FC.AgendaView = View.extend({
 	},
 
 
-	// rendering
-
-
-	renderEventsPayload: function(eventsPayload) {
-		View.prototype.renderEventsPayload.apply(this, arguments);
-
-		// the all-day area is flexible and might have a lot of events, so shift the height
-		this.updateHeight();
-	},
-
-
 	/* Dragging (for events and external elements)
 	------------------------------------------------------------------------------------------------------------------*/
 

+ 3 - 1
src/agenda/TimeGrid.js

@@ -392,7 +392,9 @@ var TimeGrid = FC.TimeGrid = InteractiveDateComponent.extend(StandardInteraction
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	updateSize: function(isResize) { // NOT a standard Grid method
+	updateSize: function(totalHeight, isAuto, isResize) {
+		InteractiveDateComponent.prototype.updateSize.apply(this, arguments);
+
 		this.slatCoordCache.build();
 
 		if (isResize) {

+ 3 - 18
src/basic/BasicView.js

@@ -156,7 +156,9 @@ var BasicView = FC.BasicView = View.extend({
 
 
 	// Refreshes the horizontal dimensions of the view
-	updateWidth: function() {
+	updateSize: function(totalHeight, isAuto, isResize) {
+		View.prototype.updateSize.apply(this, arguments);
+
 		if (this.colWeekNumbersVisible) {
 			// Make sure all week number cells running down the side have the same width.
 			// Record the width for cells created later.
@@ -164,11 +166,7 @@ var BasicView = FC.BasicView = View.extend({
 				this.el.find('.fc-week-number')
 			);
 		}
-	},
-
 
-	// Adjusts the vertical dimensions of the view to the specified values
-	setHeight: function(totalHeight, isAuto) {
 		var eventLimit = this.opt('eventLimit');
 		var scrollerHeight;
 		var scrollbarWidths;
@@ -250,19 +248,6 @@ var BasicView = FC.BasicView = View.extend({
 		if (scroll.top !== undefined) {
 			this.scroller.setScrollTop(scroll.top);
 		}
-	},
-
-
-	/* Events
-	------------------------------------------------------------------------------------------------------------------*/
-
-
-	// Renders the given events onto the view and populates the segments array
-	renderEventsPayload: function(eventsPayload) {
-		View.prototype.renderEventsPayload.apply(this, arguments);
-
-		// must compensate for events that overflow the row
-		this.updateHeight();
 	}
 
 });

+ 5 - 0
src/component/DateComponent.js

@@ -60,6 +60,11 @@ var DateComponent = Component.extend({
 	},
 
 
+	updateSize: function(totalHeight, isAuto, isResize) {
+		this.callChildren('updateSize', arguments);
+	},
+
+
 	// Options
 	// -----------------------------------------------------------------------------------------------------------------