Close Dashboard Sidebar Automatically On Custom Single Page View

Permalink
I want to build a dashboard single page that does not have the side menu open by default. I'd like to close it so I can use more screen space for my single page idea. Of course it should still be available to open by clicking the dashboard button, but is there anyway to close it for the sake of a special dashboard single page that needs more screen space?

ob7dev
 
ob7dev replied on at Permalink Reply
ob7dev
Never mind, I just realized you can close the dashboard sidebar from a dashboard single page by clicking the dashboard button. I thought the sidebar was stuck open and couldn't be closed at all.

So new question, how to have my single page view initiate the sidebar to close automatically?
ob7dev replied on at Permalink Best Answer Reply
ob7dev
Gosh, do I always have to be the person to answer my own questions!!!

Just kidding thats how I get smarter.

So I wanted to close the dashboard sidebar automatically whenever the user navigates to my single page in the dashboard.

The code that runs the open and close event of the dashboard side panel is found in the dashboard theme footer.php:
$(function() {
        $('a[data-launch-panel=dashboard]').on('click', function() {
            setTimeout(function() {
                // needs a moment
                var panel = ConcretePanelManager.getByIdentifier('dashboard');
                if (panel.isOpen) {
                    $.cookie('dashboardPanelStatus', 'open', {path: '<?php echo DIR_REL?>/'});
                } else {
                    $.cookie('dashboardPanelStatus', 'closed', {path: '<?php echo DIR_REL?>/' });
                }
            }, 500);
        });
    });
Anytime you click the button in the very top right for opening and closing the sidebar, the above code gets executed.

jQuery has a cool function that will execute an event from code instead of it actually happening, so I can execute the dashboard button being clicked from jQuery whenever my single page is opened:
$(function() {
    $('a[data-launch-panel=dashboard]').triggerHandler('click');
});


And thats it, I've got that code registered as an asset on my single page view, and it causes the dashboard side bar to close upon visiting my single page!