Template:Calgary/Template-Code

function updateSectionMenuPosition() {

var currentScrollPos = window.pageYOffset;

desktopSectionMenu = document.getElementById("banner-back"); menuTop = desktopSectionMenu.offsetTop + desktopSectionMenu.offsetHeight; desktopSections = document.getElementById("desktop-sections"); desktopGotoTop = document.getElementById("go-top"); interface = document.getElementById("interface"); var totalSectionMenuHeight = desktopSections.offsetHeight + 60 + desktopGotoTop.offsetHeight;

if(currentScrollPos > menuTop-150) { desktopSections.classList.add("scroll"); desktopGotoTop.classList.add("scroll"); desktopSections.style.top = 300 + "px"; desktopGotoTop.style.top = (desktopSections.offsetHeight + 300 + 60) + "px"; } else { desktopSections.classList.remove("scroll"); desktopGotoTop.classList.remove("scroll"); }

}

function updateSectionMenuEmphasis() {

var currentScrollPos = window.pageYOffset;

  	for(var sectionIndex = 0; sectionIndex < sections.length; ++sectionIndex) {
  		var activeSection = getActiveSection();
  		if (activeSection != null) {
  			activeSection[1] = false;
  		}

if(sectionIndex == 0) {

  			if(sections.length > 1) {
  				if(currentScrollPos < sections[1][3]) {
  					sections[0][1] = true;
  					break;
  				}
  			} else {
  				sections[0][1] = true;
  				break;
  			}
  		} else {
  			if (sectionIndex == sections.length-1) {
  				if(currentScrollPos >= sections[sections.length-1][3]) {
  					sections[sections.length-1][1] = true;
  					break;
  				}
  			} else {
  				if(currentScrollPos >= sections[sectionIndex][3] && currentScrollPos < sections[sectionIndex+1][3]) {
  					sections[sectionIndex][1] = true;
  					break;
  				}
  			}
  		}
  	}
  		
  	changeSectionHTML();

}

function generateSectionMarkers() { var content = document.getElementById("textual-content"); var headers = content.querySelectorAll("h1");

for(var headerIndex = 0; headerIndex < headers.length; ++headerIndex) { headerText = headers[headerIndex].textContent; var marker = document.createElement("DIV"); marker.classList.add("section-marker"); headers[headerIndex].appendChild(marker); marker.id = headerText.replace(/\s/g, ); } }

var sections = [];

function storeAndLabelSections() {

var content = document.getElementById("textual-content"); var headers = content.querySelectorAll("h1");

var data = [];

for(var headerIndex = 0; headerIndex < headers.length; ++headerIndex) { sectionMarker = headers[headerIndex].querySelectorAll(".section-marker")[0]; headerText = headers[headerIndex].textContent; if (headerIndex == 0) { data.push([headerText,true, headers[headerIndex], headers[headerIndex].offsetTop+sectionMarker.offsetTop-10]); } else { data.push([headerText,false, headers[headerIndex], headers[headerIndex].offsetTop+sectionMarker.offsetTop-10]); } }

sections = data; }

function toggleMenu() { banner = document.getElementById("banner"); sectionMenu = document.getElementById("section-menu");

bannerTop = banner.offsetTop bannerHeight = banner.offsetHeight; sectionMenuHeight = sectionMenu.offsetHeight;

if (sectionMenu.classList.contains("section-menu-up")) { sectionMenu.classList.remove("section-menu-up"); sectionMenu.style.transform = "translateY(0px)"; } else { sectionMenu.classList.add("section-menu-up"); sectionMenu.style.transform = "translateY(" + -sectionMenuHeight + "px)"; }

}

function activateClick(e) {

e = e || window.event; var target = e.target || e.srcElement;

if(!bigScreen && target.parentElement != null && target.parentElement.parentElement != null) { if (target.parentElement.parentElement.className.match("section-menu")) { toggleMenu(); } } }

function getActiveSection() { for(var sectionIndex = 0; sectionIndex < sections.length; ++sectionIndex) { if (sections[sectionIndex][1]) { return sections[sectionIndex]; } } }

function changeSectionHTML() {

var HTML = ""; for(var sectionIndex = 0; sectionIndex < sections.length; ++sectionIndex) { sectionText = sections[sectionIndex][0]; sectionTextNoSpaces = sectionText.replace(/\s/g, ); if(sectionIndex == 0) { if(sections[sectionIndex][1]) { HTML += "<a class=\"section active\" href=\"#" + sectionTextNoSpaces + "\">" + sectionText + "</a>"; } else { HTML += "<a class=\"section\" href=\"#" + sectionTextNoSpaces + "\">" + sectionText + "</a>"; } } else { if(sections[sectionIndex][1]) {

HTML += "
<a class=\"section active\" href=\"#" + sectionTextNoSpaces + "\">" + sectionText + "</a>";

} else {

HTML += "
<a class=\"section\" href=\"#" + sectionTextNoSpaces + "\">" + sectionText + "</a>";

} } }

var sectionsDivisionDesktop = document.getElementById("desktop-sections").innerHTML = HTML; var sectionsDivision = document.getElementById("sections").innerHTML = HTML; }


function initializeButtonEvents() {

if (document.body.addEventListener) { document.body.addEventListener('click', activateClick, false); } else { document.body.attachEvent('onclick', activateClick); //for IE }

}