Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRO] and standard - Navbar works only with a full page refresh #21

Open
fabOnReact opened this issue May 16, 2017 · 2 comments
Open

[PRO] and standard - Navbar works only with a full page refresh #21

fabOnReact opened this issue May 16, 2017 · 2 comments

Comments

@fabOnReact
Copy link

Hello,

I have an app with Ruby on Rails Turbolinks 5 so I am also trying to fix this out and we can help each other.

If you check your pro version navbar, it will not work well if you try to click more then once the navbar links, this is because that version is maybe done with angular and is not doing a full page refresh..

http://demos.creative-tim.com/light-bootstrap-dashboard-pro/examples/charts.html#

While the standard one works allways, because you allways trigger with those links a full page refresh.

http://demos.creative-tim.com/light-bootstrap-dashboard/icons

Turbolinks 5, similar to angular and other JS Frameworks, will not trigger a full page refresh after that I click the links.

The solution is in the following code, from light-bootstrap-dashboard.js row 107-119

lbd.misc.navbar_menu_visible will be 1 when visible and the removeClass('nav-open'); will hide the navbar, while addClass('nav-open') will show it. I will try to trigger this on page refresh somehow.

Thanks a lot for the amazing Layout
Trying to help you
Best Regards
Fabrizio Bertoglio

$toggle.click(function (){    
                if(lbd.misc.navbar_menu_visible == 1) {
                    $('html').removeClass('nav-open'); 
                    lbd.misc.navbar_menu_visible = 0;
                    $('#bodyClick').remove();
                     setTimeout(function(){
                        $toggle.removeClass('toggled');
                     }, 400);
                
                } else {
                    setTimeout(function(){
                        $toggle.addClass('toggled');
                    }, 430);                    
@fabOnReact
Copy link
Author

fabOnReact commented May 16, 2017

I solved like this the issue with the following code. I am using Rails 5 with Turbolinks 5.
I included this code in my js file script.js

var ready = function() {
    if ($(window).width() <= 991) { 
        $('.navbarLinks').click(function(){
            $('html').removeClass('nav-open');
            lbd.misc.navbar_menu_visible = 0;
            $('#bodyClick').remove();
             setTimeout(function(){
                $toggle.removeClass('toggled');
             }, 400);
        });

    }    
}

/*$(document).ready(ready);*/
$(document).on('turbolinks:load', ready);

@alexandru-paduraru
Copy link
Member

@fabriziobertoglio1987 thank you for pointing out and also including the solution. Yes, you're right, Rails and turbolinks are not doing a full page reload and the document.ready is not triggered on each page change. Another option would be to place the .navbarLinks in a function that is inside a "document on click" triggered. That makes sure it will work no matter how many times you add/remove the .navbarLinks button. More details here: http://stackoverflow.com/questions/14879168/document-onclick-id-function-vs-id-onclick-function

But your solution is better because you have more elements that are triggered after they are loaded, we used the same technique for creative-tim.com too.

Best,
Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants