Skip to content

Commit

Permalink
Added option to disable CSS injection entirely
Browse files Browse the repository at this point in the history
- Placement.js: Added `no_css` option to disable template css injection
- examples/dfp*.html: Added `beforeLoad` optional hook for executing or injecting custom templates before loading placements (v3.2.0)
- package.json: Bumped to 1.20.0
  • Loading branch information
kfitzgerald committed Nov 11, 2021
1 parent 52dfaec commit 420f19e
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 37 deletions.
20 changes: 15 additions & 5 deletions dist/okanjo-bundle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! okanjo-js v1.19.1 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-js v1.20.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
Expand Down Expand Up @@ -323,7 +323,7 @@ var okanjo = function (window, document) {
/**
* Okanjo version
*/
version: "1.19.1",
version: "1.20.0",

/**
* Placeholder
Expand Down Expand Up @@ -3207,6 +3207,7 @@ var okanjo = function (window, document) {
// Functional settings
key: string().strip(), // don't need to resend key on all our requests
no_init: bool().strip(), // don't automatically load the placement, do it manually (e.g. (new Placement({no_init:true})).init()
no_css: bool().strip(), // don't automatically include stylesheets
proxy_url: string().strip(),
expandable: bool().strip().default(true),
disable_inline_buy: bool().strip().default(false), // stops inline buy functionality
Expand Down Expand Up @@ -3793,8 +3794,12 @@ var okanjo = function (window, document) {
offer._index = index;
});

var model = {
css: !this.config.no_css
};

// Render and display the results
this.setMarkup(okanjo.ui.engine.render(templateName, this));
this.setMarkup(okanjo.ui.engine.render(templateName, this, model));

// Track widget impression
if (data.results.length === 0) {
Expand Down Expand Up @@ -3995,8 +4000,12 @@ var okanjo = function (window, document) {
article._index = index;
});

var model = {
css: !this.config.no_css
};

// Render and display the results
this.setMarkup(okanjo.ui.engine.render(templateName, this));
this.setMarkup(okanjo.ui.engine.render(templateName, this, model));

// Track widget impression
if (data.results.length === 0) {
Expand Down Expand Up @@ -4129,6 +4138,7 @@ var okanjo = function (window, document) {

// Pass along what the template needs to know to display the ad
var renderContext = {
css: !this.config.no_css,
size: size,
adUnitPath: adUnitPath
};
Expand Down Expand Up @@ -5082,7 +5092,7 @@ var okanjo = function (window, document) {
return okanjo;
}));

/*! okanjo-js v1.19.1 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-js v1.20.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(okanjo) {(function (window) {

var okanjo = window.okanjo;
Expand Down
12 changes: 6 additions & 6 deletions dist/okanjo-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-bundle.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/okanjo-metrics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! okanjo-metrics.js v1.19.1 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-metrics.js v1.20.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
Expand Down Expand Up @@ -319,7 +319,7 @@ var okanjo = function (window, document) {
/**
* Okanjo version
*/
version: "1.19.1",
version: "1.20.0",

/**
* Placeholder
Expand Down
4 changes: 2 additions & 2 deletions dist/okanjo-metrics.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-metrics.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/okanjo-templates.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-templates.min.js.map

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions dist/okanjo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! okanjo-js v1.19.1 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-js v1.20.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
Expand Down Expand Up @@ -323,7 +323,7 @@ var okanjo = function (window, document) {
/**
* Okanjo version
*/
version: "1.19.1",
version: "1.20.0",

/**
* Placeholder
Expand Down Expand Up @@ -3207,6 +3207,7 @@ var okanjo = function (window, document) {
// Functional settings
key: string().strip(), // don't need to resend key on all our requests
no_init: bool().strip(), // don't automatically load the placement, do it manually (e.g. (new Placement({no_init:true})).init()
no_css: bool().strip(), // don't automatically include stylesheets
proxy_url: string().strip(),
expandable: bool().strip().default(true),
disable_inline_buy: bool().strip().default(false), // stops inline buy functionality
Expand Down Expand Up @@ -3793,8 +3794,12 @@ var okanjo = function (window, document) {
offer._index = index;
});

var model = {
css: !this.config.no_css
};

// Render and display the results
this.setMarkup(okanjo.ui.engine.render(templateName, this));
this.setMarkup(okanjo.ui.engine.render(templateName, this, model));

// Track widget impression
if (data.results.length === 0) {
Expand Down Expand Up @@ -3995,8 +4000,12 @@ var okanjo = function (window, document) {
article._index = index;
});

var model = {
css: !this.config.no_css
};

// Render and display the results
this.setMarkup(okanjo.ui.engine.render(templateName, this));
this.setMarkup(okanjo.ui.engine.render(templateName, this, model));

// Track widget impression
if (data.results.length === 0) {
Expand Down Expand Up @@ -4129,6 +4138,7 @@ var okanjo = function (window, document) {

// Pass along what the template needs to know to display the ad
var renderContext = {
css: !this.config.no_css,
size: size,
adUnitPath: adUnitPath
};
Expand Down
8 changes: 4 additions & 4 deletions dist/okanjo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo.min.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion examples/dfp.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
outside of the iframe (when able to do so) to enable expandable functionality.
-->
<script>
/*! Okanjo Placement Loader v3.1.0 - https://developer.okanjo.com/okanjo-js */
/*! Okanjo Placement Loader v3.2.0 - https://developer.okanjo.com/okanjo-js */
(function (config) {

//noinspection ES6ConvertVarToLetConst
Expand Down Expand Up @@ -133,6 +133,11 @@
}).call(win, function () {
// this = top window (if self or friendly) or the current frame if sandboxed

// Before load hook
if (config.beforeLoad) {
config.beforeLoad(); // no async
}

//noinspection ES6ConvertVarToLetConst
var win = this, targets = win.okanjo.qwery('.okanjo-placement:not(.loaded)', container), i = 0;
debug('Okanjo: Loading placements, Found=%d', targets.length);
Expand All @@ -148,6 +153,9 @@
});

})({
beforeLoad: function() {
// Do something here after Okanjo-JS loaded, before placements load
},
placement: {
// key: 'PUT_YOUR_PLACEMENT_KEY_HERE',
// expandable: true,
Expand Down
9 changes: 6 additions & 3 deletions examples/dfp.min.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
outside of the iframe (when able to do so) to enable expandable functionality.
-->
<script>
/*! Okanjo Placement Loader v3.1.0 - https://developer.okanjo.com/okanjo-js */
(function(i){var e=document,n=window,a=e.getElementById("okanjo-placement-container"),o=n.top===n.self,t=false,s=i.debug&&function(){console.info.apply(console,arguments)}||function(){};s("Okanjo: Initializing...");try{if(!o){s("Okanjo: Not top frame, locating self...");var l=n.top.document.getElementsByTagName("iframe"),c=0,r,d;for(;c<l.length;c++){r=l[c];try{d=r.contentDocument||l.contentWindow.document;if(d===document){s("Okanjo: Located self on top: ",r);a.removeAttribute("id");r.parentNode.appendChild(a);r.style.display="none";e=n.top.document;n=n.top;t=true;break}}catch(j){s("Okanjo: Failed to check frame: ",j)}}}}catch(j){console.warn("[Okanjo]","Failed to locating parent frame.",j)}if(!o&&!t){console.warn("[Okanjo]","Forcing non-expandable functionality. Top=%s, Located=%s",o,t);i.placement&&(i.placement.expandable=false)}(function(n){if(this.okanjo){s("Okanjo: previously loaded");n.call(this)}else{var o=this,e=o.document,a=e.head,t=e.createElement("script"),l=false,c=0,r;t.type="text/javascript";t.async=true;t.setAttribute("crossorigin","anonymous");t.onload=function(e){if(!l){s("Okanjo: SDK loaded, Version=%s, Event=",o.okanjo&&o.okanjo.version,e);if(o.okanjo){l=true;n.call(o)}else{s("Okanjo: SDK did not load, retrying...");r=setInterval(function(){if(o.okanjo){s("Okanjo: SDK loaded, Version=%s, Event=",o.okanjo.version,e);l=true;clearInterval(r);return n.call(o)}else if(++c>10){clearInterval(r);console.error("[Okanjo] Failed to load SDK: retries exceeded. Win=",o)}},100)}}};t.onerror=function(e){console.error("[Okanjo] Failed to load SDK:",e)};t.src=i.src||"//cdn.okanjo.com/js/latest/okanjo-bundle.min.js";a.appendChild(t)}}).call(n,function(){var e=this,n=e.okanjo.qwery(".okanjo-placement:not(.loaded)",a),o=0;s("Okanjo: Loading placements, Found=%d",n.length);e.__okanjoPlacements=e.__okanjoPlacements||[];for(;o<n.length;o++){n[o].className+=" loaded";e.__okanjoPlacements.push(new e.okanjo.Placement(n[o],i.placement));s("Okanjo: Loaded placement: ",e.__okanjoPlacements[e.__okanjoPlacements.length-1])}})
})({
/*! Okanjo Placement Loader v3.2.0 - https://developer.okanjo.com/okanjo-js */
!function(o){var e=document,n=window,a=e.getElementById("okanjo-placement-container"),t=n.top===n.self,l=!1,c=o.debug&&function(){console.info.apply(console,arguments)}||function(){};c("Okanjo: Initializing...");try{if(!t){c("Okanjo: Not top frame, locating self...");for(var r,d,i=n.top.document.getElementsByTagName("iframe"),s=0;s<i.length;s++){r=i[s];try{if(d=r.contentDocument||i.contentWindow.document,d===document){c("Okanjo: Located self on top: ",r),a.removeAttribute("id"),r.parentNode.appendChild(a),r.style.display="none",e=n.top.document,n=n.top,l=!0;break}}catch(m){c("Okanjo: Failed to check frame: ",m)}}}}catch(m){console.warn("[Okanjo]","Failed to locating parent frame.",m)}t||l||(console.warn("[Okanjo]","Forcing non-expandable functionality. Top=%s, Located=%s",t,l),o.placement&&(o.placement.expandable=!1)),function(e){if(this.okanjo)c("Okanjo: previously loaded"),e.call(this);else{var n,a=this,t=a.document,l=t.head,r=t.createElement("script"),d=!1,i=0;r.type="text/javascript",r.async=!0,r.setAttribute("crossorigin","anonymous"),r.onload=function(o){d||(c("Okanjo: SDK loaded, Version=%s, Event=",a.okanjo&&a.okanjo.version,o),a.okanjo?(d=!0,e.call(a)):(c("Okanjo: SDK did not load, retrying..."),n=setInterval(function(){return a.okanjo?(c("Okanjo: SDK loaded, Version=%s, Event=",a.okanjo.version,o),d=!0,clearInterval(n),e.call(a)):void(++i>10&&(clearInterval(n),console.error("[Okanjo] Failed to load SDK: retries exceeded. Win=",a)))},100)))},r.onerror=function(o){console.error("[Okanjo] Failed to load SDK:",o)},r.src=o.src||"//cdn.okanjo.com/js/latest/okanjo-bundle.min.js",l.appendChild(r)}}.call(n,function(){o.beforeLoad&&o.beforeLoad();var e=this,n=e.okanjo.qwery(".okanjo-placement:not(.loaded)",a),t=0;for(c("Okanjo: Loading placements, Found=%d",n.length),e.__okanjoPlacements=e.__okanjoPlacements||[];t<n.length;t++)n[t].className+=" loaded",e.__okanjoPlacements.push(new e.okanjo.Placement(n[t],o.placement)),c("Okanjo: Loaded placement: ",e.__okanjoPlacements[e.__okanjoPlacements.length-1])})
}({
// beforeLoad: function() {
// // Do something here after Okanjo-JS loaded, before placements load
// },
placement: {
// key: 'PUT_YOUR_PLACEMENT_KEY_HERE',
// expandable: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "okanjo-js",
"homepage": "https://okanjo.com/",
"version": "1.19.1",
"version": "1.20.0",
"description": "Okanjo JavaScript Widget Framework",
"main": "index.js",
"repository": {
Expand Down
14 changes: 12 additions & 2 deletions src/Placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
// Functional settings
key: string().strip(), // don't need to resend key on all our requests
no_init: bool().strip(), // don't automatically load the placement, do it manually (e.g. (new Placement({no_init:true})).init()
no_css: bool().strip(), // don't automatically include stylesheets
proxy_url: string().strip(),
expandable: bool().strip().default(true),
disable_inline_buy: bool().strip().default(false), // stops inline buy functionality
Expand Down Expand Up @@ -690,8 +691,12 @@
offer._index = index;
});

const model = {
css: !this.config.no_css
};

// Render and display the results
this.setMarkup(okanjo.ui.engine.render(templateName, this));
this.setMarkup(okanjo.ui.engine.render(templateName, this, model));

// Track widget impression
if (data.results.length === 0) {
Expand Down Expand Up @@ -904,8 +909,12 @@
article._index = index;
});

const model = {
css: !this.config.no_css
};

// Render and display the results
this.setMarkup(okanjo.ui.engine.render(templateName, this));
this.setMarkup(okanjo.ui.engine.render(templateName, this, model));

// Track widget impression
if (data.results.length === 0) {
Expand Down Expand Up @@ -1046,6 +1055,7 @@

// Pass along what the template needs to know to display the ad
const renderContext = {
css: !this.config.no_css,
size,
adUnitPath
};
Expand Down

0 comments on commit 420f19e

Please sign in to comment.