MediaWiki talk:Gadget-CollapsibleTemplates.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Notice The use of CollapsibleTemplates has been deprecated in favour of using the mw-collapsible, mw-collapsed and mw-collapsible-content CSS classes (since MediaWiki 1.20).


This script can be used to create collapsible tables or boxes.
For tables the usage is slightly different, see equivalent m:Help:Collapsing (except user customization, which is not working on Commons).

Box example:

<div class="collapsibletemplate" style="border: 3px solid black;">
<div class="collapsibleheader header">
Click here to show details
</div>
<div class="body">
{{Lorem}}
</div>
</div>

generates

Click here to show details

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.


The box can be auto-collapsed by adding "collapsed" as a class. Example:

<div class="collapsibletemplate collapsed" style="border: 3px solid black;">
<div class="collapsibleheader header">
Click here to show details
</div>
<div class="body">
{{Lorem}}
</div>
</div>

generates


MediaWiki default implementation
<div class="mw-collapsible mw-collapsed" style="border: 3px solid black;">
<div class="mw-collapsible-toggle" style="cursor:pointer">Click here to show details</div>
This text is not collapsible; but the next is collapsible and hidden by default:
<div class="mw-collapsible-content">{{Lorem}}</div>
</div>

generates

Click here to show details

This text is not collapsible; but the next is collapsible and hidden by default:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

<div class="mw-collapsible mw-collapsed" style="border: 3px solid black;">
<div class="mw-collapsible-toggle" style="cursor:pointer; float:none">Click here to show details</div>
<div class="mw-collapsible-content">{{Lorem}}</div>
</div>

generates

Click here to show details
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Is this needed?[edit]

We already have two scripts to make collapsible boxes: MediaWiki:CollapsibleTables.js (tables) and MediaWiki:NavFrame.js (divs), do we really need another one? Instead of using if(skin=='vector'), it should be placed on or included in MediaWiki:Vector.js. There's no need to load this for every skin if it's only for vector. The CSS also seems to be specific to the vector skin and shouldn't be in Common.css. Since MediaWiki:NavFrame.js is already in use, uses the same name as en.wp and other projects, and is fairly stable, I think we should stick to that (but it needs to be moved from Monobook.js/Vector.js to Common.js, the css can be skin-specific). Rocket000 (talk) 16:40, 24 August 2010 (UTC)[reply]

Links in header[edit]

...are currently disabled. Click on the "Leonardo da Vinci" link at File:Mona Lisa.jpg: it will open the collabsed table instead of going to Leonardo da Vinci. Evidently the mousedown handler on the header overrides the normal click handler on the link. Methinks the code should be something like

    $headings.click(function(e) {
        if (e.target == this) {
          toggleTemplate($j(this));
          return false;
        }
        return true;
    });

This changes the behavior such that clicks on children on the header take precedence, i.e. only clicks on the header background will expand/collapse the collapsible, while clicks on links will open whatever is linked to.

Tested only on FF. Should the years ("1452-1519") also link somewhere? (Where does this bit come from anyway?) That still doesn't work with this modification. Also test on IE6/8 before deploying. Lupo 09:26, 22 October 2010 (UTC)[reply]

This template has issues too. The links should not expand it. Any way to get the old behavior, where only the arrow expands/collapses it? Rocket000 (talk) 01:23, 23 October 2010 (UTC)[reply]
It works now. Personnally I like that you can click anywhere, but I think the text remain black, otherwise it can be confusing, especially when there is a link in the template, like here.--Zolo (talk) 11:36, 29 October 2010 (UTC)[reply]
A few people mentioned this before. Removed now--DieBuche (talk) 16:01, 29 October 2010 (UTC)[reply]
Ah yes thanks, my cache had not gotI thought I remembered that it had been mentioned, but I could not find it, so I wasn't sure--Zolo (talk) 20:15, 29 October 2010 (UTC)[reply]

{{Edit request}} The table doesn't collapse when clicking text links in the header, but it does collapse when clicking linked images (since the target is then the image, not the link). For an example, see the Wikidata link in the header of Creator:Edvard Munch. This is confusing, and could be fixed by applying the following diff (updated). – Danmichaelo (δ) 13:20, 5 January 2013 (UTC)[reply]

This took quite a while. Sorry for this. We are suffering from staff shortages in the JS-area. -- Rillke(q?) 14:44, 27 June 2013 (UTC)[reply]

Fix hook handler[edit]

{{Editprotected}}

(I also moved the event handlers out of the hook handler, so they are not recreated on each page preview, and removed the :first-child compatibility fix, as no supported browser lacks it.) —Tacsipacsi (talk) 20:06, 20 June 2019 (UTC)[reply]

✓ Done Awesome! Thank you! But anyway, is this Gadget not deprecated? -- User: Perhelion 08:47, 6 August 2019 (UTC)[reply]
This Gadget is definitely deprecated. Also the documentation is very poor, the extra table-class is fully missing too. -- User: Perhelion 11:42, 6 August 2019 (UTC)[reply]