Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm developing a WordPress theme that allows users to toggle the visibility of the sidebars using Javascript in the same way that wikis allow users to show or hide a table of contents.

When a user clicks the link to hide a sidebar I have a toggle() javascript toggle function that sets the visibility of the sidebar to "none" and also sets a document cookie so that the next time the users visits that page, the sidebar will remember the last toggle state.

I have another javascript function setToggleFromCookie() that gets the cookie and sets the visibility based on that cookie. This all works except:

If a sidebar is hidden (i.e. visibility of the sidebar div = "none" and the document cookie hidesidebar = 1), when the page is loaded, the sidebar appears briefly before the javascript overrides the visibility = "block" with visibility = "none."

I have put setToggleFromCookie() in jQuery(document).ready(function(), but the page still seems to load and display the sidebar BEFORE setToggleFromCookie() jumps in to hide it...

share|improve this question
    
Is this theme of yours, or the code you've used to make what you described possible, available for download anywhere? It sounds very interesting, I'd love to have a look at it. –  Erlend Nov 25 '12 at 8:45
    
Yes, this theme is available for download, see: github.com/marpa/translucence –  marpa Nov 26 '12 at 16:28
    
That's exactly what I was hoping for, thanks a lot! –  Erlend Nov 26 '12 at 20:35
add comment

1 Answer

up vote 4 down vote accepted

While annoying, your plugin is functioning properly. The page completely renders itself first, showing the sidebar, and then the JavaScript code activates to hide the sidebar.

The fix for this is to have your PHP code check/grab the user's cookie and set the display's sidebar status accordingly. That way when the page renders it will be set to none initially, and then any future image toggles can hide/show the sidebar dynamically.

When the page is loaded again for whatever reason, the same PHP loading code will run again, and set the initial state of the sidebar accordingly, without any need to "follow up" after the initial page load to show/hide the sidebar.

Hopefully this makes sense. If you need some specifics, you might try updating your question with the code involved.

share|improve this answer
    
using php to check the cookie... of course, don't know why I didn't think of that. Thanks so much! –  marpa Apr 3 '11 at 0:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.