I think it would help in theming if, after a style has been selected and the user has navigated to a new page, the subsequent page gets the appropriate class added to the BODY tag.
"Appropriate class" here refers to the classes that are added to / removed from the BODY tag by jQuery while dynamically switching between the styles - 'pagestyle_standard', 'pagestyle_black_white', etc. This would mean that themers could override styles - eg 'body.pagestyle_black_white' - in their theme CSS instead of manually editing the module's included CSS files.
This could be done either using jQuery (at the point of $(document).ready();), or by adding the class to the global $body_classes variable during the loading process. In order to extend support for non-JavaScript browsers I think the latter method is preferable.
After all that blather you will be pleased to know that the actual process of doing so is incredibly easy - just make use of the template preprocessing hooks for the 'page' event, just declare a template_preprocess_page() function and mod the 'body_classes' element of the passed-in argument:
/**
*Override or insert variables into the page template.
*
* @param &$variables
* Contains the following arguments: $content, $show_blocks
*
* @see template_preprocess_page
*/
function pagestyle_preprocess_page(&$variables) {
if ($stylor = pagestyle_get_current()) {
$variables['body_classes'] .= ' pagestyle_'. $stylor;
}
}
That's worked for me at a theme level and I can't see any reason why it wouldn't in a module.
Comments
Comment #1
CZ commentedCan not follow you. Please tell me more information or attach a patch.
Comment #2
kingandyWhen switching between styles, the jQuery code adds a class to the BODY tag (eg 'pagestyle_standard' or 'pagestyle_black_white').
The next time a page loads, the BODY tag is not assigned this class.
It would be useful if the BODY tag loaded with the appropriate class assigned to it.
Comment #3
mshepherd commentedThis snippet is really useful.
I want to add additional styles to each page that is processed by the pagestyle module (applies for textsize module also). So that once a page style has been selected each page will assume my additional styles.
Example: I'd rather have blocks outlined in black on the pagestyle_black_white style. When the user first selects the page style, this module drops a class into the html body tag
<body class="pagestyle_black_white">.... So I can easily write custom styles in my theme which then supplement the styles provided by the module.Example from my theme:
However, once a visitor navigates to a new page, the pagestyle_black_white class is no longer in the body tag and so the custom styles from my theme don't load.
This snippet fixes this. Very useful. Thanks for sharing!
Comment #4
mshepherd commentedWith further testing, I found this actually made the styles switch improperly, sometimes switching back and forth apparently randomly. By moving the function into the theme's preprocess_page function, I found it worked as it should.
Comment #5
mrfelton commentedsubscribing
Comment #6
mrfelton commentedI don't know why, but the pagestyle module includes the following inline styles at the top of the pages:
I have no idea why it does that, but I found that with either of the above snippets, the font weights were getting reset to normal all over the place all the time. I used the following to ensure that the css class was only applied to the body for styles other than the standard one.
Comment #7
CZ commentedThe JavaScript code in the head is required for jQuery (JavasScript) style switcher, because the module use the current style from the external linked CSS. This allows a style switcher in the browser, see first image [1]. Not the easiest way, I know. Add current style to $body_classes is possible and approved.
[1] http://www.zwahlendesign.ch/downloads/pagestyle/images/pagestyle.png
Comment #8
CZ commentedThanks! Added.