";
modules.push(elementId);
placementDiff = applyInsert($(this), moduleDivString);
if (debug) {
console.log("Just placed a module and the placementDiff is: " + placementDiff);
}
placementTarget = cumulativeHeight + placementDiff + interModuleHeight + moduleHeightBuffer;
moduleCounter++;
}
loopCounter++;
}
// Avoid placing elements too soon due to non-large figures inflating the cumulative height
if ($(this).is("figure") && !$(this).is("figure.large")) {
cumulativeHeight += grafHeight;
}
else {
cumulativeHeight += $(this).height() + grafHeight;
}
}
});
// clone Related Stories module to come in after eighth para in article body for mobile breakpoint display
var $relatedStories = $('.related-promo-wrapper');
if ($relatedStories.length) {
var $relatedStoriesClone = $relatedStories.clone();
$relatedStoriesClone.insertAfter( "#drr-container > p:eq(7)");
}
// For mobile only, place ad after second paragraph.
if (firstMobileAdHtml) {
$(firstMobileAdHtml).insertAfter("#drr-container > p:eq(1)");
}
var $insiderPromo = $('.insider-promo-wrapper');
if ($insiderPromo.length) {
var $insiderPromoClone = $insiderPromo.clone();
$insiderPromoClone.insertAfter( "#drr-container > p:eq(1)");
}
//place left side element
cumulativeHeight = 0;
var leftPlacementTarget = tagHeight < 100 ? 100 : tagHeight;
var leftPlacementLookaheadStart = null;
var leftIntervalHeight = 650;
var leftPlacementIndex = null;
var $leftPlacementElement;
// Only place left module if not a sponsored article and not on greenbot
if (!false && true) {
$("#drr-container").children().each(function(index,value) {
if (debug) {
console.log("leftRailProcessor iterate. index "+ index);
console.log($(this));
}
//ignore any hidden elements in the body, like the mobile-only "read this next" module
if($(this).is(':visible')) {
if (cumulativeHeight >= leftPlacementTarget) {
if (debug) {
console.log("congratulations... we've passed the initial start point");
}
if (leftPlacementIndex == null) {
//it's not good enough to not be a left avoid - it also shouldn't be a
with an immediately preceding small or medium image left avoid.
if (!isLeftAvoid($(this)) && noPrevFigures($(this)) ) {
leftPlacementIndex = $(this).index();
$leftPlacementElement = $(this);
leftPlacementLookaheadStart = cumulativeHeight;
if (debug) {
console.log("is not a left avoid and no prev figures. ########## set placementIndex ("+leftPlacementIndex+") and lookaheadStart ("+leftPlacementLookaheadStart+") ##########");
}
} else {
if (debug) {
console.log("is a left avoid or has previous figures. continue");
}
}
} else {
if (debug) {
console.log("#### leftPlacementIndex already set to "+leftPlacementIndex+". looking ahead...");
}
//not null; has been set
if ((cumulativeHeight - leftPlacementLookaheadStart) > leftIntervalHeight) {
if (debug) {
console.log("###### THRESHOLD REACHED. LOOKAHEAD COMPLETE. END ###### (cumulativeHeight - leftPlacementLookaheadStart) ("+(cumulativeHeight-leftPlacementLookaheadStart)+") > leftIntervalHeight ("+leftIntervalHeight+").");
}
return false;
} else {
if (debug) {
console.log("threshold not reached: (cumulativeHeight - leftPlacementLookaheadStart) ("+(cumulativeHeight-leftPlacementLookaheadStart)+") < leftIntervalHeight ("+leftIntervalHeight+")");
}
if (isLeftAvoid($(this))) {
if (debug) {
console.log("This element is left avoid. #RESET, CONTINUE#");
}
leftPlacementIndex = null;
leftPlacementLookaheadStart = null;
}
}
}
}
//we shouldn't be counting small or medium figures towards height since their heights are reflected in the following
tags
if (!(isLeftAvoid($(this)) && ($(this).hasClass('small') || $(this).hasClass('inline-small') || $(this).hasClass('medium') || $(this).hasClass('inline-medium') || $(this).hasClass('apart') ))) {
cumulativeHeight += $(this).height() + grafHeight;
}
if (debug) {
console.log("-------------------- set cumulativeHeight("+cumulativeHeight+") ---------------");
console.log("");
}
}
});
}
if (leftPlacementIndex != null && elementNotNearEnd($leftPlacementElement, leftPixelWindow)) {
if (debug) {
console.log(" insert into index "+leftPlacementIndex);
}
$("#drr-container").children().eq(leftPlacementIndex).before("
");
}
IDG.GPT.trackOmniture();
// Add Right rail module content
for (var i=0; i" + adString + "
";
}
function getEpoParams() {
var parts = document.referrer.replace(/^https?:///, '').split('/');
var defaultCatId = 1111;
var defaultTypeId = 2;
var epoParams = "module.epo";
parts.shift();
// From HOMEPAGE; show default typeId articles
if (parts.join('/') == "" && document.referrer.indexOf(document.domain)) {
epoParams += "&typeId=" + defaultTypeId + "&referrer=home";
}
// From ARTICLE: Show articles w referrer catId
else if (document.referrer != undefined && document.referrer.indexOf('article') >= 0) {
var a = document.createElement('a');
a.href = document.referrer;
var uriParts = a.pathname.split('/');
a = '';
if (typeof uriParts[3] == 'undefined') {
epoParams += "&typeId=" + defaultTypeId + "&referrer=home"; // default is 'home' behavior
}
else {
var refCatSlug = uriParts[3];
epoParams += "&catSlug=" + refCatSlug + "&referrer=article";
}
}
// From SEARCH: Show article with catId same as current article
else if (document.referrer.indexOf("google") >= 0 || document.referrer.indexOf("yahoo") >= 0 || document.referrer.indexOf("bing") >= 0) {
var categories = [3404, 3547];
if (categories instanceof Array && categories.length > 0) {
var primaryCatId = categories[0];
epoParams += "&catId=" + primaryCatId + "&referrer=search";
}
else {
epoParams += "&typeId=" + defaultTypeId + "&referrer=home"; // default is 'home' behavior
}
}
// Default is to show like coming from homepage
else {
epoParams += "&typeId=" + defaultTypeId + "&referrer=home";
// default is 'home' behavior
}
return epoParams;
}
/**
* @param jqo Original jquery object target
* @param divString The div to be inserted.
* @return Difference in height between original placement target and final target.
* Checks first 6 elements for an allowable placement (600 pixel window).
* If none, check nearby for elements that are not right avoids.
* If none, place element before current target.
*/
function applyInsert(jqo, divString) {
if (debug) {
console.log("applyInsert at top and jqo index is: " + jqo.index());
}
for (var i=0; i<=6; i++) {
$thisElement = jqo.nextAll().andSelf().slice(i, i+1);
if (debug) {
console.log("Checking first six and i is: " + i + " and this element index is " + $thisElement.index() );
}
if ($thisElement.index() < 0) {
break;
}
if (allowPlacement($thisElement)) {
return addElement(jqo, $thisElement, divString);
}
}
// If got here, no good place to put it.. just put it before one that is not right avoid!
var $allowElement = null;
if (($allowElement = findNearbyAllow(jqo)) != null) {
return addElement(jqo, $allowElement, divString);
}
else {
// nothing good so put in first spot that is not rightReject and not followed by reject.
if (debug) {
console.log("No nearby allows so just place in first spot that is not rightReject.");
}
var numElements = jqo.nextAll().length;
var startIndex = jqo.index();
for (var i=startIndex; i<=numElements; i++) {
var $element = $("#drr-container").children().eq(i);
// This element is eligible when not null, not in placement index, and not a rightReject nor is next element
if ($element != null && (placementIndex == null || placementIndex.indexOf(i) == -1)) {
if (!isRightReject($element) && !isRightReject($element.next())) {
return addElement(jqo, $element, divString);
}
}
}
if (debug) {
console.log("Not going to place element: return 0.");
}
return 0;
}
}
/**
* @param jqo Original jquery object
* @param allowElement Element that is good placement for module/ad
* @param divString The div to be inserted before the good element
* @return placementHeightDiff Diff in height between original placement target and current target.
*
* If element is not too close to the end the insert the div before allowable element.
* Add element index to placementIndex to keep track of which elements already have placements
*/
function addElement(jqo, allowElement, divString) {
var offset = allowElement.index() - jqo.index();
if (debug) {
console.log("addElement: jqo index is " + jqo.index() + " allowElement index is " + allowElement.index());
}
if (elementNotNearEnd(allowElement, rightPixelWindow)) {
allowElement.before(divString);
if (debug) {
console.log("addElement: Adding " + allowElement.index() + " to placementIndex.");
}
placementIndex.push(allowElement.index());
if (offset == 0) {
return 0;
}
else {
return getHeightDifference(jqo,allowElement);
}
}
else {
if (debug) {
console.log("addElement: Near the end so do NOT add.");
}
return 0;
}
}
function getHeightDifference(jqo,allowElement) {
var offset = allowElement.index() - jqo.index();
var height = 0;
var children = null;
if (offset > 0) {
children = $("#drr-container").children().slice(jqo.index(), allowElement.index() );
}
else {
children = $("#drr-container").children().slice(allowElement.index(), jqo.index());
}
if (children != null) {
children.each(function(i) {
if (debug) {
console.log("About to add this element's height to heigh diff offset");
console.log($(this));
}
height += $(this).height() + grafHeight;
});
}
if (offset < 0) {
height *= -1;
}
if (debug) {
console.log("getHeightDifference: offset was " + offset + " and height diff is : " + height);
}
return height;
}
/**
* Return true if next 550 pixels do not include a right avoid; false otherwise.
*/
function allowPlacement(jqo) {
$testElement = jqo;
var height = 0;
while (height < 550) {
if ($testElement != null && !isRightAvoid($testElement)) {
if (debug) {
console.log("allowPlacement: this element height is " + $testElement.height() + " and index is: " + $testElement.index());
}
height += $testElement.height() + grafHeight;
}
else {
return false;
}
$testElement = $testElement.next();
}
return true;
}
/**
* Look ahead and back for element that is not rightAvoid
* Return the index of the closest allowable element or null if none found.
*/
function findNearbyAllow(jqo) {
if (debug) {
console.log("In nearby allow so could not find 600 px window.");
}