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

Font-Awesome 5 #155

Open
dgmarques opened this issue Jan 9, 2018 · 8 comments
Open

Font-Awesome 5 #155

dgmarques opened this issue Jan 9, 2018 · 8 comments

Comments

@dgmarques
Copy link

Hi guys,

I'm using metismenu 2.7.1 in sb-admin2 template.

I'm having a lot of problems because i'm using font-awesome 5. Is it possible to update the Metis Menu with font-awesome 5? Would greatly appreciate it.

Thanks for your time!!

@dgmarques dgmarques reopened this Jan 19, 2018
@onokumus onokumus reopened this Jan 19, 2018
@onokumus
Copy link
Owner

Hi @dgmarques
I'm sorry for the late reply. Using FA-5 with metisMenu should not be a problem. What kind of problem do you have?

@dgmarques
Copy link
Author

It must have been a problem with SB-Admin2; it does not use MetisMenus' css classes, instead it has it's own, something about this whole thing was not working, pseudo-elements where not working properly (they would not change from 'angle-down' to 'angle-left' nor the other way around.

What I did to get around this was not use pseudo-elements, but instead use FA-5 normally with SVG elements; for MetisMenu to work like this I edited it's javascript to instead of changing classes, it would find the SVG and change it's data-icon attribute according to the state ('.active` or not).

@messyhair66
Copy link

Same issue + using SBAdmin 2. I can get icons in the menu to work without pseudo elements, not with.

@messyhair66
Copy link

Someone much smarter than me can probably come up with a more elegant solution, but here's something... I didn't want to edit metisMenu directly and updating the CSS for sbadmin had no effect. I added this JS instead to handle the show and collapse events:

            $('ul.nav-second-level').each(function() {
                $(this).on('show.bs.collapse', function() {
                    $(this).siblings('a').children('svg[data-icon=angle-left]').each(function(index, value) {
                        $(value).removeClass('fa-angle-left').addClass('fa-angle-down');
                    });
                }).on('hide.bs.collapse', function() {
                    $(this).siblings('a').children('svg[data-icon=angle-down]').each(function(index, value) {
                        $(value).removeClass('fa-angle-down').addClass('fa-angle-left');
                    });
                });
            });

And this is probably more appropriate in the sbAdmin repo, but this was the only Google result; so, cheers.

@jamesflynn
Copy link

@messyhair66 Can you share explicitly how to implement your solution? Where do you add that code? I'm having the same problem.

@messyhair66
Copy link

I added it in the footer after including all of the regular dependencies inside of my document.ready function.

<script type="text/javascript">
           (function($) {
               $('ul.nav-second-level').each(function() {
                   $(this).on('show.bs.collapse', function() {
                       $(this).siblings('a').children('svg[data-icon=angle-left]').each(function(index, value) {
                           $(value).removeClass('fa-angle-left').addClass('fa-angle-down');
                       });
                   }).on('hide.bs.collapse', function() {
                       $(this).siblings('a').children('svg[data-icon=angle-down]').each(function(index, value) {
                           $(value).removeClass('fa-angle-down').addClass('fa-angle-left');
                       });
                   });
               });
           })(jQuery);
       </script>

I also updated the angle down in the menu to be:
<span class="fas fa-angle-left pull-right"></span>

@ItsDanielHarris
Copy link

@messyhair66 The script doesn't work with third-level menus.

@AlexM1dn1ght
Copy link

The code above did not work for me because metisMenu uses its own events for showing and hiding the menu and was eating the bootstrap events, at least that is what I understood from my debug session. I ended up using the following code (tested with metisMenu 2.7.7 and FontAwesome 5.0.13 SVG). This should work with any level of menu.

$('#yourMenuSelectorId').metisMenu().on('show.metisMenu', function (e) { $(e.target).siblings('a').children('svg[data-icon=angle-left]').removeClass('fa-angle-left').addClass('fa-angle-down'); }).on('hide.metisMenu', function (e) { $(e.target).siblings('a').children('svg[data-icon=angle-down]').removeClass('fa-angle-down').addClass('fa-angle-left'); });

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

6 participants