cq-prolyfill.js
function getContainer(element, prop) {

	var cache;
	if (containerCache.has(element)) {
		cache = containerCache.get(element);
		if (cache[prop]) {
			return cache[prop];
		}
	}
	else {
		cache = {};
		containerCache.set(element, cache);
	}

	if (element === documentElement) {
		cache[prop] = element;
	}

	else if (prop !== 'width' && prop !== 'height') {
		// Skip transparent background colors
		if (prop === 'background-color' && !parseColor(getComputedStyle(element).getPropertyValue(prop))[3]) {
			cache[prop] = getContainer(element.parentNode, prop);
		}
		else {
			cache[prop] = element;
		}
	}

	// Skip inline elements
	else if (getComputedStyle(element).display === 'inline') {
		cache[prop] = getContainer(element.parentNode, prop);
	}

	else if (isFixedSize(element, prop)) {
		cache[prop] = element;
	}

	else {

		var parentNode = element.parentNode;

		// Skip to next positioned ancestor for absolute positioned elements
		if (getComputedStyle(element).position === 'absolute') {
			while (
				parentNode.parentNode
				&& parentNode.parentNode.nodeType === 1
				&& ['relative', 'absolute'].indexOf(getComputedStyle(parentNode).position) === -1
			) {
				parentNode = parentNode.parentNode;
			}
		}

		// Skip to next ancestor with a transform applied for fixed positioned elements
		if (getComputedStyle(element).position === 'fixed') {
			while (
				parentNode.parentNode
				&& parentNode.parentNode.nodeType === 1
				&& [undefined, 'none'].indexOf(
					getComputedStyle(parentNode).transform
					|| getComputedStyle(parentNode).MsTransform
					|| getComputedStyle(parentNode).WebkitTransform
				) !== -1
			) {
				parentNode = parentNode.parentNode;
			}
		}

		var parentContainer = getContainer(parentNode, prop);
		while (getComputedStyle(parentNode).display === 'inline') {
			parentNode = parentNode.parentNode;
		}
		if (parentNode === parentContainer && !isIntrinsicSize(element, prop)) {
			cache[prop] = element;
		}
		else {
			cache[prop] = parentContainer;
		}
	}

	return cache[prop];

}
function getContainer(element, prop) {

	var cache;
	if (containerCache.has(element)) {
		cache = containerCache.get(element);
		if (cache[prop]) {
			return cache[prop];
		}
	}
	else {
		cache = {};
		containerCache.set(element, cache);
	}

	if (element === documentElement) {
		cache[prop] = element;
	}

	else if (prop !== 'width' && prop !== 'height') {
		// Skip transparent background colors
		if (prop === 'background-color' && !parseColor(getComputedStyle(element).getPropertyValue(prop))[3]) {
			cache[prop] = getContainer(element.parentNode, prop);
		}
		else {
			cache[prop] = element;
		}
	}

	// Skip inline elements
	else if (getComputedStyle(element).display === 'inline') {
		cache[prop] = getContainer(element.parentNode, prop);
	}

	else if (isFixedSize(element, prop)) {
		cache[prop] = element;
	}

	else {

		var parentNode = element.parentNode;

		// Skip to next positioned ancestor for absolute positioned elements
		if (getComputedStyle(element).position === 'absolute') {
			while (
				parentNode.parentNode
				&& parentNode.parentNode.nodeType === 1
				&& ['relative', 'absolute'].indexOf(getComputedStyle(parentNode).position) === -1
			) {
				parentNode = parentNode.parentNode;
			}
		}

		// Skip to next ancestor with a transform applied for fixed positioned elements
		if (getComputedStyle(element).position === 'fixed') {
			while (
				parentNode.parentNode
				&& parentNode.parentNode.nodeType === 1
				&& [undefined, 'none'].indexOf(
					getComputedStyle(parentNode).transform
					|| getComputedStyle(parentNode).MsTransform
					|| getComputedStyle(parentNode).WebkitTransform
				) !== -1
			) {
				parentNode = parentNode.parentNode;
			}
		}

		var parentContainer = getContainer(parentNode, prop);
		while (getComputedStyle(parentNode).display === 'inline') {
			parentNode = parentNode.parentNode;
		}
		if (parentNode === parentContainer && !isIntrinsicSize(element, prop)) {
			cache[prop] = element;
		}
		else {
			cache[prop] = parentContainer;
		}
	}

	return cache[prop];

}
function getContainer ( element , prop ) { var cache ; if ( containerCache . has ( element ) ) { cache = containerCache . get ( element ) ; if ( cache [ prop ] ) { return cache [ prop ] ; } } else { cache = { } ; containerCache . set ( element , cache ) ; } if ( element === documentElement ) { cache [ prop ] = element ; } else if ( prop !== 'width' && prop !== 'height' ) { // Skip transparent background colors if ( prop === 'background-color' && ! parseColor ( getComputedStyle ( element ) . getPropertyValue ( prop ) ) [ 3 ] ) { cache [ prop ] = getContainer ( element . parentNode , prop ) ; } else { cache [ prop ] = element ; } } // Skip inline elements else if ( getComputedStyle ( element ) . display === 'inline' ) { cache [ prop ] = getContainer ( element . parentNode , prop ) ; } else if ( isFixedSize ( element , prop ) ) { cache [ prop ] = element ; } else { var parentNode = element . parentNode ; // Skip to next positioned ancestor for absolute positioned elements if ( getComputedStyle ( element ) . position === 'absolute' ) { while ( parentNode . parentNode && parentNode . parentNode . nodeType === 1 && [ 'relative' , 'absolute' ] . indexOf ( getComputedStyle ( parentNode ) . position ) === - 1 ) { parentNode = parentNode . parentNode ; } } // Skip to next ancestor with a transform applied for fixed positioned elements if ( getComputedStyle ( element ) . position === 'fixed' ) { while ( parentNode . parentNode && parentNode . parentNode . nodeType === 1 && [ undefined , 'none' ] . indexOf ( getComputedStyle ( parentNode ) . transform || getComputedStyle ( parentNode ) . MsTransform || getComputedStyle ( parentNode ) . WebkitTransform ) !== - 1 ) { parentNode = parentNode . parentNode ; } } var parentContainer = getContainer ( parentNode , prop ) ; while ( getComputedStyle ( parentNode ) . display === 'inline' ) { parentNode = parentNode . parentNode ; } if ( parentNode === parentContainer && ! isIntrinsicSize ( element , prop ) ) { cache [ prop ] = element ; } else { cache [ prop ] = parentContainer ; } } return cache [ prop ] ; }
Get the nearest qualified container element starting by the element itself

@param  {Element} element
@param  {string}  prop    CSS property
@return {Element}
Get the nearest qualified container element starting by the element itself