User:Yair rand/MobileJS.js

/* Super gross hack implemented where MOST of the JS is repeated in lib/native_app_hack.rb If you make significant changes here, make sure to update that version too!*/

window.onload = function { document.getElementById('logo').onclick = function { var n = document.getElementById( 'nav' ).style; n.display = n.display=='block'?'none':'block'; };

for(var h = document.getElementsByTagName("h2"), i = 0; i < h.length; i++){ if(h[i].className == 'section_heading'){ h[i].onclick = function{ var section_idx = parseInt( this.id.replace( /section_(\d+)/, '$1' ) ); wm_toggle_section( section_idx ); }		}	};

for(var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++){ a[i].onclick = function { if( this.hash.indexOf( '#' ) == 0 ) { wm_reveal_for_hash( this.hash ); }		}	};

if( document.location.hash.indexOf( '#' ) == 0 ) { wm_reveal_for_hash( document.location.hash ); }

updateOrientation;

// Try to scroll and hide URL bar window.scrollTo( 0, 1 );

decode = document.getElementById( 'searchField' ); decode.value = unescape( decode.value ); decode = document.getElementsByTagName( 'title' )[0]; decode.innerHTML = unescape( decode.innerHTML ); };

/** * updateOrientation checks the current orientation, sets the body's class * attribute to portrait, landscapeLeft, or landscapeRight, * and displays a descriptive message on "Handling iPhone or iPod touch Orientation Events". */ function updateOrientation { switch( window.orientation ) { case 0: document.body.setAttribute( 'class', 'portrait' ); break; case 90: case -90: document.body.setAttribute( 'class', 'landscape' ); } }

// Point to the updateOrientation function when iPhone switches between portrait and landscape modes. window.onorientationchange = updateOrientation;

function wm_reveal_for_hash( hash ) { var targetel = document.getElementById( hash.substr(1) ); if( targetel ) { for(var p = targetel.parentNode; p&&p.className!='content_block'; ){ p = p.parentNode; }		if(p && p.style.display != 'block'){ var section_idx = parseInt( p.id.replace( /content_(\d+)/, '$1' ) ); wm_toggle_section( section_idx ); }	} }

function wm_toggle_section( section_id ) { var b = document.getElementById( 'section_' + section_id ), bb = b.getElementsByTagName("button"); for(var i = 0; i <= 1; i++){var s = bb[i].style; s.display = s.display=='none'||(i&&!s.display)?'inline-block':'none';} for(var i = 0, d = ['content_','anchor_']; i<=1; i++){ var s = document.getElementById(d[i]+section_id).style; s.display=s.display=='block'?'none':'block'; } }