m Robot: moving pages out of redirected category |
Happy-melon (talk | contribs) complete rewrite |
||
Line 3: | Line 3: | ||
The initial state of any collapsible content can be controlled using a "collapsible table", because it also allows a table with only one element with content, and a header. |
The initial state of any collapsible content can be controlled using a "collapsible table", because it also allows a table with only one element with content, and a header. |
||
==Simple example== |
|||
Tables are simpler to work with, as you merely need to add the '''< |
Tables are simpler to work with, as you merely need to add the '''<tt>collapsible</tt>''' class to the table itself. For the [hide]/[show] link to appear, the table's first row must be a header row, that is, one of the cells in the first row must be declared with an exclamation mark (in wikisyntax). The use of the class <tt>wikitable</tt> in the example below is merely for appearance; it is not needed for <tt>collapsible</tt> to function. |
||
<pre> |
|||
{| class= |
{| class=wikitable style="width:80%;" align=center |
||
!Code entered!!Output produced |
|||
!colspan="2"| Fun with table columns |
|||
|- |
|- |
||
|width=50%|  |
|||
| Column 1 || Column 2 |
|||
<nowiki>{| class="wikitable </nowiki>'''collapsible'''" |
|||
|} |
|||
'''!'''<nowiki> Simple collapsible table |
|||
</pre> |
|||
{| class="toccolours collapsible" width="60%" |
|||
!colspan="2"| Fun with table columns |
|||
|- |
|- |
||
| Lorem ipsum dolor sit amet |
|||
| Column 1 || Column 2 |
|||
|}</nowiki> |
|||
|style="width:50%; text-align:center;"| |
|||
{| class="wikitable collapsible" |
|||
! Simple collapsible table |
|||
|- |
|||
| Lorem ipsum dolor sit amet |
|||
|} |
|||
|} |
|} |
||
Using the syntax above, collapsible tables are often used to always display an introduction to, or summary of, a lengthy discussion or section of content, while hiding the majority of that content from immediate view. The summary message is put in the header cell, and the content is placed into the body cell. The content is then easily accessible by clicking the 'show' button. The collapsible functionality is also available in larger and more complicated tables, as long as there is a header cell in the first row of the table. |
|||
==== One-element example, initially expanded ==== |
|||
<pre> |
|||
{| class=" |
{| class=wikitable style="width:80%;" align=center |
||
!Code entered!!Output produced |
|||
!Always displayed header |
|||
|- |
|- |
||
|style="width:50%; font-size:90%"|  |
|||
|Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text |
|||
<nowiki>{| class="wikitable </nowiki>'''collapsible'''<nowiki>" |
|||
|} |
|||
|A normal cell in the header row |
|||
</pre> |
|||
</nowiki>'''!'''<nowiki> colspan="2"| Header cell spans two cols |
|||
{| class="collapsible" |
|||
|- |
|||
!Always displayed header |
|||
| colspan="2" | Lorem ipsum dolor sit amet |
|||
| Separate body cell |
|||
|}</nowiki> |
|||
|style="width:50%; text-align:center;"| |
|||
{| class="wikitable collapsible" |
|||
|width=33%|A normal cell in the header row |
|||
! colspan="2"| Header cell spans two cols |
|||
|- |
|- |
||
| colspan="2" | Lorem ipsum dolor sit amet |
|||
|Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text |
|||
|width=33%| Separate body cell |
|||
|} |
|||
|} |
|} |
||
== |
==Collapsing tables by default== |
||
You have two choices of auto-collapse. In addition to the <code>collapsible</code> class, you can add either '''<code>collapsed</code>''' or '''<code>autocollapse</code>'''. The first always initially collapses a table. <code>autocollapse</code> only initially collapses a table if there are at least two collapsible tables on a page. |
|||
Just using the <tt>'''collapsible'''</tt> class produces a table which is expanded by default, but can be collapsed by the reader. It is also possible to create tables which are ''collapsed'' by default, and can be optionally ''expanded''. There are several methods for doing this, depending on the situations in which you want the table to collapse. |
|||
<pre>{| class="toccolours collapsible autocollapse" width=60% |
|||
==='collapsed'=== |
|||
Adding the <tt>'''collapsed'''</tt> class will cause the table to ''always'' be initially collapsed, no matter what happens around it. It is the simplest method for doing so. Using the examples above: |
|||
{| class=wikitable style="width:80%;" align=center |
|||
!Code entered!!Output produced |
|||
|- |
|- |
||
|width=50%|  |
|||
! colspan="2" | This autocollapse table will initially collapse because there are at least two collapsible tables on this page. |
|||
<nowiki>{| class="wikitable </nowiki>'''collapsible collapsed'''" |
|||
'''!'''<nowiki> Simple collapsible table |
|||
|- |
|- |
||
| Lorem ipsum dolor sit amet |
|||
| Column 1 || Column 2 |
|||
|}</ |
|}</nowiki> |
||
|style="width:50%; text-align:center;"| |
|||
{| class="toccolours collapsible autocollapse" width=60% |
|||
{| class="wikitable collapsible collapsed" |
|||
! Simple collapsible table |
|||
|- |
|||
| Lorem ipsum dolor sit amet |
|||
|} |
|||
|- |
|- |
||
|style="width:50%; font-size:90%"|  |
|||
! colspan="2" | This autocollapse table will initially collapse because there are at least two collapsible tables on this page. |
|||
<nowiki>{| class="wikitable </nowiki>'''collapsible collapsed'''<nowiki>" |
|||
|A normal cell in the header row |
|||
</nowiki>'''!'''<nowiki> colspan="2"| Header cell spans two cols |
|||
|- |
|||
| colspan="2" | Lorem ipsum dolor sit amet |
|||
| Separate body cell |
|||
|}</nowiki> |
|||
|style="width:50%; text-align:center;"| |
|||
{| class="wikitable collapsible collapsed" |
|||
|width=33%|A normal cell in the header row |
|||
! colspan="2"| Header cell spans two cols |
|||
|- |
|- |
||
| colspan="2" | Lorem ipsum dolor sit amet |
|||
| Column 1 || Column 2 |
|||
|width=33%| Separate body cell |
|||
|} |
|||
|} |
|} |
||
==='autocollapse'=== |
|||
<pre>{| class="toccolours collapsible collapsed" width=60% |
|||
|- |
|||
Adding the <tt>'''autocollapse'''</tt> class causes the table to collapse when there are more than a threshold number of collapsible tables on the page. On en.wiki, this threshold is set at 2. So all tables on a page after the first will collapse if they have the <tt>autocollapse</tt> class. The example below, therefore, collapses because there are numerous collapsible tables higher on the page; if it were moved to the top of the list, it would ''not'' collapse by default. |
|||
! colspan="2" | This table will always initially collapse |
|||
{| class=wikitable style="width:80%;" align=center |
|||
!Code entered!!Output produced |
|||
|- |
|- |
||
|width=50%|  |
|||
| Column 1 || Column 2 |
|||
<nowiki>{| class="wikitable </nowiki>'''collapsible autocollapse'''" |
|||
|}</pre> |
|||
'''!'''<nowiki> Simple collapsible table |
|||
|- |
|- |
||
| Lorem ipsum dolor sit amet |
|||
! colspan="2" | This table will always initially collapse |
|||
|}</nowiki> |
|||
|style="width:50%; text-align:center;"| |
|||
{| class="wikitable collapsible autocollapse" |
|||
! Simple collapsible table |
|||
|- |
|- |
||
| Lorem ipsum dolor sit amet |
|||
| Column 1 || Column 2 |
|||
|} |
|} |
||
One-element example, initially collapsed: |
|||
{| class="collapsible collapsed" |
|||
!Always displayed header |
|||
|- |
|||
|Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text Optionally displayed text |
|||
|} |
|} |
||
==='innercollapse' and 'outercollapse'=== |
|||
====Sortable collapsible tables==== |
|||
{| |
|||
{{ombox|type=content|text=The code for this functionality was only recently added to [[MediaWiki:Common.js]] and so will ''not'' work correctly for all readers of wikipedia until '''30 October 2008'''. When using this functionality before that time, be careful to ensure that the table would look right if it did not autocollapse. Please remove this notice after 30 October.}} |
|||
!initially expanded!!initially collapsed |
|||
Using this pair of classes, it is possible to make a table collapsed by default only when it is ''contained within'' a particular object, such as another table. |
|||
{| class=wikitable style="width:80%;" align=center |
|||
!Code entered!!Output produced |
|||
|- |
|- |
||
|width=50%|  |
|||
| |
|||
<nowiki>{| class="wikitable </nowiki>'''outercollapse'''<nowiki>" |
|||
{|class="collapsible" |
|||
! This table does not collapse |
|||
!numbers |
|||
|- |
|- |
||
| But the table inside this cell |
|||
| |
|||
{|class="wikitable sortable" |
|||
{| class="wikitable </nowiki>'''collapsible innercollapsed'''<nowiki>" |
|||
!name!!number |
|||
! Does collapse |
|||
|- |
|- |
||
| Hiding this part |
|||
|a||123 |
|||
|} |
|||
|}</nowiki> |
|||
|style="width:50%; text-align:center;"| |
|||
{| class="wikitable outercollapse" |
|||
! This table does not collapse |
|||
|- |
|- |
||
| But the table inside this cell |
|||
|b||6 |
|||
{| class="wikitable collapsible innercollapsed" |
|||
! Does collapse |
|||
|- |
|- |
||
| Hiding this part |
|||
|c||45 |
|||
|} |
|} |
||
|} |
|} |
||
| |
|||
|} |
|||
{|class="collapsible collapsed" |
|||
!numbers |
|||
==Other notes== |
|||
===Sortable tables=== |
|||
Collapsible tables can be combined with the [[Help:Sorting|sortable tables]] functionality without difficulty. However, because the hide/show button is placed in the first header cell located, its positioning can look a bit peculiar if the table is not wide enough: |
|||
{| class=wikitable style="width:80%;" align=center |
|||
!Code entered!!Output produced |
|||
|- |
|- |
||
|width=50%|  |
|||
| |
|||
{|class="wikitable sortable" |
<nowiki>{| class="wikitable </nowiki>'''collapsible sortable'''<nowiki>" |
||
! |
!Name!!Score |
||
|- |
|- |
||
| |
|John||59 |
||
|- |
|- |
||
| |
|Jane||100 |
||
|- |
|- |
||
| |
|Bob||72 |
||
|}</nowiki> |
|||
|} |
|||
|style="width:50%; text-align:center;"| |
|||
{|class="wikitable sortable collapsible" |
|||
!Name!!Score |
|||
|- |
|||
|John||59 |
|||
|- |
|||
|Jane||100 |
|||
|- |
|||
|Bob||72 |
|||
|} |
|} |
||
|} |
|} |
||
===Customization=== |
|||
Registered users can edit [[Special:MyPage/monobook.js|their monobook.js]] file to change some of the variables used. |
|||
<source lang=javascript> |
|||
autoCollapse = 4 //how many collapsible tables on the page before autocollapse works (default=2) |
|||
var collapseCaption = 'collapse' //text of the [hide] link (default='hide') |
|||
var expandCaption = 'uncollapse' //text of the [show] link (default='show') |
|||
</source> |
|||
===Other HTML elements=== |
|||
The code that performs the manipulation only checks for table elements, so these classes will not work for, for instance, <tt><nowiki><div></nowiki></tt> or <tt><nowiki><span></nowiki></tt> elements. There is a similar feature for use with <tt><nowiki><div></nowiki></tt> elements, called "NavFrame". See [[Help:NavFrame |
|||
==See also== |
==See also== |
Revision as of 15:34, 30 September 2008
Collapsible tables provide a way to collapse and uncollapse a table when a show/hide button is clicked. The code for this feature is found in the MediaWiki:Common.js.
The initial state of any collapsible content can be controlled using a "collapsible table", because it also allows a table with only one element with content, and a header.
Simple example
Tables are simpler to work with, as you merely need to add the collapsible class to the table itself. For the [hide]/[show] link to appear, the table's first row must be a header row, that is, one of the cells in the first row must be declared with an exclamation mark (in wikisyntax). The use of the class wikitable in the example below is merely for appearance; it is not needed for collapsible to function.
Code entered | Output produced | ||
---|---|---|---|
{| class="wikitable collapsible" ! Simple collapsible table |- | Lorem ipsum dolor sit amet |} |
|
Using the syntax above, collapsible tables are often used to always display an introduction to, or summary of, a lengthy discussion or section of content, while hiding the majority of that content from immediate view. The summary message is put in the header cell, and the content is placed into the body cell. The content is then easily accessible by clicking the 'show' button. The collapsible functionality is also available in larger and more complicated tables, as long as there is a header cell in the first row of the table.
Code entered | Output produced | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable collapsible" |A normal cell in the header row ! colspan="2"| Header cell spans two cols |- | colspan="2" | Lorem ipsum dolor sit amet | Separate body cell |} |
|
Collapsing tables by default
Just using the collapsible class produces a table which is expanded by default, but can be collapsed by the reader. It is also possible to create tables which are collapsed by default, and can be optionally expanded. There are several methods for doing this, depending on the situations in which you want the table to collapse.
'collapsed'
Adding the collapsed class will cause the table to always be initially collapsed, no matter what happens around it. It is the simplest method for doing so. Using the examples above:
Code entered | Output produced | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable collapsible collapsed" ! Simple collapsible table |- | Lorem ipsum dolor sit amet |} |
| ||||||
{| class="wikitable collapsible collapsed" |A normal cell in the header row ! colspan="2"| Header cell spans two cols |- | colspan="2" | Lorem ipsum dolor sit amet | Separate body cell |} |
|
'autocollapse'
Adding the autocollapse class causes the table to collapse when there are more than a threshold number of collapsible tables on the page. On en.wiki, this threshold is set at 2. So all tables on a page after the first will collapse if they have the autocollapse class. The example below, therefore, collapses because there are numerous collapsible tables higher on the page; if it were moved to the top of the list, it would not collapse by default.
Code entered | Output produced | ||
---|---|---|---|
{| class="wikitable collapsible autocollapse" ! Simple collapsible table |- | Lorem ipsum dolor sit amet |} |
|
'innercollapse' and 'outercollapse'
Using this pair of classes, it is possible to make a table collapsed by default only when it is contained within a particular object, such as another table.
Code entered | Output produced | ||||
---|---|---|---|---|---|
{| class="wikitable outercollapse" ! This table does not collapse |- | But the table inside this cell {| class="wikitable collapsible innercollapsed" ! Does collapse |- | Hiding this part |} |} |
|
Other notes
Sortable tables
Collapsible tables can be combined with the sortable tables functionality without difficulty. However, because the hide/show button is placed in the first header cell located, its positioning can look a bit peculiar if the table is not wide enough:
Code entered | Output produced | ||||||||
---|---|---|---|---|---|---|---|---|---|
{| class="wikitable collapsible sortable" !Name!!Score |- |John||59 |- |Jane||100 |- |Bob||72 |} |
|
Customization
Registered users can edit their monobook.js file to change some of the variables used.
autoCollapse = 4 //how many collapsible tables on the page before autocollapse works (default=2)
var collapseCaption = 'collapse' //text of the [hide] link (default='hide')
var expandCaption = 'uncollapse' //text of the [show] link (default='show')
Other HTML elements
The code that performs the manipulation only checks for table elements, so these classes will not work for, for instance, <div> or <span> elements. There is a similar feature for use with <div> elements, called "NavFrame". See [[Help:NavFrame