The plugin is available from Atlassian Plugin Repository. Alternatively grab the jar referenced above and install manually via Administration Console/Plugins.
The plugin has no external dependencies.
Usage
Once you have installed the extension you can apply it to the main decorator of any space that uses default Confluence theme.
To include the CSS Switcher JavaScript library use the following in the HTML head section of the Velocity decorator templates.
This will instruct Confluence to render links to all files with content type "text/css" attached to the home page of the current space.
Alternatively, specify the page where to look for files explictly.
$cssSwitchHelper.renderHtmlHeaders($sitemeshPage.getProperty("page.spacekey"), "My Page")
If you have a preferred alternate style sheet that you want to be enabled by default use
$cssSwitchHelper.renderHtmlHeadersPreferred($sitemeshPage.getProperty("page.spacekey"),
"My Page", "Blue Style")
References to attached text/css files with no comments will be rendered as persistent style sheets.
Use css-switch-link macro to render links to select the alternate style-sheet.
Besides all standard HTML parameters the macro supports optional parameters "styleSheet" to reference the one that should be activated on click and "page" to create a link to a Confluence page.
{css-switch-link:Blue Style|id=rswitch|class=switchlink|style=text-decoration:none
|title=Click here to switch to red text style and go futher.
|page=TEST:Further}Switch to red text now and go further.{css-switch-link}
results in:
<a href="/display/TEST/Further"
title="Click here to switch to red text style and go futher."
style="text-decoration:none"
class="switchlink"
id="rswitch"
onclick="setActiveStyleSheet('Blue Style')">
Switch to red text now and go further.</a>
An empty value for styleSheet parameter or no parameter specified will result in a switch to preferred style sheet or the first alternate if no preferred exists in the document
Once the user selects the style sheet the choice is stored into a cookie and applied on the next visit to this or subsequent pages. If this is not desired - enable CSS Switcher JavaScript No Cookies flavor of CSS Switcher JavaScript in Adminstration/Plugins instead of the default one.
Errara
get access to sitemeshpage implicitly from Velocity helper
make it possible to apply to an existing 3rd party theme