Closed (fixed)
Project:
Style Switcher
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Jul 2009 at 09:04 UTC
Updated:
27 Apr 2014 at 15:20 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
alanburke commentedNo plans to change this - Any suggestions on how it might work?
Comment #2
mattconcentric commentedI've done this kind of thing before by adding a menu callback that sets a cookie (and redirects to referer). The links in the switcher would just need to point to this, passing a style to switch to.
I'm not set up for submitting patches, but you are welcome to have a look at the code if you want.
Comment #3
alanburke commentedSounds good
just post the code - I'll have a look.
It sounds like the menu callbacks should be there by default, but then we could use js to to hijack the links
Comment #4
mattconcentric commentedYes, something like that - the links would work as normal links to the callback, unless Js is enabled, in which case an event.preventDefault() somewhere along the line would stop the navigation.
So, something like this then. I expect this violates various style guidelines, but it works OK. Anything that changes state should strictly involve a POST, but that would mean too much of a change to the existing block output.
Helper function _styleswitcher_title_safe() just generates a slug from the title so it's safe to use in a URL:
The menu would be something like this:
And the switch itself:
This just loops back through the styles from the theme to find a matching slug, then sets the cookie to the title that is used elsewhere. Really, it could do with more checks to ensure you aren't trying to redirect to somewhere invalid, and maybe default to drupal_goto(front) if it can't match the style.
We can then change the block display code to something like this:
Writing out the active stylesheet like this could cause problems depending on the ordering, as it may appear before the standard stylesheets. I tend to make rules !important in accessibility stylesheets though, so that's not so much of an issue for me.
I've not really thought about any potential security issues or tested this exhaustively, so include at your own risk!
Comment #5
pingwin4egHello!
I'm working on 2nd branch of the module which will introduce new features and bug fixes.
So here is the patch that implements JavaScript disabled functionality of style switching. But it can be only applied after another patch (which covers a lot of fixes for proper workflow) - #1966982: Load active (selected) CSS on page init. / Use another technique for style switching.
Hope to hear your feedback on it.
Comment #7
pingwin4egCommitted to 7.x-2.x. Please update.