User:Saintrain/C1/colcol.js

// /*====================== Collapsible columns  ====================================================== ** Collapsible columns "adapted" from Common.js****************** ** Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See *        Wikipedia:NavFrame. * Maintainers: User:R. Koot *******************************************************************************/ var autoCollapse = 2; var collapseCaption = ""; var expandCaption  = "+";

//====================== collapseCol  ====================================================== function collapseCol( btnIndex ) { BUG = false; if(BUG) console.time("cc");

if(BUG) console.group('cc: ndx=', btnIndex ); var Btn = document.getElementById( "ccbtn" + btnIndex ); if ( !Btn ) { if(BUG) console.log('cc: NO find. Btn'); } var Tbl = document.getElementById( "ccbtnd" + btnIndex ); if ( !Tbl ) { if(BUG) console.log('cc: NO find. Tbl '); } var Hdr = document.getElementById( "ccbtnh" + btnIndex ); if ( !Hdr ) { if(BUG) console.log('cc: NO find. Hdr '); } if ( !Btn || !Tbl || !Hdr ) { if(BUG) console.log('cc: out' ); if(BUG) console.groupEnd; return false; } /// console.log('cc: Found ALL!.');

if(BUG) console.log('cc: Btn.childNodes.length=', Btn.childNodes.length ); if( Btn.childNodes.length ) if(BUG) console.log('cc: Btn.firstChild.data=',Btn.firstChild.data );

if( !Btn.childNodes.length || (Btn.firstChild.data == collapseCaption) ) { // do collapse  /// if(BUG) console.log('cc: collapsing'); Tbl.style.display = 'none';  // fontSizeq = 3;  // visible = false;   // color = "fuchsia";  // width = "5"; Btn.style.backgroundColor = "silver"; //  0xbbbbbb;  // "#dddddd";  // Btn.firstChild.data = btnIndex + 1; // expandCaption; } else { if(BUG) console.log('cc: EXPANDING'); Tbl.style.display = 'inline';  // fontSize = "normal";  // visible = true;   // color = "black";  // width = "55"; Btn.style.backgroundColor = "white";   /// Btn.style.color = "fuchsia"; Btn.firstChild.data = collapseCaption; } if(BUG) console.groupEnd; if(BUG) console.timeEnd("cc");

}

//====================== createColColButtons  ====================================================== function createColColButtons { BUG = false; if(BUG) console.time("cccb");

var NccBtns = 0; var CCTbls = getElementsByClass( '\\bccTbl\\b', null, 'table' ); if(BUG) console.log('nCCTbls=', CCTbls.length,  ' ');

for(var it=0; it<CCTbls.length; it++) { if(BUG) console.log('CCTbls[', it, ']={', CCTbls[it].className, '}. nKids=(', CCTbls[it].childNodes.length, ')'); if(BUG) console.log('CCTbls[', it, ']={', CCTbls[it].className, '}. nKids=(', CCTbls[it].length, ')');

if(BUG) console.log('fEBC( "ccBtn\b" ) '); var ccb = getElementsByClass( '\\bccBtn\\b', CCTbls[it], 'td', true ); if(BUG) if( ccb ) msg = ccb.className; else msg = "NOT FOUND"; if(BUG) console.log(' found "ccBtn" kid? ccb.class={', ccb.className, '} ');

var ccd = getElementsByClass( '\\bccTblD\\b', CCTbls[it], 'table', true ); if(BUG) if( ccd ) msg = ccd.className; else msg = "NOT FOUND"; if(BUG) console.log(' found "ccBtnD" kid? ccd.class={', ccb.className, '} ');

var cch = getElementsByClass( '\\bccTblDH\\b', ccd, 'tr', true ); if(BUG) if( cch ) msg = cch.className; else msg = "NOT FOUND"; if(BUG) console.log(' found "ccBtnDH" kid? cch.class={', msg, '} ');

if( ccb && ccd && cch ) { var ndx = NccBtns; ccb.setAttribute( "id", "ccbtn" + ndx ); ccb.firstChild.data = collapseCaption; ccb.onclick = new Function( "collapseCol(" + ndx + ")" );

ccd.setAttribute( "id", "ccbtnd" + ndx ); cch.setAttribute( "id", "ccbtnh" + ndx ); cch.onclick = new Function( "collapseCol(" + ndx + ")" ); if(BUG) console.log(' ccbId=',ccb.id, ' ccdId=',ccd.id, ' cchId=',cch.id ); NccBtns++; }  else { if(BUG) console.log(' NO ccb or ccd or cch! Klvl=',Klvl, ' '); }

/// Kids( CCTbls[it] ); /// document.writeln(' Klvl = ', Klvl, ' '); }

/* */ if(BUG) console.timeEnd("cccb");

}

//============================================================================ addOnloadHook( createColColButtons );

//