', { id: 'ad-pixelskin' })
}
/**
* Generate the add placement div with proper class and attributes
* for pixel element
* @returns {jQuery|HTMLElement|*}
*/
function adPixelPlaceholder() {
return $('
', { id: 'ad-pixel' })
}
/**
* This goes to all pages above header
*/
$('body').prepend( $('
', { id: 'ad-header' }) );
/**
* This goes to all pages next to H1 element
*/
$('h1').append( $('', { id: 'ad-times-travel-partnership-logo' }) );
/**
* On footer of all pages
*/
$('footer').prepend( adPixelskinPlaceholder() );
$('footer').prepend( adPixelPlaceholder() );
/**
* Homepage logic
*/
if ( $('body').hasClass('home') ) {
// BOTH MOBILE AND DESKTOP
// count blocks
let blocks = $('.widget_section');
// After 1st Block
if (blocks.length >= 1) {
$(blocks.eq(0)).after( adTravelPlaceholder() );
}
// After 3rd Block
if (blocks.length >= 3) {
$(blocks.eq(2)).after( adTravelNativeBlockPlacehoder() );
}
// After the 5th then every subsequent 2 blocks (if exist)
if (blocks.length >= 5) {
for (let i = 4; i < blocks.length + 1; i += 2) {
$(blocks.eq(i)).after( adTravelPlaceholder() );
}
}
}
/**
* All other index pages (destination, Cruises, Tours, Holiday types)
*/
if ( $('body').hasClass('tax-destinations') || $('body').hasClass('tax-holiday-type') ) {
// count blocks
let blocks = $('.widget_section');
// After 1st Block
if (blocks.length >= 1) {
$(blocks.eq(0)).after( adTravelPlaceholder() );
}
// After the 3rd then every subsequent 2 blocks (if exist) - travel block
if (blocks.length >= 3) {
for (let i = 2; i < blocks.length + 1; i += 2) {
$(blocks.eq(i)).after( adTravelPlaceholder() );
}
}
// After 2nd Block - native block
if (blocks.length >= 2) {
$(blocks.eq(1)).after( adTravelNativeBlockPlacehoder() );
}
}
/**
* Articles
*/
if ( $('body').hasClass('single-article') ) {
if ( $('main').hasClass('hide_ads') ) return ;
/**
* Check screen width then go with either desktop
* or mobile and tab version of ads
*/
if (window.innerWidth >= adDesktopWidth) {
placeArticleAddsDesktop();
} else {
placeArticleAddsDesktop();
}
}
/**
* Output add units for article post type for mobile and tablet
*/
function placeArticleAdds() {
// count paragraphs
let blocks = $('.article__postarea > *');
let articleImagesElements = $('.article__postarea img');
const articleParagraphElements = $('.article__postarea p:not(:has("img"))');
// After the 1st block on the page
if (blocks.length >= 2) {
$(blocks.eq(1)).after( adArticleTravelPlaceholder() );
}
// After the 1st block on the page
if (blocks.length >= 3) {
$(blocks.eq(3)).after( adArticleNativePlaceholder() );
}
}
/**
* Output add units for article post type desktop screen size only
*/
function placeArticleAddsDesktop() {
$('.article__content').prepend( adPixelskinPlaceholder() );
// count paragraphs
let blocks = $('.article__postarea > *');
let articleImagesElements = $('.article__postarea img');
const articleParagraphElements = $('.article__postarea p:not(:has("img"))');
// If the article has fewer than 6 paragraphs,
// there will be no ads.
if (articleParagraphElements.length <= 5) {
return
}
// If the article has between 6 & 8 Paragraphs,
// the ad can be places wrapped in between the content
// ads can be placed wrapped between para 5 and 6
if (articleParagraphElements.length >= 6 && articleParagraphElements.length <= 8) {
$(blocks.eq(4)).after( adArticleTravelPlaceholder() );
return
}
// If Article has image/Interactive above and below
// the 5th Paragraph, the ad should be placed below
// the 5th paragraph, between the paragraph and the
// interactive/ad below as a full length rail.
let isAdDisplayed = false;
if ( articleImagesElements.length ) {
let elementBefore = $(articleParagraphElements.eq(4)).prev();
let elementAfter = $(articleParagraphElements.eq(4)).next();
// check if both contain image
if ( elementBefore.children('img').length && elementAfter.children('img').length ) {
$(articleParagraphElements.eq(5)).after( adArticleTravelPlaceholder() );
isAdDisplayed = true;
}
}
// If the article has more than 8 paragraphs with image or
// interactive within first 10 paragraphs, the ads can be
// placed wrapped between para 5 and 6 (as shown in image)
if ( articleImagesElements.length && articleParagraphElements.length >= 8) {
let targetedParagraphIndex = $(blocks).index( articleParagraphElements.eq(8) );
let elementsBefore = blocks.slice(0, targetedParagraphIndex);
// check if there is an image within, if yes
// inject add slot after 5th
if (isAdDisplayed === false) {
if ( elementsBefore.children('img') ) {
if( $(articleParagraphElements.eq(5)).hasClass('wp-caption-text') ){
$(articleParagraphElements.eq(5).parent()).after( adArticleTravelPlaceholder() );
} else {
$(articleParagraphElements.eq(5)).after( adArticleTravelPlaceholder() );
}
} else {
// if no image inject after 3rd paragraph
$(articleParagraphElements.eq(3)).after( adArticleTravelPlaceholder() );
}
}
}
// If article has more than 8 paragraphs, without images or
// interactives in the first 10 items , the ad could be placed
// as shown after 4th paragraph floated right
if ( articleImagesElements.length && articleParagraphElements.length >= 10) {
let targetedParagraphIndex = $(blocks).index( articleParagraphElements.eq(10) );
let elementsBefore = blocks.slice(0, targetedParagraphIndex);
if ( ! elementsBefore.children('img') && isAdDisplayed === false ) {
$(articleParagraphElements.eq(4)).after( adArticleTravelPlaceholder() );
}
}
// If article has more than 12 paragraphs, and no images
// or interactive elements between paragraph 10-13
if ( articleImagesElements.length && articleParagraphElements.length > 12) {
let paragraphTen = $(blocks).index( articleParagraphElements.eq(10) );
let paragraphThirteen = $(blocks).index( articleParagraphElements.eq(13) );
let elementsForCheck = blocks.slice(paragraphTen, paragraphThirteen);
if ( ! elementsForCheck.children('img') ) {
$(articleParagraphElements.eq(10)).after( adArticleNativePlaceholder() );
}
}
}
});
;