Team:Queens-Canada/common/content.js

From 2010.igem.org

Revision as of 19:14, 27 October 2010 by Glh (Talk | contribs)

var mobile = false; mobile = parent.isMobile();

function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; }

function stylist() { var foo = getElementsByClass('aside', document).concat(getElementsByClass('asideR', document), getElementsByClass('asideL', document)); for(x in foo) { c = foo[x];

c.innerHTML = '
' + c.innerHTML + '
';

} }

function mobileMode() { var foo = getElementsByClass('section', document); cilist = ; var h1id = document.getElementById('p-logo'); for(x in foo) { c = foo[x].firstChild; while((c.nodeName[0] != "H") && (c != null)) { c = c.nextSibling; } if(c) { if(c.nodeName != "H1") { ci = c.innerHTML; if(cilist != "") cilist += " · "; cilist += '<a href="#' + ci + '" onclick="openv(\ + ci + '\')">' + ci + '</a>'; if(mobile) { c.innerHTML = '<a name="' + ci + '" id="' + ci + '" class="anchor"></a>' + ci + ' <a href="#" class="return">top</a>'; } else { c.innerHTML = '<a name="' + ci + '" id="' + ci + '" class="anchor"></a>' + ci + ' <a href="#" class="return">return to top</a> · <a href="#" onclick="history.back()" class="return">back</a>'; } if(mobile) togglev(c); } else { h1id = c; } // c.onclick = togglev; } }

if(mobile) { bb = document.getElementById('bodyb'); bb.setAttribute('style', 'margin-left: auto; margin-right: auto; max-width: 700px'); h1id.innerHTML = '' + h1id.innerHTML + ''; // no calculated table on mobile } else {

h1id.innerHTML = '' + h1id.innerHTML + '
' + cilist + '
';

} }

function openv(theol) { theo = document.getElementById(theol); if(!theo.nodeName) theo = this; if(theo.nodeName == "SPAN") theo = theo.parentNode; tha = theo.parentNode.parentNode; tha.scrollTop = 0; tha.style.height = "auto"; parent.resizeIframe(document.getElementById('bodyb').scrollHeight); }

function togglev(theo) { if(!theo.nodeName) theo = this; if(theo.nodeName == "SPAN") theo = theo.parentNode; tha = theo.parentNode; var c = theo.nextSibling; tha.scrollTop = 0; if(!tha.style.height) tha.style.height = "auto"; if(tha.style.height == "auto") { tha.style.height = theo.clientHeight + 'px'; } else { tha.style.height = "auto"; } parent.resizeIframe(document.getElementById('bodyb').scrollHeight); }