User:Chlod/Templates/toggle/doc
| This is a documentation subpage for User:Chlod/Templates/toggle. It may contain usage information, categories and other content that is not part of the original user template page. |
Example
Usage
This template allows you to create toggle-able elements with the power of CSS and TemplateStyles.
To use it, place a {{User:Chlod/Templates/toggletop}} template at the top of the content, and a {{User:Chlod/Templates/togglebot}} at the bottom. You can also wrap all contents as a parameter of {{User:Chlod/Templates/toggle}}, but this will pollute syntax highlighting for your wikitext editor.
After that, you'll need to set up styling. Create a CSS file at the TemplateStyles sandbox and then move it into your userspace after creation. Add the following lines of code to it, and then replace the comment with anything you want the contents to do when the toggle is activated.
.mw-collapsed + .ch-toggletarget {
/* Your custom CSS statements here. */
}
You may alternatively use this button in order to quickly create this file. Make sure to move it to your userspace after creation. The filename must end with .css!
After creating the file, use the stylesheet on your page with the following wikitext:
<templatestyles src="<!-- Location of your stylesheet file here -->" />
When finished, any content between the top and bottom templates (or all content passed as part of {{User:Chlod/Templates/toggle}}) will be styled with the content you added in the CSS file.
Mechanism
This template works by fooling the sitewide JavaScript creating a collapsible "table" which is then picked up by the sitewide JavaScript and made interactive. This allows styling of the table depending on whether or not it is collapsed or not. The catch is that there is nothing else on the table except the toggle, which can then lead to interesting styling.
The + selector in CSS is responsible for most of the movie magic. It picks up the collapsed (or not) table, and styles the succeeding element based on that state. In other words, for the selector .mw-collapsed + .ch-toggletarget, what actually gets styled is the element with the ch-toggletarget class, not the toggle button. As such, it implements a client-side toggle whose actions can be controlled with CSS.
Customization
You can change the text of the toggle when enabled/disabled using CSS as well. The following will change the text to "disabled" when disabled and "enabled" when enabled.
.ch-toggle .mw-collapsible-toggle-default::before {
content: '[disabled]' !important;
}
.ch-toggle.mw-collapsed .mw-collapsible-toggle-default::before {
content: '[enabled]' !important;
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.