ہتھونڈائی:Collapsing

وکیپیڈیا توں
Jump to navigation Jump to search

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
|}
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
|}
A normal cell in the header row Header cell spans two cols
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 2 or more collapsible tables on the page (this threshold might be different on other projects). The example below, therefore, collapses because there are numerous collapsible tables on the page.

Code entered Output produced
{| class="wikitable collapsible autocollapse"
! Simple collapsible table
|-
| Lorem ipsum dolor sit amet
|}
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. This is mainly useful for tables inside templates, which are often nested.

Code entered Output produced
{| class="wikitable outercollapse"
! This table does not collapse
|-
| But the table inside this cell

{| class="wikitable collapsible innercollapse"
! Does collapse
|-
| Hiding this part
|}

|}
This table does not collapse
But the table inside this cell
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 cell is not wide enough:

Code entered Output produced
{|class="wikitable collapsible sortable" style="width:5em"
<!--table width too narrow, on purpose here-->
|-
!scope="col"|Name!!scope="col"|Score
|-
|John||59
|-
|Jane||100
|-
|Bob||72
|}
Name Score
John 59
Jane 100
Bob 72

Possible alternative (that appears quite horrible from utility point of view, though) is sortable table inside one-cell collapsible table whose header will be as large as the full table embedded below. See the following example.

Code entered Output produced
{|class="wikitable collapsible collapsed" style="border:none"
|-
!scope="col"|header
|-
|style="padding:0;border:none"|
{|class="wikitable sortable" style="margin:0;width:100%"
|-
!scope="col"|a!!scope="col"|b
|-
|3||4
|-
|5||6
|}
|}


Customization[لکھو]

Registered users can edit their personal 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 other elements, such as <div> or <span>. There is a similar feature for use with <div> elements, called "NavFrame".

Limitations[لکھو]

This functionality requires the end-user's browser to have JavaScript enabled. If Javascript is disabled, the default behaviour is to show the content.

See also[لکھو]

Documentation:

Templates:

External links[لکھو]

سانچہ:Wikipedia technical help


Content can be made collapsible with JavaScript (acting on CSS classes and manipulating their display properties).

This functionality (unlike sortable tables) is not part of MediaWiki. It depends on the code added by admins to the project's MediaWiki:Common.js.

Collapsible table[لکھو]

To make any table collapsible, add a special class collapsible

For example, the following table is defined with {| class="collapsible wikitable":

Always displayed header
Optionally displayed text; optionally displayed text

Initial state[لکھو]

Collapsible table is initially expanded by default.

You can change this with two additional special classes:

  • autocollapse: table will be collapsed if there are more than 2 collapsible tables on the page,
  • collapsed: table will be initially collapsed.

Example: {| class="wikitable collapsible collapsed"

Table width[لکھو]

Since usually the natural width of the header is smaller than of the main content, the table' width will increase after expanding and it will "jump" around. (Also, even if the header would fit in the width of the browser window, the layout engine might divide it over two lines.) It is ugly in itself and inconvenient if you want only to have a quick look at the hidden content and then collapse it again without having to hunt the link with cursor in between. This is prevented by explicitly setting table's width, which then remains the same in the collapsed and expanded state.

Compare this to the first example: {| class="collapsible wikitable" style="width:34em"

Always displayed header, table has width:34em
optionally displayed text: you can see it doesn't matter at all that this is so much longer, table width has been set at 34em

Usage[لکھو]

For content that is not a table one can create a table with only one element with content, and a header. However there's a table-less, purely DIV-based solution available on the Wikipedia - see #Collapsible DIV below.

For existing table one can simply add collapsible class. If the table has several colums, it might be a good idea to add a heading row consisting of one cell otherwise the link will be in the first one. Sometimes an easy solution is to put the whole table as element inside another table (see example below); however this is bad from the webdesign and usability viewpoint.

Sortable collapsible table[لکھو]

Sortable table inside a collapsible table:

initially expanded initially collapsed
class="collapsible" class="collapsible collapsed"
numbers
name number
a 123
b 6
c 45

If the sortable table is itself made collapsible the positioning of the hide/show button is a bit odd:

initially expanded initially collapsed
class="wikitable sortable collapsible" class="wikitable sortable collapsible collapsed"
name number
a 123
b 6
c 45

Another way to fix this:

initially expanded initially collapsed
class="mw-collapsible" class="mw-collapsible collapsed"
Numbers table
name number
a 123
b 6
c 45
Numbers table
name number
a 123
b 6
c 45

Personal customization[لکھو]

Registered users can edit their own monobook.js to change these variables (default values are shown):

autoCollapse = 2 //how many collapsible tables on the page before autocollapse works
var collapseCaption = 'hide' //text of the [hide] link
var expandCaption = 'show' //text of the [show] link

Collapsible DIV[لکھو]

This functionality is not implemented on Meta, for information see سانچہ:Mlww.

See also[لکھو]

سانچہ:H:f