Problem adding classes and removing before and after ajaxify

NodeBB Development
  • I'm having problems trying to remove this class on a route after a username. The class is suppose to only be called on this route and no route after. domain.tld/user/username instead, it stays the same ondomain.tld/user/username/edit

    Here's the script I have so far;

    $(window).on('action:ajaxify.end', function(ev, data) {
       if ( data.url === '' || data.url.indexOf('user') !== -1)
           $(".forum-logo").addClass("forum-logo-alt"),
    });
    $(window).on('action:ajaxify.start', function(ev, data) {
       if ( data.url !== '' && data.url.indexOf('user') === -1)
           $(".forum-logo").removeClass("forum-logo-alt"),
    });
    

    Any ideas?

  • If I did not misunderstand your issue, I think using regexp here you can narrow the match down to exactly the data.url that you want. Something like this:

            if (/^user\/[a-zA-Z0-9]+$/.test(data.url))  {
                $(".forum-logo").addClass("forum-logo-alt");
            }
    
  • Where I was trying to get at was whenever anyone visited a profile, the logo would change (addClass) and will change back to normal (removeClass) when they browse off that page. I will try your method to see if that works.

    Edit: That actually fixed the problem. Thanks a bunch! 👍

  • Glad you figured it out with @arasbm's help @trevor, sorry I had to go to bed 😄


Suggested Topics