Skip to content

Recent Cards - fix for slider on mobile not working

Customisation
23 3 8.6k 1
  • If you’ve downloaded the plugin nodebb-plugin-recent-cards and are struggling with getting the slider to work on a mobile device in the way that it’s supposed to (swipe), there is a (relatively) simple fix.

    First, add the below to ACP -> Appearance -> Custom Header

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://cdn.jsdelivr.net/bxslider/4.2.12/jquery.bxslider.min.js"></script>
    

    Then, add the below JS snippet to your ACP -> Appearance -> Custom JS

    $(window).on('action:ajaxify.end', function(data) {
        $('.carousel-mode').bxSlider();
    });
    

    This provides the real slider functionality you are looking for 🙂 Admittedly, it’s pulling in another library, but it’s tiny and unlikely to have any real impact (unless the source is offline of course).

    And, with a bit of imagination, plus assistance from the documentation available from
    https://bxslider.com/options/

    It’s possible to create (in conjunction with https://sudonix.com/topic/256/recent-cards-plugin-customization/2) this effect (automatic scrolling through categories) using the below code

    $(window).on('action:ajaxify.end', function(data) {
        $('.carousel-mode').bxSlider({
            auto: true,
            autoControls: true,
            stopAutoOnClick: true,
            pager: false
        });
    });
    

    slider.gif

    Enjoy

  • phenomlabundefined phenomlab marked this topic as a regular topic on
  • Small caveat here in the sense that links in the slider no longer work. The bug is reported here
    https://github.com/stevenwanderski/bxslider-4/issues/1246#issuecomment

    The suggested “fix” is to use touchEnabled: false in the config, but that kind of defeats the purpose of the slider in my view on a mobile device.

  • And so, it appears that the bug only impacts Google Chrome, so we’ll have to test the browser first to ensure that if it is indeed Chrome, we will need to disable the touchEnabled setting. This code below will do exactly that. If anything other than Chrome is detected, we set touchEnabled: true (which is actually the default anyway)

    window.addEventListener("load", () => {
        // CHROME
        if (navigator.userAgent.indexOf("Chrome") != -1) {
            console.log("Google Chrome");
            $(window).on('action:ajaxify.end', function(data) {
                $('.carousel-mode').bxSlider({
                    auto: true,
                    autoControls: true,
                    stopAutoOnClick: true,
                    pager: false,
                    keyboardEnabled: true,
                    touchEnabled: false
                });
            });
        } else {
            console.log("Others");
            $(window).on('action:ajaxify.end', function(data) {
                $('.carousel-mode').bxSlider({
                    auto: true,
                    autoControls: true,
                    stopAutoOnClick: true,
                    pager: false,
                    keyboardEnabled: true,
                    touchEnabled: true
                });
            });
        }
    });
    
  • And so, it appears that the bug only impacts Google Chrome, so we’ll have to test the browser first to ensure that if it is indeed Chrome, we will need to disable the touchEnabled setting. This code below will do exactly that. If anything other than Chrome is detected, we set touchEnabled: true (which is actually the default anyway)

    window.addEventListener("load", () => {
        // CHROME
        if (navigator.userAgent.indexOf("Chrome") != -1) {
            console.log("Google Chrome");
            $(window).on('action:ajaxify.end', function(data) {
                $('.carousel-mode').bxSlider({
                    auto: true,
                    autoControls: true,
                    stopAutoOnClick: true,
                    pager: false,
                    keyboardEnabled: true,
                    touchEnabled: false
                });
            });
        } else {
            console.log("Others");
            $(window).on('action:ajaxify.end', function(data) {
                $('.carousel-mode').bxSlider({
                    auto: true,
                    autoControls: true,
                    stopAutoOnClick: true,
                    pager: false,
                    keyboardEnabled: true,
                    touchEnabled: true
                });
            });
        }
    });
    

    @phenomlab when I use the codes in the top two black boxes, in firefox it gives this:

    Screen Shot 2022-04-06 at 11.42.54 AM.png

    one card is taking the whole space of 4 cards…

  • @phenomlab when I use the codes in the top two black boxes, in firefox it gives this:

    Screen Shot 2022-04-06 at 11.42.54 AM.png

    one card is taking the whole space of 4 cards…

    @crazycells Yes, because you have hard coded relative widths set - did you modify anything ?

    8f23883f-6a66-4ad2-8841-2826f459d409-image.png

    The default width from the plugin is around 290px

  • @crazycells Yes, because you have hard coded relative widths set - did you modify anything ?

    8f23883f-6a66-4ad2-8841-2826f459d409-image.png

    The default width from the plugin is around 290px

    @phenomlab let me check the settings…

  • @phenomlab let me check the settings…

    @crazycells If you can’t find it, this will resolve it

    li.col-md-3.col-sm-6.col-xs-12.recent-card-container {
        width: 290px !important;
    }
    
  • @crazycells If you can’t find it, this will resolve it

    li.col-md-3.col-sm-6.col-xs-12.recent-card-container {
        width: 290px !important;
    }
    

    @phenomlab said in Recent Cards - fix for slider on mobile not working:

    @crazycells If you can’t find it, this will resolve it

    li.col-md-3.col-sm-6.col-xs-12.recent-card-container {
        width: 290px !important;
    }
    

    I could not find any CSS codes related to the width of these cards, but this code solved the problem. Thanks.

    Additionally, why the pages are shown as points under these cards? We do not normally have that setting on, I checked the settings and restarted the forum, but they did not go away.

  • @phenomlab said in Recent Cards - fix for slider on mobile not working:

    @crazycells If you can’t find it, this will resolve it

    li.col-md-3.col-sm-6.col-xs-12.recent-card-container {
        width: 290px !important;
    }
    

    I could not find any CSS codes related to the width of these cards, but this code solved the problem. Thanks.

    Additionally, why the pages are shown as points under these cards? We do not normally have that setting on, I checked the settings and restarted the forum, but they did not go away.

    @crazycells Because you are overriding the plugin bxslider library with one from an external source - see below

    $(window).on('action:ajaxify.end', function(data) {
        $('.carousel-mode').bxSlider({
            auto: true,
            autoControls: true,
            stopAutoOnClick: true,
            pager: false
        });
    });
    

    Essentially, you’ll need to use pager: false as shown above to disable it

  • @crazycells Because you are overriding the plugin bxslider library with one from an external source - see below

    $(window).on('action:ajaxify.end', function(data) {
        $('.carousel-mode').bxSlider({
            auto: true,
            autoControls: true,
            stopAutoOnClick: true,
            pager: false
        });
    });
    

    Essentially, you’ll need to use pager: false as shown above to disable it

    @phenomlab to stop automatic movement, I should do:

    auto: false,
    

    right?

  • @phenomlab to stop automatic movement, I should do:

    auto: false,
    

    right?

    @crazycells Yes, or just remove it

    0ef15f46-5d7d-4527-9ffb-f7c47ac72757-image.png

  • @crazycells Yes, or just remove it

    0ef15f46-5d7d-4527-9ffb-f7c47ac72757-image.png

    @phenomlab yeap, I see it now. Thank you very much. 🙏

    In Firefox (desktop), and in safari (mobile) I do not have any problem and it works beautifully.

  • @phenomlab yeap, I see it now. Thank you very much. 🙏

    In Firefox (desktop), and in safari (mobile) I do not have any problem and it works beautifully.

    @crazycells Great !!

  • Previously, baris said: “For me ajaxifying between pages was breaking when I activated touchEnabled.”

    Is this change causing the same problem?

    PS. I do not know what ajaxifying is, I checked the definition but I did not really understand it. 🤣

  • Previously, baris said: “For me ajaxifying between pages was breaking when I activated touchEnabled.”

    Is this change causing the same problem?

    PS. I do not know what ajaxifying is, I checked the definition but I did not really understand it. 🤣

    @crazycells No, because we call the function again using

    $(window).on('action:ajaxify.end', function(data) {
    
  • @crazycells No, because we call the function again using

    $(window).on('action:ajaxify.end', function(data) {
    

    @phenomlab great! Good to hear that (although I do not understand fully)…

    Thanks a lot 😄

  • @phenomlab yeap, I see it now. Thank you very much. 🙏

    In Firefox (desktop), and in safari (mobile) I do not have any problem and it works beautifully.

    @crazycells said in Recent Cards - fix for slider on mobile not working:

    In Firefox (desktop), and in safari (mobile) I do not have any problem and it works beautifully.

    Are you using the code block from here ?
    https://sudonix.com/topic/257/recent-cards-fix-for-slider-on-mobile-not-working/3

  • phenomlabundefined phenomlab referenced this topic on
  • Previously, baris said: “For me ajaxifying between pages was breaking when I activated touchEnabled.”

    Is this change causing the same problem?

    PS. I do not know what ajaxifying is, I checked the definition but I did not really understand it. 🤣

    @crazycells said in Recent Cards - fix for slider on mobile not working:

    PS. I do not know what ajaxifying is, I checked the definition but I did not really understand it.

    AJAX is “Asynchronous Javascript And XML (Extensible Markup Language)” and means that requests for data can be sent and received without having to reload the entire page. This strategy is commonplace in today’s internet world - particularly for Single Page Applications (known as SPA’s)

  • @crazycells said in Recent Cards - fix for slider on mobile not working:

    In Firefox (desktop), and in safari (mobile) I do not have any problem and it works beautifully.

    Are you using the code block from here ?
    https://sudonix.com/topic/257/recent-cards-fix-for-slider-on-mobile-not-working/3

    @phenomlab no, I made these changes:

    Custom Header:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://cdn.jsdelivr.net/bxslider/4.2.12/jquery.bxslider.min.js"></script>
    

    Custom JS

    $(window).on('action:ajaxify.end', function(data) {
        $('.carousel-mode').bxSlider({
            stopAutoOnClick: true,
            pager: false
        });
    });
    
  • @crazycells said in Recent Cards - fix for slider on mobile not working:

    PS. I do not know what ajaxifying is, I checked the definition but I did not really understand it.

    AJAX is “Asynchronous Javascript And XML (Extensible Markup Language)” and means that requests for data can be sent and received without having to reload the entire page. This strategy is commonplace in today’s internet world - particularly for Single Page Applications (known as SPA’s)

    @phenomlab I changed the code to this:

    window.addEventListener("load", () => {
        // CHROME
        if (navigator.userAgent.indexOf("Chrome") != -1) {
            console.log("Google Chrome");
            $(window).on('action:ajaxify.end', function(data) {
                $('.carousel-mode').bxSlider({
                    auto: true,
                    autoControls: true,
                    stopAutoOnClick: true,
                    pager: false,
                    keyboardEnabled: true,
                    touchEnabled: false
                });
            });
        } else {
            console.log("Others");
            $(window).on('action:ajaxify.end', function(data) {
                $('.carousel-mode').bxSlider({
                    auto: true,
                    autoControls: true,
                    stopAutoOnClick: true,
                    pager: false,
                    keyboardEnabled: true,
                    touchEnabled: true
                });
            });
        }
    });
    

    with “auto: false” edit…

    and it is still working with firefox and safari; but not with google chrome.


Related Topics
  • navigation menu panel on mobile

    Solved Customisation nodebb css
    8
    1
    7 Votes
    8 Posts
    2k Views
    @crazycells hmm. That’s odd. I haven’t made any changes from recollection but I could be wrong. I’ll need to check. EDIT - very strange. I honestly don’t recall adding the below CSS block to alter the bottom bar, but you’re right… .bottombar-nav { padding: 0px !important; } I’ve removed this so it reflects stock Harmony.
  • Whitespace fixes in Nodebb

    Solved Customisation nodebb
    18
    2
    7 Votes
    18 Posts
    5k Views
    @Panda Just circling back here with something of an update (which I think you’ll like). I’ve completely restructured the ranking system. There are now less ranks, with a higher point threshold to reach them. More importantly, if you reload the site, you’ll notice that the ranks are now icons. I also removed the “Author” badge, and made this a single icon, which (to me) looks much better.
  • How to fix size of photos & videos NodeBB

    Solved Customisation nodebb nodebb size
    7
    3 Votes
    7 Posts
    2k Views
    @crazycells pleasure. Using percentages makes much more sense in this case. It’s the same argument with px vs pt vs em with fonts, margins, padding, etc., in the sense that em is generally preferred over px and pt https://stackoverflow.com/questions/609517/why-em-instead-of-px
  • How to fix header side as boxed

    Solved Customisation header boxed sudonix nodebb
    10
    1
    6 Votes
    10 Posts
    3k Views
    @phenomlab yes it caused a problem for mobile users. thank you for helping …
  • ineffecient use of space on mobile

    Solved Customisation nodebb
    10
    2
    7 Votes
    10 Posts
    3k Views
    @phenomlab Thanks
  • Recent Cards plugin customization

    Solved Customisation nodebb
    21
    1
    13 Votes
    21 Posts
    10k Views
    @pobojmoks that’s easily done by modifying the code provided here so that it targets background rather than border In essence, the below should work $(document).ready(function() { $(window).on('action:ajaxify.end', function(data) { $('.recent-card-container').each(function(i) { var dataId = $(this).attr("data-cid"); var color = $('[role="presentation"]', this).css("background-color"); console.log("data-cid " + dataId + " is " + color); $('[data-cid="' + dataId + '"] .recent-card').attr("style", "background-color: " + color); }); }); });
  • 0 Votes
    9 Posts
    2k Views
    @downpw I’m inclined to agree with this. There isn’t much else you can do, and provided it works with no odd looking artefacts in other browsers, then ok. The :before and :after are pseudo classes and very well supported across all browsers (except perhaps Internet Exploder, but who uses that these days ?)
  • 3 Votes
    9 Posts
    2k Views
    @Sala Yes, I personally use Edge. Hated Internet Exploder (misspell intentional) but seeing as Edge is Chromium and Webkit backed, it works for me.