Jump to content

User:Zigger/autosection/doc

From Wikipedia, the free encyclopedia

Autosections allow interactive hiding and showing of entire sections, without breaking the header structure. They can optionally be embedded within another autosection for a cascading effect, without regard to header level. The template can be used anywhere on a line, unlike "==". Autosections are containers for their contents, unlike traditional wiki sections which currently require additional hackery for interaction and stylisation. Both types can be used within the same page.

Autosections currently have three flaws compared to wiki sections: anchors don't work when parents are collapsed, they have no section-editing features, and they are less convenient to create (although easier to customise).

CSS styles can be applied to the entire autosection as one or more of the parameters, and most of these styles settings are inherited automatically by any embedded autosections, with others available through the use of the heir parameter (or explicit setting via other styling parameters).

Usage

Simple example:
{{User:Zigger/autosection| Hello world }} Hi! {{User:Zigger/autosection}}

Parameters

title
The title of the section. The default value is "Missing section title parameter (more...)". This parameter name can be omitted if the title is supplied as the first parameter. (If the title value starts with an "=" character (e.g. "title==Hello world="), this will be treated by mediawiki as increasing the "depth". assuming that there is a matching ending "=" character.) This parameter can also be named as 1. e.g. {{User:Zigger/autosection| depth=2 |1 = Hello world }}
depth
Section indentation depth, i.e. HTML heading level less two. The default value is 0. Values other than -1, 0, 1, 2 or 3 will result in a value of 4. Outer sections can use the default or specify 0. The next inner section level must specify 1, and so on. The resulting HTML header level will be a number two greater than depth. (A value of -1, resulting in HTML heading level 1, is reserved by mediawiki for the page title, and should be avoided.) Section embedding is not controlled by depth, but can be easily done by placement of the start and end templates (see the full examples).
state
Whether the section is shown initially. The default is that it is shown, which also ensures that printing & other non-interactive renderings of the initial view are complete (strongly recommended for pages in the article namespace, despite the popularity of "spoilers"). Use "state=collapsed" if you want the section to be hidden initially. Using "state=autocollapse" initially collapses the autosection only if there are two or more autosections (or collapsible tables such as navboxes) on the same page. Other values can produce various results (as state is used in the class list for the "section table").
anchorN
In addition to the anchor for the section title, which is always set automatically, this parameter allows additional anchors to be set, e.g.
{{User:Zigger/autosection| Hello world | anchor1 = Hello | anchor2 = World }}
Test autosection anchors on this page: title=Limitations (due to the template design), anchor1=Limitations.
See also: Template:Anchor.
width
The minimum percentage width of the section (within the parent container). The default is "100". A useful value for a messagebox-type size is "80". Using "width=50" is equivalent to using "style=width:50%", but width is more convenient. Use style to set width in other units, e.g. "style=width:50em", or to use the "min-width:" and "max-width" variations. Please note that the width is more of a guideline than an absolute, with browsers expected to follow various CSS computations.
color
The background color, which is a CSS parameter. The default is inherited from the "parent container". Examples of valid CSS values are "blue", "rgb(50%,50%,50%)" and "#aaa;". Using "color=red" is equivalent to using "style=background-color:red", but color is more convenient.
style
Any extra CSS style setting or combination thereof. Please note that "style=color:green" sets the default text color of the section, whereas "color=green" is equivalent to "style=background-color:green" and sets the background color. Tip: in CSS, multiple attribute:value tuples are separated by ";", e.g. "style=margin-top:3em;font-family:Cursive".
heir
This allows the autosection to inherit the particular group of style settings (border, margin, padding) which are otherwise reset to standard values by default. Use "heir=1" to instead inherit these particular style settings from the parent container. Please note that all other style settings are inherited regardless, except for those explicitly overriden via the color and style parameters.



Limitations (due to the template design)

  • TOC / anchor navigation to embedded sub-sections with collapsed parents does nothing at all. Most users would probably expect to end up at the parent at least. And it's not obvious how to find the top-most collapsed parent in order to expand it.
  • By default, the Table of Contents will appear within the first section's box. It can be moved elsewhere using the __TOC__ magic word, or can be disabled by using the __NOTOC__ magic word.
  • This template is dependent on the site software (MediaWiki), which could be changed at any time by a developer / site operator.
    • Autosections lack section-edit links, and editing the preceding standard section includes the following autosections. (Edit links were shown at Special:ExpandTemplates in early November, but not in actual transclusions.) (See Help:Section — edit links within parser functions may lack the correct numbering anyway. But from some pre-processor discussion, it doesn't seem impossible, as long as a parameter is used. Could start experimenting with layout, or patch mediawiki.)
  • This template is dependent on the site-level style-sheets and scripts, which could be changed at any time by an administrator edit.
    • Two problems with the expand/collapse mechanism itself have been seen: inconsistent width shrinkage on collapse, with the first "show" action just resulting in width-correction. (Seen with both outer and embedded autosections. Also seen with other templates, so probably not bug of this one.) Browsers' CSS width computations often seem to exclude the section number (if enabled in preferences), causing the title to wrap. This is often seen with "style=width:auto".
    • Collapsed sections do not print, but I consider this a feature as it allows one to choose which sections print. (Printing includes show links which indicate that the section is collapsed, but it does seem pointless to print hide links on visible sections.)
    • The [show] tag should be emphasised compared to the [hide] tag.
  • The result is only functional for browsers with javascript enabled. Otherwise the sections are always expanded.

See also