//================================================================== // NAME: // bioLocate.js // PURPOSE: // Javascript location functions // HISTORY: // 09-05-2007, Craig Helgason (craig.helgason@und.edu) //================================================================== //------------------------------------------------------------------ // NAME: // findPosX // PURPOSE: // Return the current left (X) position of the object on the page // INPUTS: // obj = the object to find the position of // RETURNS: // The X location. // PROCEDURE: // If offsetParent is supported, traverse up the object tree, incrementing // the left position. Else if obj.x is supported, add it to left position //------------------------------------------------------------------ function findPosX(obj){ var curleft = 0; if (obj.offsetParent){ while (obj.offsetParent){ curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } //------------------------------------------------------------------ // NAME: // findPosY // PURPOSE: // Return the current top (Y) position of the object on the page // INPUTS: // obj = the object to find the position of // RETURNS: // The Y location. // PROCEDURE: // If offsetParent is supported, traverse up the object tree, incrementing // the top position. Else if obj.y is supported, add it to top position //------------------------------------------------------------------ function findPosY(obj){ var curtop = 0; if (obj.offsetParent){ while (obj.offsetParent){ curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; } //------------------------------------------------------------------ // NAME: // toggle // PURPOSE: // Toggles the visibility of expandable blocks of content // INPUTS: // id = the id of the content block to toggle // RETURNS: // none // PROCEDURE: // Set object variables // - "section" to the content block // - "sectionImage" to the expand/contract graphic // (in our case, small plus/minus graphics used throughtout UMAC sites) // - "main" to the sub content block below the link/title. // If the block is hidden, show it // - set display style to "block" // - set image source to minus/contract graphic // - get the top position of the sub content block // - scroll the window to display the entire sub content block // (this is so the block won't expand beyond the bottom of the window) // Else if it's visible, hide it // - set display style to "none" // - set image source to plus/expand graphic //------------------------------------------------------------------ function toggle(id){ section = document.getElementById(id); sectionImage = document.getElementById("img_"+id); main = document.getElementById("main_"+id); if (section.style.display == 'none'){ section.style.display = "block"; sectionImage.src = "/images/minus.gif"; main_Ypos = findPosY(main); // If expanding the content block will result in it spilling off the page, // reset the page scroll so the bottom of the bio lands on the bottom of the page. // If the (block Y + block height) > (window Y + window height) // then, set Y scroll = bottom of the block - window height. if(document.all){ if(ie7) { scrollTop = document.documentElement.scrollTop; offsetHeight = document.documentElement.offsetHeight; } else { scrollTop = document.body.scrollTop; offsetHeight = document.body.offsetHeight; } if((main_Ypos+main.offsetHeight)>=(scrollTop+offsetHeight)){ window.scrollTo(0,main_Ypos+main.offsetHeight-offsetHeight+20); } }else { if((main_Ypos+main.offsetHeight)>=(window.pageYOffset+window.innerHeight)){ window.scrollTo(0,main_Ypos+main.offsetHeight-window.innerHeight+20); } } // NOTE: If you want to just point to the top of the block, add a named anchor above // each block, and uncomment this assignment to set the browser position to the hash. //location.hash = 'a_'+id; }else{ section.style.display = "none"; sectionImage.src = "/images/plus.gif"; } }