Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing #141, prevent listener to be called more then once, fixed tests #143

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions jquery.dfp.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,45 +303,48 @@
pubadsService.setCentering(true);
}

// Setup event listener to listen for renderEnded event and fire callbacks.
pubadsService.addEventListener('slotRenderEnded', function (event) {
if(!googletag.__dfp_event__) {
// Setup event listener to listen for renderEnded event and fire callbacks.
pubadsService.addEventListener('slotRenderEnded', function (event) {

rendered++;
rendered++;

var $adUnit = $('#' + event.slot.getSlotId().getDomId());
var $adUnit = $('#' + event.slot.getSlotId().getDomId());

var display = event.isEmpty ? 'none' : 'block';
var display = event.isEmpty ? 'none' : 'block';

// if the div has been collapsed but there was existing content expand the
// div and reinsert the existing content.
var $existingContent = $adUnit.data('existingContent');
if (display === 'none' && $.trim($existingContent).length > 0 &&
dfpOptions.collapseEmptyDivs === 'original') {
$adUnit.show().html($existingContent);
display = 'block display-original';
}
// if the div has been collapsed but there was existing content expand the
// div and reinsert the existing content.
var $existingContent = $adUnit.data('existingContent');
if (display === 'none' && $.trim($existingContent).length > 0 &&
dfpOptions.collapseEmptyDivs === 'original') {
$adUnit.show().html($existingContent);
display = 'block display-original';
}

$adUnit.removeClass('display-none').addClass('display-' + display);
$adUnit.removeClass('display-none').addClass('display-' + display);

// Excute afterEachAdLoaded callback if provided
if (typeof dfpOptions.afterEachAdLoaded === 'function') {
dfpOptions.afterEachAdLoaded.call(this, $adUnit, event);
}
// Excute afterEachAdLoaded callback if provided
if (typeof dfpOptions.afterEachAdLoaded === 'function') {
dfpOptions.afterEachAdLoaded.call(this, $adUnit, event);
}

// Excute afterAllAdsLoaded callback if provided
if (typeof dfpOptions.afterAllAdsLoaded === 'function' && rendered === count) {
dfpOptions.afterAllAdsLoaded.call(this, $adCollection);
}
// Excute afterAllAdsLoaded callback if provided
if (typeof dfpOptions.afterAllAdsLoaded === 'function' && rendered === count) {
dfpOptions.afterAllAdsLoaded.call(this, $adCollection);
}

});
});
googletag.__dfp_event__ = true;
}

// this will work with AdblockPlus
if(dfpScript.shouldCheckForAdBlockers() && !googletag._adBlocked_) {
setTimeout(function () {
var slots = pubadsService.getSlots ? pubadsService.getSlots() : [];
if (slots.length > 0) {
$.get(slots[0].getContentUrl()).always(function (r) {
if (r.status !== 200) {
$.get({ url:slots[0].getContentUrl(), dataType: 'script' }).always(function (c, status) {
if (status !== 'success') {
$.each(slots, function () {
var $adUnit = $('#' + this.getSlotId().getDomId());
dfpOptions.afterAdBlocked.call(dfpScript, $adUnit, this);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.4.2",
"devDependencies": {
"grunt": "~0.4",
"grunt-contrib-jasmine": "^0.8.2",
"grunt-contrib-jasmine": "^1.1.0",
"grunt-contrib-jshint": "^0.11.1",
"grunt-contrib-uglify": "^0.8.0"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/loadingPhaseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Loading Phase', function () {
return false;
}
}, function () {
expect(window.googletag.getVersion()).toBeGreaterThan('23');
expect(window.googletag.getVersion()).toBeGreaterThan('109');
done();
}, 5000);
});
Expand Down