Skip to content

Commit

Permalink
updates to support renaming pbjs in universal creative (#53)
Browse files Browse the repository at this point in the history
* updates to support renaming pbjs in universal creative

* Update to remove package-lock

* Update package.json
  • Loading branch information
GLStephen authored and jaiminpanchal27 committed Feb 12, 2019
1 parent a60efe5 commit 387f46e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -17,6 +17,7 @@
"keywords": [
"Prebid.js"
],
"globalVarName": "pbjs",
"author": "Prebid.org Contributors",
"license": "Apache-2.0",
"bugs": {
Expand Down Expand Up @@ -63,10 +64,12 @@
"webdriverio": "^4.13.2",
"webpack": "^3.0.0",
"webpack-stream": "^4.0.0",
"yargs": "^11.0.0"
"yargs": "^11.0.0",
"string-replace-webpack-plugin": "^0.1.3"
},
"dependencies": {
"babel-plugin-transform-object-assign": "^6.22.0",
"dev": "^0.1.3",
"postscribe": "^2.0.8"
}
}
4 changes: 2 additions & 2 deletions src/renderingManager.js
Expand Up @@ -47,9 +47,9 @@ export function newRenderingManager(win, environment) {
let w = win;
for (let i = 0; i < 10; i++) {
w = w.parent;
if (w.pbjs) {
if (w.$$PREBID_GLOBAL$$) {
try {
w.pbjs.renderAd(doc, adId);
w.$$PREBID_GLOBAL$$.renderAd(doc, adId);
break;
} catch (e) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions test/spec/renderingManager_spec.js
Expand Up @@ -16,7 +16,7 @@ const renderingMocks = {
},
parent: {
postMessage: sinon.spy(),
pbjs: {
$$PREBID_GLOBAL$$: {
renderAd: sinon.spy()
}
},
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('renderingManager', function() {
};

renderObject.renderAd(mockWin.document, ucTagData);
expect(mockWin.parent.pbjs.renderAd.callCount).to.equal(1);
expect(mockWin.parent.$$PREBID_GLOBAL$$.renderAd.callCount).to.equal(1);
});
});
});
15 changes: 15 additions & 0 deletions webpack.conf.js
@@ -1,4 +1,5 @@
var creative = require('./package.json');
var StringReplacePlugin = require('string-replace-webpack-plugin');
var path = require('path');
var webpack = require('webpack');

Expand Down Expand Up @@ -26,6 +27,20 @@ module.exports = {
}
}
]
},
{
test: /\.js$/,
include: /(src|test|testpages)/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /\$\$PREBID_GLOBAL\$\$/g,
replacement: function (match, p1, offset, string) {
return creative.globalVarName;
}
}
]
})
}
]
}
Expand Down

0 comments on commit 387f46e

Please sign in to comment.