Преглед изворни кода

more clever scroll init. works better with render q

Adam Shaw пре 8 година
родитељ
комит
3d327fbe7b
2 измењених фајлова са 11 додато и 28 уклоњено
  1. 5 15
      src/Calendar.render.js
  2. 6 13
      src/View.js

+ 5 - 15
src/Calendar.render.js

@@ -200,7 +200,7 @@ Calendar.mixin({
 	// Renders a view because of a date change, view-type change, or for the first time.
 	// If not given a viewType, keep the current view but render different dates.
 	// Accepts an optional scroll state to restore to.
-	renderView: function(viewType, forcedScroll) {
+	renderView: function(viewType) {
 		var _this = this;
 		var oldView = this.view;
 		var newView;
@@ -228,15 +228,8 @@ Calendar.mixin({
 			this.toolbarsManager.proxyCall('activateButton', viewType);
 		}
 
-		if (this.view) {
-
-			if (forcedScroll) {
-				this.view.addForcedScroll(forcedScroll);
-			}
-
-			if (this.elementVisible()) {
-				this.view.setDate(this.currentDate);
-			}
+		if (this.view && this.elementVisible()) {
+			this.view.setDate(this.currentDate);
 		}
 
 		this.stopBatchRender();
@@ -264,13 +257,10 @@ Calendar.mixin({
 	// TODO: maintain any other user-manipulated state.
 	reinitView: function() {
 		this.startBatchRender();
-
-		var viewType = this.view.type;
-		var scrollState = this.view.queryScroll();
+		this.view.addScroll({ isLocked: true });
 		this.clearView();
 		this.calcSize();
-		this.renderView(viewType, scrollState);
-
+		this.renderView();
 		this.stopBatchRender();
 	},
 

+ 6 - 13
src/View.js

@@ -221,19 +221,16 @@ var View = FC.View = InteractiveDateComponent.extend({
 
 
 	// if dateProfile not specified, uses current
-	executeDateRender: function(dateProfile, skipScroll) {
+	executeDateRender: function(dateProfile) {
 
 		if (this.render) {
 			this.render(); // TODO: deprecate
 		}
 
 		this.renderDates(dateProfile);
+		this.addScroll({ isDateInit: true });
 		this.startNowIndicator(); // shouldn't render yet because updateSize will be called soon
 
-		if (!skipScroll) {
-			this.addScroll(this.computeInitialDateScroll());
-		}
-
 		this.trigger('dateRender');
 		this.isDatesRendered = true;
 	},
@@ -395,17 +392,10 @@ var View = FC.View = InteractiveDateComponent.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	addForcedScroll: function(scroll) {
-		this.addScroll(
-			$.extend(scroll, { isForced: true })
-		);
-	},
-
-
 	addScroll: function(scroll) {
 		var queuedScroll = this.queuedScroll || (this.queuedScroll = {});
 
-		if (!queuedScroll.isForced) {
+		if (!queuedScroll.isLocked) {
 			$.extend(queuedScroll, scroll);
 		}
 	},
@@ -437,6 +427,9 @@ var View = FC.View = InteractiveDateComponent.extend({
 
 	applyScroll: function(scroll) {
 		if (this.isDatesRendered) {
+			if (scroll.isDateInit) {
+				$.extend(scroll, this.computeInitialDateScroll());
+			}
 			this.applyDateScroll(scroll);
 		}
 	},