Parcourir la source

add 'parent' option for height

Casey Holzer il y a 9 ans
Parent
commit
302d3edaa6
2 fichiers modifiés avec 16 ajouts et 14 suppressions
  1. 3 0
      src/Calendar.js
  2. 13 14
      tests/automated/height-and-contentHeight.js

+ 3 - 0
src/Calendar.js

@@ -740,6 +740,9 @@ function Calendar_constructor(element, overrides) {
 		else if (typeof t.options.height === 'function') { // exists and is a function
 			suggestedViewHeight = t.options.height() - (header.el ? header.el.outerHeight(true) : 0);
 		}
+		else if (t.options.height === 'parent') { // set to height of parent element
+			suggestedViewHeight = element.parent().height() - (header.el ? header.el.outerHeight(true) : 0);
+		}
 		else {
 			suggestedViewHeight = Math.round(content.width() / Math.max(t.options.aspectRatio, .5));
 		}

+ 13 - 14
tests/automated/height-and-contentHeight.js

@@ -1,11 +1,19 @@
 (function() {
 
-[ 'height', 'contentHeight' ].forEach(function(heightProp) { describe(heightProp, function() {
+[ 'height', 'contentHeight' ].forEach(function(heightProp) { ddescribe(heightProp, function() {
 
 	var calendarEl;
 	var options;
 	var heightElm;
 	var asAMethod;
+	var heightPropDescriptions = [
+		{ description: 'as a number', height: 600 },
+		{ description: 'as a function', height: getParentHeight, heightWrapper: true }
+	];
+
+	if (heightProp === 'height') {
+		heightPropDescriptions.push({ description: 'as "parent"', height: 'parent', heightWrapper: true });
+	}
 
 	beforeEach(function() {
 		affix('#cal');
@@ -65,10 +73,7 @@
 					options.defaultView = 'month';
 				});
 
-				[
-					{ description: 'as a number', height: 600 },
-					{ description: 'as a function', height: getParentHeight, heightWrapper: true }
-				].forEach(function(testInfo) {
+				heightPropDescriptions.forEach(function(testInfo) {
 					describe(testInfo.description, function() {
 						if (testInfo.heightWrapper) {
 							beforeEach(function() {
@@ -76,7 +81,7 @@
 							});
 						}
 
-						describe('when there are no events', function() {
+						ddescribe('when there are no events', function() {
 							it('should be the specified height, with no scrollbars', function() {
 								init(testInfo.height);
 								expect(Math.round(heightElm.outerHeight())).toBe(600);
@@ -155,10 +160,7 @@
 						options.defaultView = viewName;
 					});
 
-					[
-						{ description: 'as a number', height: 600 },
-						{ description: 'as a function', height: getParentHeight, heightWrapper: true }
-					].forEach(function(testInfo) {
+					heightPropDescriptions.forEach(function(testInfo) {
 						describe(testInfo.description, function() {
 							if (testInfo.heightWrapper) {
 								beforeEach(function() {
@@ -216,10 +218,7 @@
 								$.extend(options, moreOptions);
 							});
 
-							[
-								{ description: 'as a number', height: 600 },
-								{ description: 'as a function', height: getParentHeight, heightWrapper: true }
-							].forEach(function(testInfo) {
+							heightPropDescriptions.forEach(function(testInfo) {
 								describe(testInfo.description, function() {
 									if (testInfo.heightWrapper) {
 										beforeEach(function() {