Przeglądaj źródła

fix bug where View's title property was unpopulated

Adam Shaw 11 lat temu
rodzic
commit
0373426ea7
3 zmienionych plików z 32 dodań i 1 usunięć
  1. 2 1
      src/Calendar.js
  2. 7 0
      src/common/View.js
  3. 23 0
      tests/automated/View.js

+ 2 - 1
src/Calendar.js

@@ -612,7 +612,8 @@ function Calendar(element, instanceOptions) {
 
 
 	function updateTitle() {
-		header.updateTitle(currentView.computeTitle());
+		currentView.updateTitle();
+		header.updateTitle(currentView.title);
 	}
 
 

+ 7 - 0
src/common/View.js

@@ -6,6 +6,7 @@ var View = fc.View = Class.extend({
 
 	type: null, // subclass' view name (string)
 	name: null, // deprecated. use `type` instead
+	title: null, // the text that will be displayed in the header's title
 
 	calendar: null, // owner Calendar object
 	options: null, // view-specific options
@@ -187,6 +188,12 @@ var View = fc.View = Class.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
+	// Sets the view's title property to the most updated computed value
+	updateTitle: function() {
+		this.title = this.computeTitle();
+	},
+
+
 	// Computes what the title at the top of the calendar should be for this view
 	computeTitle: function() {
 		return this.formatRange(

+ 23 - 0
tests/automated/View.js

@@ -0,0 +1,23 @@
+describe('View object', function() {
+
+	var options;
+
+	/*
+	TODO: move tests from eventLimitClick.js about view.name/type into here
+	*/
+
+	beforeEach(function() {
+		affix('#cal');
+		options = {
+			defaultDate: '2015-01-01'
+		};
+	});
+
+	describe('title', function() {
+		it('is a correctly defined string', function() {
+			$('#cal').fullCalendar(options);
+			var view = $('#cal').fullCalendar('getView');
+			expect(view.title).toBe('January 2015');
+		});
+	});
+});