User:Conrad.Irwin/navframes.js

/*

Configuration
*/

var nf_show = 'show'; var nf_hide = 'hide';

var nf_general_state=false; //Global function nf_state(node){

//Allow editors to mark them as open by default if( node.className.indexOf('Shown') >= 0 ){ return nf_show; } if( nf_general_state==false ){ //Check userprefs if( getCookie('WiktionaryPreferencesShowNav') == 'true' ) { return nf_general_state=nf_show; }else{ var preview = document.getElementById('wikiPreview'); if (preview != null) { var p = preview.getElementsByTagName('p'); if (p != null && p.length >= 2 && p[1].firstChild.id == 'Translations') { return nf_general_state=nf_show; }     }      return nf_general_state=nf_hide; }   //Check length of content? } return nf_general_state; } /*

Find NavFrames
*/ function nf_initialise{

var divs = document.getElementsByTagName('div'); for( var i=0;i= 0 ){ nf_create(divs[i],i,nf_state(divs[i])); } } } /*

Create a Toggle
*/ function nf_create(node,uid,state){

var head = false; var content = false;

//Find the NavHead and NavContent for( var i=0;i= 0 ){ head = child; }else if( child.className.indexOf('NavContent') >= 0 ){ content = child; }   }  }  if(!head || !content) return false; //Make Nodes var span = document.createElement('span'); span.className='NavToggle editsection'; //Gives consistency with [edit] links var toggle=document.createElement('a'); //Register Event Handler try{ toggle.addEventListener('click',function{nf_toggle(toggle)},false); }catch(e){ toggle.attachEvent('onclick',function{nf_toggle(toggle)}); } //Create DOM toggle.appendChild(document.createTextNode(state)); span.appendChild(document.createTextNode('[')); span.appendChild(toggle); span.appendChild(document.createTextNode(']')); head.appendChild(span); //Link the two together and go to initial state content.setAttribute('id','for_nftog_'+uid); toggle.setAttribute('id','nftog_'+uid); nf_toggle(toggle); } /*

Click Handler
*/ function nf_toggle(toggle){ var id = toggle.getAttribute('id'); var state = toggle.childNodes[0].nodeValue; var content = document.getElementById('for_'+id); if(!content) return false; if( state==nf_hide ){ content.style.display='none'; toggle.childNodes[0].nodeValue=nf_show; }else{ //guess show content.style.display='block'; toggle.childNodes[0].nodeValue=nf_hide; } }

$(nf_initialise);

function createNavigationBarToggleButton {return false;}