Browse Source

safeguards against no els in CoordCache

Adam Shaw 9 years ago
parent
commit
5f8f6488fc
1 changed files with 18 additions and 5 deletions
  1. 18 5
      src/common/CoordCache.js

+ 18 - 5
src/common/CoordCache.js

@@ -35,9 +35,15 @@ var CoordCache = FC.CoordCache = Class.extend({
 	// Queries the els for coordinates and stores them.
 	// Queries the els for coordinates and stores them.
 	// Call this method before using and of the get* methods below.
 	// Call this method before using and of the get* methods below.
 	build: function() {
 	build: function() {
-		var offsetParentEl = this.forcedOffsetParentEl || this.els.eq(0).offsetParent();
+		var offsetParentEl = this.forcedOffsetParentEl;
+		if (!offsetParentEl && this.els.length > 0) {
+			offsetParentEl = this.els.eq(0).offsetParent();
+		}
+
+		this.origin = offsetParentEl ?
+			offsetParentEl.offset() :
+			null;
 
 
-		this.origin = offsetParentEl.offset();
 		this.boundingRect = this.queryBoundingRect();
 		this.boundingRect = this.queryBoundingRect();
 
 
 		if (this.isHorizontal) {
 		if (this.isHorizontal) {
@@ -220,12 +226,19 @@ var CoordCache = FC.CoordCache = Class.extend({
 
 
 	// Compute and return what the elements' bounding rectangle is, from the user's perspective.
 	// Compute and return what the elements' bounding rectangle is, from the user's perspective.
 	// Right now, only returns a rectangle if constrained by an overflow:scroll element.
 	// Right now, only returns a rectangle if constrained by an overflow:scroll element.
+	// Returns null if there are no elements
 	queryBoundingRect: function() {
 	queryBoundingRect: function() {
-		var scrollParentEl = getScrollParent(this.els.eq(0));
+		var scrollParentEl;
+
+		if (this.els.length > 0) {
+			scrollParentEl = getScrollParent(this.els.eq(0));
 
 
-		if (!scrollParentEl.is(document)) {
-			return getClientRect(scrollParentEl);
+			if (!scrollParentEl.is(document)) {
+				return getClientRect(scrollParentEl);
+			}
 		}
 		}
+
+		return null;
 	},
 	},
 
 
 	isPointInBounds: function(leftOffset, topOffset) {
 	isPointInBounds: function(leftOffset, topOffset) {