(function( w ){ var loadJS = function( src, cb, ordered ){ "use strict"; var tmp; var ref = w.document.getElementsByTagName( "script" )[ 0 ]; var script = w.document.createElement( "script" ); if (typeof(cb) === 'boolean') { tmp = ordered; ordered = cb; cb = tmp; } script.src = src; script.async = !ordered; ref.parentNode.insertBefore( script, ref ); if (cb && typeof(cb) === "function") { script.onload = cb; } return script; }; // commonjs if( typeof module !== "undefined" ){ module.exports = loadJS; } else { w.loadJS = loadJS; } }( typeof global !== "undefined" ? global : this )); /* Bootstrap */ loadJS("https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"); /* Menu toggling */ var menuButton = document.getElementById("menuButton"); if(menuButton){ menuButton.addEventListener("click",function(e){ try{ let collapse = document.getElementById('main-nav'); if(!collapse.classList.contains("show")){ collapse.classList.add('show'); console.log("Menu opened!"); var elemDiv = document.createElement('div'); elemDiv.id = "bgMobileFloating"; elemDiv.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;opacity:0.5;z-index:100;background:#000;'; document.body.appendChild(elemDiv); }else{ console.log("Menu closed!"); collapse.classList.remove("show"); document.getElementById("bgMobileFloating").remove(); } }catch(error){ console.log("%cError on mobile menu: "+error, "color:red; font-weight:bold;"); } }); }else{ console.log("%cError on mobile menu: Button does not exists!", "color:red; font-weight:bold;"); } /* Social sharing */ try{ var share_button = document.getElementById("share"); if(share_button){ if(navigator.share){ share_button.addEventListener("click",function(e){ navigator.share({ title: document.title, text: document.title, url: window.location.href, }) .catch((error) => console.log("%cError on social sharing: "+error, "color:red; font-weight:bold;")); }, false); }else{ share_button.remove(); console.log("%cError on social sharing: Browser not supported", "color:red; font-weight:bold;"); } } }catch(error){ console.log("%cError on social sharing: "+error, "color:red; font-weight:bold;"); } window.onload = function(){ document.body.className = document.body.className.replace("no-js", ""); console.log("%c Animations enabled by theme options.", "color:green; font-weight:bold;"); /* * * Link optimization * */ try{ var anchors = document.querySelectorAll('span[data-link-optimizer], div[data-link-optimizer], button[data-link-optimizer]'); if(anchors && anchors.length>0){ for(var i = 0; i < anchors.length; i++){ var anchor = anchors[i]; anchor.addEventListener("click", function(event){ if(typeof event.target !== 'undefined' && event.target !== undefined){ if(event.target.localName == "a"){ return true; } var anchor = (event.target || event.srcElement); var url = this.getAttribute("data-link-optimizer"); if(url != null && typeof url !== 'undefined' && url !== undefined){ var target = anchor.getAttribute('data-link-target'); if(typeof target !== 'undefined' && target !== false && target == "_blank"){ window.open(atob(url), '_blank'); }else{ window.location.href=atob(url); } }else{ console.log("%cData link is not valid: "+error, "color:red; font-weight:bold;"); } } }, false); } } }catch(error){ console.log("%cError on 'links' module: "+error, "color:red; font-weight:bold;"); } } /*/ /* Going to top. /*/ try{ /* Go to top */ document.getElementById("go-to-top").addEventListener("click", function(e){ window.scrollTo(0,0); },false); /* Show & Hide go-to-top on scroll */ window.onscroll = function(){ let pageOffset = (document.documentElement.scrollTop || document.body.scrollTop); if(pageOffset >= 100){ document.getElementById("go-to-top").style.display="block"; }else{ document.getElementById("go-to-top").style.display="none"; } }; }catch(error){ console.log("%cError on 'go to top' module: "+error, "color:red; font-weight:bold;"); } /* Index table */ try{ function toggleIndexTable(){ var index = document.getElementById("index-table"); if(index.classList.contains("hidden")){ index.classList.remove("hidden"); index.classList.add("active"); document.getElementById("toggleIndex").innerHTML = ''; }else{ index.classList.add("hidden"); index.classList.remove("active"); document.getElementById("toggleIndex").innerHTML = ''; } } }catch(error){ console.log("%cError on 'index tables' module: "+error, "color:red; font-weight:bold;"); } /* Scroll menu */ try{ }catch(error){ console.log("%cError on 'sticky header' module: "+error, "color:red; font-weight:bold;"); } /* Disable right click */ try{ }catch(error){ console.log("%cError on 'disable right click' module: "+error, "color:red; font-weight:bold;"); } /* Google Analytics */ try{ }catch(error){ console.log("%cError on 'google analytics' module: "+error, "color:red; font-weight:bold;"); } /* Adsense */ try{ function gads(){const e=document.createElement("script");e.async=!0,e.setAttribute("crossorigin","anonymous"),e.src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7912518993246104";let t=0;document.addEventListener("mousemove",function(){1==++t&&document.getElementsByTagName("HEAD").item(0).appendChild(e)}),window.onscroll=function(n){1==++t&&document.getElementsByTagName("HEAD").item(0).appendChild(e)},setTimeout(function(){0===t&&(t++,document.getElementsByTagName("HEAD").item(0).appendChild(e))},5e3)} }catch(error){ console.log("%cError on 'adsense' module: "+error, "color:red; font-weight:bold;"); } /* Add custom code */ try{ /* Pure Javascript only */ console.clear(); /* Botón de compartir */ if(!navigator.share){ try{ document.getElementById("compartir").remove(); console.log("Eliminados botones de compartir. Este dispositivo no es compatible."); }catch(error){ console.error("Error al eliminar botón de compartir: "+error); } } function openInNewTab(url){ console.log("Abierta nueva pestaña."); window.open(url, '_blank').focus(); } function evento_carrera_a_universidad(){ if (typeof ga === 'function'){ console.log("Evento enviado (carrera hacia universidad)."); ga('send', {hitType: 'event', eventCategory: 'Clic en botón de Universidad dentro de grado', eventAction: 'Clic', eventLabel: window.location.href}); } } /* Compartir página */ function share(){ if(navigator.share){ if (typeof ga === 'function'){ console.log("Evento enviado (share)."); ga('send', {hitType: 'event', eventCategory: 'Compartir página', eventAction: 'Clic', eventLabel: window.location.href}); } navigator.share({ title: window.title, text: 'Comprova les notes de tall per a la teva universitat en aquesta pàgina.', url: window.location.href }) .then(() => console.log('Página compartida correctamente')) .catch((error) => console.log('Error al compartir página', error)); }else{ alert("No se puede compartir esta página desde tu dispositivo"); } } }catch(error){ console.log("%cError on 'custom code' module: "+error, "color:red; font-weight:bold;"); } /* Resize window, menu options */ function checkDropdownTypes(){ var dropdownType = (window.innerWidth<700 ? 'dropdown' : 'collapse'); var links = document.querySelectorAll("#main-nav a.dropdown-toggle.nav-link[data-bs-toggle]"); if(links.length>0){ for(var i=0; i