Nous faisons Apparence numérique et nos partenaires utilisent biscuits, stockage local et d’autres technologies similaires pour personnaliser le contenu, les publicités, les fonctionnalités des médias sociaux, l’analyse du trafic et améliorer votre expérience sur ce site Web conformément à nos Conditions d’utilisation et confidentialité. En poursuivant votre navigation, vous acceptez ces conditions.
window.OD = {
// Data
postID: false, // if single, contains postID
// OnLoad manager
loaded: false,
onloadlist: [],
addOnLoad: function(callback){
if (OD.loaded) callback.apply(callback);
OD.onloadlist.push(callback);
},
LGPDVerify: function(){
if (OD.getCookie(‘LGPDOpt’) != ‘all’){
OD.e(‘lgpd_optall’).classList.add(‘show’);
}
},
LGPDConfirm: function(){
OD.setCookie(‘LGPDOpt’, ‘all’, 86400*30*12);
OD.e(‘lgpd_optall’).classList.remove(‘show’);
},
// Init
bodyLoaded: function(){
var e = OD.e(‘singleMain’), i;
if (OD.loaded === true) return;
// flag
OD.loaded = true;
// LGPD
OD.LGPDVerify();
// get the post id
if (e) OD.postID = e.getAttribute(‘data-post-id’);
// post views counter – pvc
if (OD.postID) OD.getHTML(‘/wp-admin/admin-ajax.php?action=pvc-check-post’,{post_id:OD.postID});
// Refresh
OD.setupPageRefresh();
// Post/reactions
if (OD.postID) OD.reactionsInit();
// Scroll/Lazy
OD.bodyScroll();
// Galleries
//OD.prepareGalleries();
// Run onloaded callbacks
for (i=0; i {
var galBlock = (
e.target &&
e.target.tagName &&
e.target.tagName.toLowerCase() == ‘img’ &&
e.target.closest(‘.wp-block-gallery’)
);
return !!galBlock && window.OD.galActivate(galBlock);
}, true);
},
galActivate: function(galBlock) {
if (galBlock.getAttribute(‘data-init’) != ‘yes’) {
galBlock.setAttribute(‘data-init’, ‘yes’);
galBlock.gallery = window.OD.galCreate(galBlock);
}
galBlock.gallery.ovl.classList.add(‘show’);
},
galCreate: function(gal) {
var gallery = {
ovl:document.createElement(‘div’),
cnt:document.createElement(‘div’),
stg:document.createElement(‘div’),
thb:document.createElement(‘div’),
}, index = 0;
gallery.ovl.appendChild(gallery.cnt);
gallery.cnt.appendChild(gallery.stg);
gallery.cnt.appendChild(gallery.thb);
gallery.ovl.classList.add(‘gal-overlay’);
gallery.cnt.classList.add(‘gal-container’);
gallery.stg.classList.add(‘gal-stage’);
gallery.thb.classList.add(‘gal-thumbs’);
gal.querySelectorAll(‘.blocks-gallery-item img’).forEach(img => {
var e = document.createElement(‘div’);
img.setAttribute(‘data-item’, ++index);
e.classList.add(‘gal-img’);
e.appendChild(img.cloneNode());
gallery.stg.appendChild(e);
gallery.thb.appendChild(e.cloneNode(true));
});
document.body.appendChild(gallery.ovl);
return gallery;
},
// Lazyes
bodyScrollPos: function(){
return (window.pageYOffset==0 ? 0 : window.pageYOffset/OD.bodyScrollSize());
},
bodyScrollSize: function(){
return document.body.offsetHeight-window.innerHeight;
},
bodyScroll: function(){
if (OD.postID && !OD.commentsOK){
if (OD.isInViewPort(OD.commentsHidderWidget())) OD.commentsInit();
}
if (OD.postID && !OD.mgidOK){
if (!OD.mgidWidget()) {
OD.mgidOK = true;
} else {
// In viewport, scroll > .5, 10s ?
if (OD.isInViewPort(OD.mgidWidget())) OD.mgidInit();
else if (OD.bodyScrollSize() > 1000 && OD.bodyScrollPos() >= .5) OD.mgidInit();
else if (OD.MGIDTout !== true) {OD.MGIDTout = true; window.setTimeout(function(){OD.mgidInit();}, 20000);}
}
}
if (OD.postID && !OD.taboolaOK){
if (!OD.taboolaWidget()) {
OD.taboolaOK = true;
} else {
// In viewport, scroll > .5, 10s ?
if (OD.isInViewPort(OD.taboolaWidget())) OD.taboolaInit();
else if (OD.bodyScrollSize() > 1000 && OD.bodyScrollPos() >= .5) OD.taboolaInit();
else if (OD.taboolaTout !== true) {OD.taboolaTout = true; window.setTimeout(function(){OD.taboolaInit();}, 10000);}
}
}
if (!OD.openWebOK){
if (!OD.openWebWidget()) {
OD.openWebOK = true;
} else {
// In viewport, scroll > .5, 15s ?
if (OD.isInViewPort(OD.openWebWidget())) OD.openWebInit();
else if (OD.bodyScrollSize() > 1600 && OD.bodyScrollPos() >= .5) OD.openWebInit();
else if (OD.openWebTout !== true) {OD.openWebTout = true; window.setTimeout(function(){OD.openWebInit();}, 15000);}
}
}
},
// Lazy:Comments
commentsHidderWidget: function(){
if (!OD._commentsHidderWidget) OD._commentsHidderWidget = OD.e(‘cmtHiddder’);
return OD._commentsHidderWidget;
},
commentsWidget: function(){
if (!OD._commentsWidget) OD._commentsWidget = OD.e(‘postComments’);
return OD._commentsWidget;
},
commentsInit: function(){
var script, head = document.head;
OD.commentsOK = true;
script = document.createElement(“script”);
script.setAttribute(“src”, “https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6”);
script.setAttribute(“async”, “false”);
script.setAttribute(“onload”, “FB.XFBML.parse();”);
head.insertBefore(script, head.firstElementChild);
},
// Lazy:Taboola
taboolaWidget: function(){
// Desabilitado por conta da MGID
return false;
if (!OD._taboolaWidget) OD._taboolaWidget = OD.e(‘widgetTaboola’);
return OD._taboolaWidget;
},
taboolaInit: function(){
var script, head = document.head;
if (OD.taboolaOK === true) return;
OD.taboolaOK = true;
// 3rd tag
window._taboola = window._taboola || [];
_taboola.push({article:’auto’});
!function (e, f, u, i) {
if (!document.getElementById(i)){e.async = 1; e.src = u;e.id = i;f.parentNode.insertBefore(e, f);}
}(document.createElement(‘script’), document.getElementsByTagName(‘script’)[0], ‘//cdn.taboola.com/libtrc/olhardigital/loader.js’, ‘tb_loader_script’);
if(window.performance && typeof window.performance.mark == ‘function’) {window.performance.mark(‘tbl_ic’);}
},
// Lazy:openWeb
openWebWidget: function(){
if (!OD._openWebWidget) OD._openWebWidget = OD.e(‘widgetOpenWeb’);
return OD._openWebWidget;
},
openWebInit: function(){
if (OD.openWebOK === true) return;
OD.openWebOK = true;
// 3rd tag
!function (e, f, u, i) {
if (!document.getElementById(i)){e.async = 1; e.src = u; e.setAttribute(‘data-spotim-module’, ‘spotim-launcher’); e.id = i;f.parentNode.insertBefore(e, f);}
}(document.createElement(‘script’), document.getElementsByTagName(‘script’)[0], ‘//launcher.spot.im/spot/sp_ScWcqqRz’, ‘scriptOpenWeb’);
if(window.performance && typeof window.performance.mark == ‘function’) {window.performance.mark(‘oweb_prfmrk’);}
},
// Lazy:MGID
mgidWidget: function(){
if (!OD._mgidWidget) OD._mgidWidget = OD.e(‘M806238ScriptRootC1311647’);
return OD._mgidWidget;
},
mgidInit: function(){
var script, head = document.head;
if (OD.mgidOK === true) return;
OD.mgidOK = true;
// MGOD Composit Start
(function (e, f, u, i) {
if (!document.getElementById(i)){e.async = 1; e.src = u; f.appendChild(e);}
})(document.createElement(‘script’), document.getElementsByTagName(‘body’)[0], ‘//jsc.mgid.com/o/l/olhardigital.com.br.1311647.js’);
},
// Ajax
getJSON: function(url, data, success, error, complete){
success = success||function(){};
OD.getHTML(url, data, function(responseText){
success(JSON.parse(xhr.responseText));
}, error, complete);
},
getHTML:function(url, data, success, error, complete) {
var xhr = new XMLHttpRequest(),
serialize = function(obj){
var p, str=[];
for (p in obj) {
if (!obj.hasOwnProperty(p)) continue;
str.push(encodeURIComponent(p) + “=” + encodeURIComponent(obj[p]));
}
return str.join(“&”);
};
xhr.withCredentials = true;
success = success || function() {};
complete = complete || function() {};
error = error || function() {}
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
if (xhr.status == 200) success(xhr.responseText);
else error(xhr.status, xhr.responseText);
complete();
}
xhr.open(‘GET’, url+’&’+serialize(data),true);
xhr.send();
},
// Util
e: function(id){
return document.getElementById(id);
},
isInViewPort: function(element){
var rect, top, bottom;
if (!element) return false;
rect=element.getBoundingClientRect();
top=rect.top;
bottom=rect.bottom;
return (top>=0 && bottom<=window.innerHeight);
},
toggleClass: function(id, className){
var e = OD.e(id);
if (e.classList.contains(className)) {e.classList.remove(className); return false;}
else {e.classList.add(className); return true;}
},
toggleSearch: function(){
if (OD.toggleClass('mainSearch', 'show')) OD.e('mainSearchInput').focus();
},
getUrlParameter: function(name) {
var url = window.location.href.split('?'), vars, upar, i;
url.shift();
vars = unescape(url.join('?')).split('&');
for (i = 0; i < vars.length; i++) {
upar = vars[i].split('=');
if (upar[0] === name) {
if (upar[1] === undefined) return '';
return upar[1].replace(/+/g, ' ');
}
}
return '';
},
// Resfresh
setupPageRefresh: function(){
var seconds = parseInt(OD.e('body').getAttribute('data-refresh'), 10);
if (seconds<=0) return;
window.setTimeout(function(){location.reload();}, Math.max(30,seconds)*1000);
},
// Behaviors
linkTargetPopup: function(e){
var path=e.path||e.composedPath(), link=false, i, w=600, h=600,l,t,coords="";
if (!path) return;
for (i=0; i0 && l>0) coords=”,top=”+t+’,’+’left=”+l+”,screenY=’+t+’,screenX=’+l;
window.open(link.getAttribute(‘href’),’popup’,a=”width=”+w+’,height=”+h+coords+”,resizable=yes,scrollbars=yes,status=yes,menubar=no’);
return false;
}
},
// Cookies
setCookie: function(name, value, expires) {
var d = new Date(), expires;
d.setTime(d.getTime() + (expires*1000));
expires = (expires>0 ? “;expires=”+ d.toUTCString() : ”);
document.cookie = name+”=”+value+expires+”;path=/”;
},
getCookie: function(name) {
var cname = name+”=”, i, c
decodedCookie = decodeURIComponent(document.cookie),
ca = decodedCookie.split(‘;’);
for (i=0; i<ca.length; i++) {
c = ca[i];
while (c.charAt(0)==' ') {c = c.substring(1);}
if (c.indexOf(cname) == 0) return c.substring(cname.length, c.length);
}
return false;
},
hasCookie: function(name){
return OD.getCookie(name)!==false;
},
// Reactions
reactionsWidget: function(){
if (!OD._reactionsWidget) OD._reactionsWidget = OD.e('postReaction');
return OD._reactionsWidget;
},
reactionsInit: function(){
var type = localStorage.getItem('react_'+OD.postID), wdg, counter, btns, btn, b;
if (!(wdg = OD.reactionsWidget())) return;
if (!type) {
btns = wdg.querySelectorAll('button[data-reaction]');
for (b=0; b<btns.length; b++) {
btns[b].addEventListener('click', OD.reactionSelect);
}
return;
}
if (!(btn = wdg.querySelector('button[data-reaction="'+type+'"]'))) return;
counter = btn.querySelector('[data-reaction-counter]');
wdg.setAttribute('data-reacted','yes');
btn.classList.add('selected');
counter.setAttribute('data-reaction-counter', parseInt(counter.getAttribute('data-reaction-counter'),10)+1);
},
reactionSelect: function(){
var btn = this, type = btn.getAttribute('data-reaction'), counter = btn.querySelector('[data-reaction-counter]'), wdg;
if (!type) return;
if (!(wdg = OD.reactionsWidget())) return;
if (wdg.getAttribute('data-reacted')=='yes') return;
localStorage.setItem('react_'+OD.postID, type);
wdg.setAttribute('data-reacted','yes');
btn.classList.add('selected');
counter.setAttribute('data-reaction-counter', parseInt(counter.getAttribute('data-reaction-counter'),10)+1);
OD.getJSON('/wp-admin/admin-ajax.php?action=post_reaction', {post_id:OD.postID,reaction:type});
},
// Navegação reviews
reviewTo: function(target) {
var e = document.querySelector('[data-rvw-bloco="'+target+'"]');
if (e) e.scrollIntoView({behavior: 'smooth', block: 'center'});
},
// play by click
playSingleVideo(target){
var id = target.getAttribute('id');
if (target.getAttribute('data-loaded') == 'yes') return;
target.setAttribute('data-loaded', 'yes');
playerDef = document.getElementById(id+'Object');
if (!playerDef){
target.innerHTML = '
‘;
} else if (playerDef.getAttribute(‘data-type’) == ‘iframe’){
target.innerHTML = ”;
} else {
target.innerHTML = ‘“‘;
}
}
};
if (window.OD_bodyAlreadyLoaded===true) OD.bodyLoaded();
document.addEventListener(‘click’, OD.linkTargetPopup, true);
////////////////////////////////////////////////
// OpenWeb
////////////////////////////////////////////////
window.OD.addOnLoad(function(){
// Apenas matérias
if (!OD.postID) return;
// Callbacks
window.openWeb_onNewUnseen = function(count) {
var e = document.getElementById(‘openWebBellBadge’);
if (e){e.innerText = count; e.setAttribute(‘data-unseen’, (count>0 ? ‘yes’ : ‘no’));}
}
window.openWeb_openNotifications = function(){
var payload = {postId: OD.postID, instanceId: “EmbeddedNotifications”};
if (typeof window.__OW_OPEN_NOTIFICATIONS__ === ‘function’) {
window.__OW_OPEN_NOTIFICATIONS__(payload);
window.openWeb_onNewUnseen(0);
return;
}
document.addEventListener(‘ow-notifications-sdk-ready’, function() {
window.__OW_OPEN_NOTIFICATIONS__(payload);
window.openWeb_onNewUnseen(0);
});
// clicked but not loaded, load now if available
window.OD.openWebInit();
};
// Init
if (typeof window.__OW_SUBSCRIBE_TO_NOTIFICATIONS__ === ‘function’) {
window.__OW_SUBSCRIBE_TO_NOTIFICATIONS__(OD.postID, window.openWeb_onNewUnseen);
return;
}
document.addEventListener(‘ow-notifications-sdk-ready’, function(){
window.__OW_SUBSCRIBE_TO_NOTIFICATIONS__(OD.postID, window.openWeb_onNewUnseen);
});
});