FIX: handle no ad size given for AdSense and DFP ad units
For AdSense, assume responsive size. For DFP, don't attempt to render the ad unit.
This commit is contained in:
		
							parent
							
								
									2ad24e4a60
								
							
						
					
					
						commit
						62888e734f
					
				| 
						 | 
					@ -14,14 +14,24 @@ function parseAdWidth(value) {
 | 
				
			||||||
  if (value === "responsive") {
 | 
					  if (value === "responsive") {
 | 
				
			||||||
    return "auto";
 | 
					    return "auto";
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return `${parseInt(value.substring(0, 3).trim())}px`;
 | 
					  const w = parseInt(value.substring(0, 3).trim());
 | 
				
			||||||
 | 
					  if (isNaN(w)) {
 | 
				
			||||||
 | 
					    return "auto";
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    return `${w}px`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function parseAdHeight(value) {
 | 
					function parseAdHeight(value) {
 | 
				
			||||||
  if (value === "responsive") {
 | 
					  if (value === "responsive") {
 | 
				
			||||||
    return "auto";
 | 
					    return "auto";
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return `${parseInt(value.substring(4, 7).trim())}px`;
 | 
					  const h = parseInt(value.substring(4, 7).trim());
 | 
				
			||||||
 | 
					  if (isNaN(h)) {
 | 
				
			||||||
 | 
					    return "auto";
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    return `${h}px`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function loadAdsense() {
 | 
					function loadAdsense() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,10 +126,14 @@ function getWidthAndHeight(placement, settings, isMobile) {
 | 
				
			||||||
    renderCounts[placement] += 1;
 | 
					    renderCounts[placement] += 1;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return {
 | 
					  const sizeObj = {
 | 
				
			||||||
    width: parseInt(splitWidthInt(size)),
 | 
					    width: parseInt(splitWidthInt(size)),
 | 
				
			||||||
    height: parseInt(splitHeightInt(size))
 | 
					    height: parseInt(splitHeightInt(size))
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (!isNaN(sizeObj.width) && !isNaN(sizeObj.height)) {
 | 
				
			||||||
 | 
					    return sizeObj;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function defineSlot(
 | 
					function defineSlot(
 | 
				
			||||||
| 
						 | 
					@ -290,21 +294,24 @@ export default AdComponent.extend({
 | 
				
			||||||
    "showToTrustLevel",
 | 
					    "showToTrustLevel",
 | 
				
			||||||
    "showToGroups",
 | 
					    "showToGroups",
 | 
				
			||||||
    "showAfterPost",
 | 
					    "showAfterPost",
 | 
				
			||||||
    "showOnCurrentPage"
 | 
					    "showOnCurrentPage",
 | 
				
			||||||
 | 
					    "size"
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
  showAd(
 | 
					  showAd(
 | 
				
			||||||
    publisherId,
 | 
					    publisherId,
 | 
				
			||||||
    showToTrustLevel,
 | 
					    showToTrustLevel,
 | 
				
			||||||
    showToGroups,
 | 
					    showToGroups,
 | 
				
			||||||
    showAfterPost,
 | 
					    showAfterPost,
 | 
				
			||||||
    showOnCurrentPage
 | 
					    showOnCurrentPage,
 | 
				
			||||||
 | 
					    size
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      publisherId &&
 | 
					      publisherId &&
 | 
				
			||||||
      showToTrustLevel &&
 | 
					      showToTrustLevel &&
 | 
				
			||||||
      showToGroups &&
 | 
					      showToGroups &&
 | 
				
			||||||
      showAfterPost &&
 | 
					      showAfterPost &&
 | 
				
			||||||
      showOnCurrentPage
 | 
					      showOnCurrentPage &&
 | 
				
			||||||
 | 
					      size
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue