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

method for reinitializing the current view

Adam Shaw 9 лет назад
Родитель
Сommit
2251e699a4
1 измененных файлов с 27 добавлено и 3 удалено
  1. 27 3
      src/Calendar.js

+ 27 - 3
src/Calendar.js

@@ -590,10 +590,8 @@ function Calendar_constructor(element, overrides) {
 
 		// if viewType is changing, remove the old view's rendering
 		if (currentView && viewType && currentView.type !== viewType) {
-			header.deactivateButton(currentView.type);
 			freezeContentHeight(); // prevent a scroll jump when view element is removed
-			currentView.removeElement();
-			currentView = t.view = null;
+			clearView();
 		}
 
 		// if viewType changed, or the view was never created, create a fresh view
@@ -636,6 +634,32 @@ function Calendar_constructor(element, overrides) {
 		ignoreWindowResize--;
 	}
 
+
+	// Unrenders the current view and reflects this change in the Header.
+	// Unregsiters the `currentView`, but does not remove from viewByType hash.
+	function clearView() {
+		header.deactivateButton(currentView.type);
+		currentView.removeElement();
+		currentView = t.view = null;
+	}
+
+
+	// Destroys the view, including the view object. Then, re-instantiates it and renders it.
+	// Maintains the same scroll state.
+	// TODO: maintain any other user-manipulated state.
+	function reinitView() {
+		ignoreWindowResize++;
+		freezeContentHeight();
+
+		var viewType = currentView.type;
+		var scrollState = currentView.queryScroll();
+		clearView();
+		renderView(viewType, scrollState);
+
+		unfreezeContentHeight();
+		ignoreWindowResize--;
+	}
+
 	
 
 	// Resizing