Hey all,
I've created a jQuery toggle to show/hide the sidebar based on user toggle. The sidebar has been wrapped in a div element , that I'm hiding/displaying using .toggle().
The status of this is being saved for each user using the localStorage saving method, so on each page refresh the sidebar shouldn't suddenly re-appear.
The problem I'm having is that for a user who wants to hide the sidebar, the sidebar HTML is loading quicker than the jQuery, resulting in the sidebar briefly appearing and then disappearing in a glitchy/annoying way.
I tried modifying this so that the code in the <head> section changed the css of the div to be display:none; but this had the same problem - it was taking place after the HTML for the sidebar loaded, so it suddenly disappeared in a glitchy way.
Is there any way I can force the CSS change to happen before the HTML loads? Alternatively, can I update a custom setting using JS/jQuery? Any examples?
Thanks for any help!
In <head> section of PAGE_CONTAINER:
In <body> section - is requested only if sidebar is enabled:
I've created a jQuery toggle to show/hide the sidebar based on user toggle. The sidebar has been wrapped in a div element , that I'm hiding/displaying using .toggle().
The status of this is being saved for each user using the localStorage saving method, so on each page refresh the sidebar shouldn't suddenly re-appear.
The problem I'm having is that for a user who wants to hide the sidebar, the sidebar HTML is loading quicker than the jQuery, resulting in the sidebar briefly appearing and then disappearing in a glitchy/annoying way.
I tried modifying this so that the code in the <head> section changed the css of the div to be display:none; but this had the same problem - it was taking place after the HTML for the sidebar loaded, so it suddenly disappeared in a glitchy way.
Is there any way I can force the CSS change to happen before the HTML loads? Alternatively, can I update a custom setting using JS/jQuery? Any examples?
Thanks for any help!
In <head> section of PAGE_CONTAINER:
JavaScript:
<xf:js>$(document).ready(function(){
var block = localStorage.getItem('sidebar');
if (block == 'true') {
$('#sidebar_toggle_test_id').hide();
}
});
</xf:js>
In <body> section - is requested only if sidebar is enabled:
Code:
<xf:js>$(document).ready(function(){
$("#toggle_sidebar").click(function(){
$("#sidebar_toggle_test_id").toggle('slow',callbackFn());
});
function callbackFn(){
localStorage.setItem('sidebar', $("#sidebar_toggle_test_id").is(":visible"));
}
});
</xf:js>