瀏覽代碼

allow rendering to be specified on event source. tests

Adam Shaw 11 年之前
父節點
當前提交
4213fc7d05
共有 3 個文件被更改,包括 50 次插入4 次删除
  1. 14 3
      src/common/Grid.events.js
  2. 1 1
      src/common/View.js
  3. 35 0
      tests/automated/background-events.js

+ 14 - 3
src/common/Grid.events.js

@@ -549,7 +549,7 @@ $.extend(Grid.prototype, {
 			if (eventGroup.length) {
 				ranges.push.apply(
 					ranges,
-					eventGroup[0].rendering === 'inverse-background' ?
+					isInverseBgEvent(eventGroup[0]) ?
 						_this.eventsToInverseRanges(eventGroup) :
 						_this.eventsToNormalRanges(eventGroup)
 				);
@@ -660,8 +660,19 @@ $.extend(Grid.prototype, {
 ----------------------------------------------------------------------------------------------------------------------*/
 
 
-function isBgEvent(event) {
-	return event.rendering === 'background' || event.rendering === 'inverse-background';
+function isBgEvent(event) { // returns true if background OR inverse-background
+	var rendering = getEventRendering(event);
+	return rendering === 'background' || rendering === 'inverse-background';
+}
+
+
+function isInverseBgEvent(event) {
+	return getEventRendering(event) === 'inverse-background';
+}
+
+
+function getEventRendering(event) {
+	return firstDefined((event.source || {}).rendering, event.rendering);
 }
 
 

+ 1 - 1
src/common/View.js

@@ -216,7 +216,7 @@ View.prototype = {
 	// Iterates through event segments. Goes through all by default.
 	// If the optional `event` argument is specified, only iterates through segments linked to that event.
 	// The `this` value of the callback function will be the view.
-	segEach: function(func, event, isBg) {
+	segEach: function(func, event) {
 		var segs = this.getSegs();
 		var i;
 

+ 35 - 0
tests/automated/background-events.js

@@ -381,6 +381,41 @@ describe('background events', function() {
 			$('#cal').fullCalendar(options);
 		});
 
+		describe('when in month view', function() {
+			it('can be activated when rendering set on the source', function(done) {
+				options.defaultView = 'month';
+				options.eventSources = [ {
+					rendering: 'background',
+					events: [ {
+						start: '2014-11-04'
+					} ]
+				} ];
+				options.eventAfterAllRender = function() {
+					expect($('.fc-bgevent').length).toBe(1);
+					expect($('.fc-event').length).toBe(0);
+					done();
+				};
+				$('#cal').fullCalendar(options);
+			});
+		});
+
+		describe('when in agenda view and timed event', function() {
+			it('can be activated when rendering set on the source', function(done) {
+				options.defaultView = 'agendaWeek';
+				options.eventSources = [ {
+					rendering: 'background',
+					events: [ {
+						start: '2014-11-04T01:00:00'
+					} ]
+				} ];
+				options.eventAfterAllRender = function() {
+					expect($('.fc-bgevent').length).toBe(1);
+					expect($('.fc-event').length).toBe(0);
+					done();
+				};
+				$('#cal').fullCalendar(options);
+			});
+		});
 	});
 
 	describe('when in agendaWeek view', function() {