Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*== Actual code ==<source lang="javascript">*/functioncollapseTable(tableIndex){varButton=document.getElementById('collapseButton'+tableIndex);varTable=document.getElementById('collapsibleTable'+tableIndex);if(!Table||!Button){returnfalse;}varcollapseColsOptin=hasCollapsibleCol(tableIndex);// newvarcollapseColsOptout=hasNoncollapsibleCol(tableIndex);// newvarCols=Table.rows[0].cells;// newvarCollapseCols=newArray(Cols.length);// new; has to be larger if there are colspansif(collapseColsOptin||collapseColsOptout){// new// @colspan currently not handled// the following two if-for-if constructs could be combinedif(collapseColsOptin){for(vari=0;i<Cols.length;i++){if(CollapseCols[i]==null||!hasClass(Cols[i],'collapsible')){CollapseCols[i]=!collapseColsOptin;}else{CollapseCols[i]=collapseColsOptin;}}}// 'nocollapse' takes precedence over 'collapsible', i.e.// default columns are not collapsible when both types existif(collapseColsOptout){for(vari=0;i<Cols.length;i++){if(CollapseCols[i]==null||!hasClass(Cols[i],'nocollapse')){CollapseCols[i]=collapseColsOptout;}else{CollapseCols[i]=!collapseColsOptout;}}}// column with first |th| should be excluded, because it holds the show/hide buttonvarHeader=Table.rows[0].getElementsByTagName('th')[0];CollapseCols[Header.cellIndex]=false;// cellIndex doesn’t handle @colspan}varRows=Table.rows;// insert check for @colspan here, change CollapseCols accordinglyif(Button.firstChild.data==collapseCaption){// hideif(collapseColsOptin||collapseColsOptout){// newfor(vari=0;i<Rows.length;i++){varCells=Rows[i].cells;for(varj=0;j<CollapseCols.length;j++){// if we used Cells.length the handling of rows with empty cells at the end should improve// this would be a problem if the header row had empty cells at the end// we could also do CollapseCols.length-Cells.length times Rows[i].insertCell(-1) if(CollapseCols[j]){Cells[j].style.display='none';// needs to take @colspan into account}}}}varcollapseRowsOptin=hasCollapsibleRow(tableIndex);// new// @rowspan currently not handledfor(vari=1;i<Rows.length;i++){if(collapseRowsOptin){// newif(hasClass(Rows[i],'collapsible')){Rows[i].style.display='none';}}elseif(!collapseColsOptin&&!collapseColsOptout){if(!hasClass(Rows[i],'nocollapse')&&!(hasClass(Rows[i],'sortbottom')&&!hasClass(Rows[i],'collapsible'))){// new condition to exclude certain rows from collapsingRows[i].style.display='none';}}}Button.firstChild.data=expandCaption;}else{// showfor(vari=0;i<Rows.length;i++){if(collapseColsOptin||collapseColsOptout){// newvarCells=Rows[i].cells;for(varj=0;j<CollapseCols.length;j++){if(CollapseCols[j]){Cells[j].style.display=Rows[0].style.display;}}}Rows[i].style.display=Rows[0].style.display;}Button.firstChild.data=collapseCaption;}}/* new function to check whether the collapsible table has * any column with the class 'collapsible' */functionhasCollapsibleCol(tableIndex){varTable=document.getElementById('collapsibleTable'+tableIndex);if(!Table){returnfalse;}varCols=Table.rows[0].cells;for(vari=0;i<Cols.length;i++){if(hasClass(Cols[i],'collapsible')){returntrue;}}returnfalse;}/* new function to check whether the collapsible table has * any column with the class 'nocollapse' */functionhasNoncollapsibleCol(tableIndex){varTable=document.getElementById('collapsibleTable'+tableIndex);if(!Table){returnfalse;}varCols=Table.rows[0].cells;for(vari=0;i<Cols.length;i++){if(hasClass(Cols[i],'nocollapse')){returntrue;}}returnfalse;}/* new function to check whether the collapsible table has * any row (except the header) with the class 'collapsible' */functionhasCollapsibleRow(tableIndex){varTable=document.getElementById('collapsibleTable'+tableIndex);if(!Table){returnfalse;}varRows=Table.rows;for(vari=1;i<Rows.length;i++){if(hasClass(Rows[i],'collapsible')){returntrue;}}returnfalse;}// </source>