Skip to content

Commit

Permalink
(feat): implements taboola
Browse files Browse the repository at this point in the history
  • Loading branch information
markharding committed Jan 11, 2017
1 parent 809f5a5 commit e51113f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
71 changes: 71 additions & 0 deletions app/src/components/ads/taboola.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Component, EventEmitter, ElementRef } from '@angular/core';

@Component({
selector: 'taboola',
template: `
<!-- ads will load into here -->
<div [id]="id"></div>
`,
host: {
'class': 'm-ad-block m-ad-block-taboola'
}
})

export class Taboola{

visible : boolean = false;
_element : any;
id : string = 'taboola-below-article-thumbnails';

constructor(element : ElementRef) {
this._element = element.nativeElement;
this.id = 'taboola-below-article-thumbnails-' + Date.now();
TaboolaService.load(this._element, this.id).then(() => {
this.visible = true;
});
}

ngOnDestroy(){
TaboolaService.unload(this._element);
}

}

class TaboolaService{

static loaded : boolean;

static load(element : any, id : string){
return new Promise((resolve) => {
if(!TaboolaService.loaded){
(<any>window)._taboola = (<any>window)._taboola || [];
(<any>window)._taboola.push({article:'auto'});
!function (e, f, u, i) {
if (!document.getElementById(i)){
e.async = true;
e.src = u;
e.id = i;
f.parentNode.insertBefore(e, f);
}
}(document.createElement('script'),
document.getElementsByTagName('script')[0],
'//cdn.taboola.com/libtrc/minds/loader.js',
'tb_loader_script');
TaboolaService.loaded = true;
}
(<any>window)._taboola = (<any>window)._taboola || [];
(<any>window)._taboola.push({
mode: 'thumbnails-d',
container: id,
placement: 'Below Article Thumbnails',
target_type: 'mix'
});
(<any>window)._taboola.push({flush: true});
resolve(true);
});
}

static unload(element : any){
//element.innerHTML = '';
}
}
2 changes: 2 additions & 0 deletions app/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {InviteModal} from './components/modal/invite/invite';
import {AnalyticsImpressions} from './components/analytics/impressions';
import {GoogleAds} from './components/ads/google-ads';
import {RevContent} from './components/ads/revcontent';
import {Taboola} from './components/ads/taboola';
import {TagsInput} from './components/forms/tags-input/tags';
import {MindsEmoji} from './components/emoji/emoji';
import {MindsTooltip} from './components/tooltip/tooltip';
Expand Down Expand Up @@ -141,6 +142,7 @@ export const MINDS_DECLARATIONS: any[] = [
AnalyticsImpressions,
GoogleAds,
RevContent,
Taboola,
TagsInput,
SignupOnActionModal,
MindsEmoji,
Expand Down

0 comments on commit e51113f

Please sign in to comment.