mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
accessed before being loaded Show we check for $.ready when jQuery is not downloaded yet in the browser. The solution is to check if document is ready with plain DOM javascript event `DOMContentLoaded`
35 lines
810 B
Plaintext
35 lines
810 B
Plaintext
:javascript
|
|
var isInIframe = function(){
|
|
try {
|
|
return window.self !== window.top;
|
|
} catch (e) {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
document.addEventListener(
|
|
'DOMContentLoaded',
|
|
function() {
|
|
var inIframe = isInIframe();
|
|
var embedded_styles_active = $('body.off-canvas').hasClass('embedded');
|
|
|
|
var set_shopfront_styles = function (state) {
|
|
$.ajax({
|
|
url: '/embedded_shopfront/' + state,
|
|
type: 'POST'
|
|
});
|
|
};
|
|
|
|
if (inIframe && !embedded_styles_active){
|
|
$('body.off-canvas').addClass('embedded');
|
|
set_shopfront_styles('enable');
|
|
}
|
|
|
|
if (!inIframe && embedded_styles_active) {
|
|
$('body.off-canvas').removeClass('embedded');
|
|
set_shopfront_styles('disable');
|
|
}
|
|
},
|
|
false
|
|
);
|