// //JavaScript file for LibCal //-------------------------------------------- // var duLibScript = (function(w, d) { "use strict"; //List of all functions: //1) Function to add My Davenport to breadcrumbs function addBreadcrumbs() { const breadCrumbList = document.querySelector(".breadcrumb"); const firstBreadCrumb = breadCrumbList.firstChild; const duHomeBreadCrumb = document.createElement("li"); duHomeBreadCrumb.innerHTML = 'My Davenport'; //to add the first breadcrumb breadCrumbList.insertBefore(duHomeBreadCrumb, firstBreadCrumb); } //end addBreadCrumbs() //2) Functions to make YouTube Embed lighter //Light YouTube Embeds by @labnol //Web: http://labnol.org/?p=27941 function youTubeEmbed() { var div, n, v = document.getElementsByClassName("youtube-player"); for (n = 0; n < v.length; n++) { div = document.createElement("div"); div.setAttribute("data-id", v[n].dataset.id); div.innerHTML = labnolThumb(v[n].dataset.id); div.onclick = labnolIframe; v[n].appendChild(div); } //end for function labnolThumb(id) { var thumb = '', play = '
'; return thumb.replace("ID", id) + play; } //end labnolThumb function labnolIframe() { var iframe = document.createElement("iframe"); var embed = "https://www.youtube.com/embed/ID?autoplay=1"; iframe.setAttribute("src", embed.replace("ID", this.dataset.id)); iframe.setAttribute("frameborder", "0"); iframe.setAttribute("allowfullscreen", "1"); this.parentNode.replaceChild(iframe, this); } //end labnolIframe } //end youTubeEmbed //3) Function to show javascript-disabled content function hideJavascriptDisabledContent() { setTimeout(function() { const nonJsElements = document.querySelectorAll(".no-js"); nonJsElements.forEach( nonJsElement => (nonJsElement.style.display = "none") ); }, 100); } //end hideJavascriptDisabledContent function //4) Function to ensure libCal skip-links work in mobile function skipLinksInMobile() { $("#s-lc-public-skiplink").click(function(e) { e.preventDefault(); $(":header:first") .attr("tabindex", "-1") .focus(); }); } //----------------------------------------------------------- //End of List of functions //----------------------------------------------------------- //All functions listed above contained in single function called 'main': function main() { addBreadcrumbs(); //Function 1 youTubeEmbed(); //Function 2 hideJavascriptDisabledContent(); //Function 3 skipLinksInMobile(); //Function 4 } //end main() //Run all functions listed above as soon as content is loaded: if (document.addEventListener) { // For all major browsers, except IE 8 and earlier document.addEventListener("DOMContentLoaded", main, false); } else { // Works on all browsers, though must wait for all content to load before firing window.onload = main; } //end if })(window, document);