Skip to content

Material View Support for Stock NodeBB

Unsolved Let's Build It
  • see this @phenomlab

    the element is perfect regardless of the mode engaged but a refresh does not replace it correctly.
    A missing hook?

  • @DownPW No. More likely a CSS class is not being applied on load.

  • hmm that doesn’t help me much 🙂

  • @DownPW Add this to your existing css class of

    .page-topic .topic .posts.timeline [component="topic/event"].timeline-event, .page-topic .topic .posts.timeline [component="topic/necro-post"].timeline-event
    
        margin-left: 52px;
    

    So you land up with

    .page-topic .topic .posts.timeline [component="topic/event"].timeline-event, .page-topic .topic .posts.timeline [component="topic/necro-post"].timeline-event {
        margin-bottom: 10px;
        margin-left: 52px;
    }
    

    That will fix it.

  • no it’s worse 🙂

    Maybe, the best would be to add a .material class but I can’t do it at the moment

  • @DownPW I remember this same issue now when I came across it whilst writing the threaded function. The problem here is that [component="topic/necro-post"] actually isn’t present in the DOM on page load, but added afterwards. This is why once the page has loaded, you can target the element with the toggle switch because it is in the DOM at the time. Because the this specific element is loaded afterwards, you cannot target it if it doesn’t exist.

    This effectively means you cannot add a class to an element that is not there. To work around this, you’d either have to wait for the page to load, add the necro element, then target it.

    Or, use the CSS I provided, and then “counter” it using other CSS when the class is removed. This is what I do in thwe threaded function.

    Raised this as an issue here

    https://community.nodebb.org/topic/17590/necro-function-dom-changes

    EDIT - should work now 🙂

    I’ve added a loop in your material function that looks specifically for the necro post

    $('[component="topic/necro-post"]').each(function () {
         // Add the 'material' class to matching elements
         if ($(this).hasClass('timeline-event')) {
         $(this).addClass('material');
         }
     });
    

    And also (on the advice of Baris) added a new hook as below

    $(window).on('action:topic.loaded', function (data) {
        material();
    });
    

    There are two separate hooks that look very much the same, but do different things (one has an “s” at the end, whilst the other doesn’t - “action:topic.loaded” and “action:topics.loaded”

    Now it works as intended 🙂

  • ohh yes better 🙂

    I undersxtand for adding .each(function () for [component=“topic/necro-post”]

    I have read the thread on nodeBB communauty. On the other hand, I don’t really understand the difference for the hook in topic and topicS

  • @DownPW I think the difference is that the topic hook is for single, and topics for a selection. Makes sense, but not very well explained in the documentation!

  • Thanks for explain. Make sense, indeed but it’s not easy to know without Baris help 🙂


    Still with the idea of improving the code, I’m going to focus now on making the selection button appear on Smartphone.

    Indeed, currently, it does not appear because it seems that on Smartphone another component is used

    b46c3d29-7f77-4f85-b207-790f2f10378b-image.png

    10d1925e-fad1-42e0-b209-12fcc9dc6ca5-image.png

  • I test this :

    // ------------------------------------------
    // material View Mode
    // ------------------------------------------
    
    function material() {
        $(document).ready(function () {
            var $buttonContainer = null;
    
            // Check if the screen width is 460px or more
            if ($(window).width() >= 991) {
                // Check if the custom thread view button already exists in the right sidebar
                $buttonContainer = $('[component="sidebar/right"]');
            } if ($(window).width() <= 991) {
                // Check if the custom thread view button already exists in the bottom bar
                $buttonContainer = $('[component="bottombar"]');
    
            }
    
    
  • @DownPW yes, the same methodology is used for the theme switcher in NodeBB v2.x 😀

  • ohh yes, don’t see that to be honest.

    Button appear but hard to position it correctly for all resolution.
    The button moves according to the resolution. it is not fixed

  • @DownPW if you use apend then it should reflect the div it is inserted into.

    The version of the theme switcher from the NodeBB v2 series used the same mechanism, and that code is still listed in this forum. It would be a good idea to review that code for inspiration as the placement for the switcher drop down was set depending on screen estate.

  • @DownPW this should provide the functionality you are looking for

    // ------------------------------------------
    // material View Mode
    // ------------------------------------------
    function material() {
        $(document).ready(function () {
                // Create the button for custom thread view mode with custom IDs
                if ($('#materialThreadViewButton').length === 0) {
                    var threadViewButton = $('<div class="material-threads-wrapper"><form class="form"><div class="form-check form-switch form-switch-sm material-threads-wrapper"> \
                        <input class="form-check-input" id="materialThreadViewButton" type="checkbox" data-field="materialThreadView"> \
                        <label class=" d-none d-md-inline fw-semibold" for="materialThreadViewButton"></label> \
                    </div></form></div>');
                    
                            // Check if the screen width is 460px or more
            if ($(window).width() >= 991) {
                // Check if the custom thread view button already exists in the right sidebar
                var buttonContainer = $('[component="sidebar/right"]');
                // Append the button to the selected container
                buttonContainer.append(threadViewButton);
            } 
            if ($(window).width() <= 991) {
                // Check if the custom thread view button already exists in the bottom bar
                //$buttonContainer = $('.bottombar-nav.p-2.text-dark.bg-light.d-flex.justify-content-between.align-items-center.w-100');
                if ($("#logged-in-menu").length > 0) {
                var buttonContainer = $('.bottombar-nav ul#logged-in-menu');
                }
                else {
                    var buttonContainer = $('.bottombar-nav ul#logged-out-menu'); 
                }
                            // Prepend the button to the selected container
                buttonContainer.prepend(threadViewButton);
            }
                }
                // Check if there's a stored state for the checkbox and update it
                var storedState = localStorage.getItem('materialThreadViewState');
                console.log("Stored State is " + storedState);
                if (storedState === 'true') {
                    $('#materialThreadViewButton').prop('checked', true);
                }
                
                // Toggle the class 'material' on or off when the checkbox changes state
                $('#materialThreadViewButton').on('change', function () {
                    var isChecked = $(this).is(':checked');
                    var theTooltip = isChecked ? "Material View Off" : "Material View On"; // Update tooltip message
                    
                    // Toggle CSS rules when the button is turned on or off
                    if (isChecked) {
                        console.log('Material Thread view is active.');
                        // Apply your CSS rules here
                        $('[component="category/topic"]').addClass('material'); 
                        $('li[component="category/topic"]').addClass('material'); 
                        $('[component="categories/category"]').addClass('material');
                        
                        $('.posts-container').addClass('material')
                        $('ul[component="topic"]').addClass('material')
                        $('.post-container').addClass('material')
                        $('.timeline-event').addClass('material')
                        $('[component="post/footer"]').addClass('material')
                        $('li.pt-4.deleted').addClass('material') 
                        
                        $('.page-topic .topic .posts.timeline .timeline-event > div:first-of-type, .page-topic .topic .posts.timeline > [component="post/placeholder"] > div:first-of-type, .page-topic .topic .posts.timeline > [component=post] > div:first-of-type').addClass('material');
    
                        $('[component="post"]').each(function () {
                            // Add the 'material' class to matching elements
                            if ($(this).hasClass('pt-4') || $(this).hasClass('self-post')) {
                                $(this).addClass('material');
                                $('[component="sidebar/right"]').addClass('material');
                            }
                        });
                        $('[component="topic/necro-post"]').each(function () {
                            // Add the 'material' class to matching elements
                            if ($(this).hasClass('timeline-event')) {
                                $(this).addClass('material');
                            }
                        });
    
                    } else {
                        console.log('Material Thread view is inactive.');
                        // Remove the CSS rules here
                        $('[component="category/topic"]').removeClass('material');
                        $('li[component="category/topic"]').removeClass('material');
                        $('[component="categories/category"]').removeClass('material');
                        
                        $('[component="post"]').removeClass('material');
                        $('ul[component="topic"]').removeClass('material');
                        $('.posts-container').removeClass('material')
                        $('ul[component="topic"]').removeClass('material')
                        $('.post-container').removeClass('material')
                        $('.timeline-event').removeClass('material')
                        $('[component="post/footer"]').removeClass('material');
                        $('li.pt-4.deleted').removeClass('material'); 
                       
                        $('.page-topic .topic .posts.timeline .timeline-event > div:first-of-type, .page-topic .topic .posts.timeline > [component="post/placeholder"] > div:first-of-type, .page-topic .topic .posts.timeline > [component=post] > div:first-of-type').removeClass('material'); 
    
                        $('[component="sidebar/right"]').removeClass('material');
                        
                    }
                    
                    // Store the checkbox state in localStorage
                    localStorage.setItem('materialThreadViewState', isChecked);
                    
                    // Update the tooltip title
                    $(this).attr('data-original-title', theTooltip).tooltip('dispose').tooltip({
                        placement: 'bottom',
                        title: theTooltip,
                        trigger: 'hover'
                    });
                });
    
                // Check for changes in the checkbox state when the page loads
                $('#materialThreadViewButton').trigger('change');
            
        });
    }
    

    Result

    6246743e-a9dd-40e3-b07f-5a69f6e54002-image.png

    I ddjusted some of your CSS - added this block

    #logged-out-menu .material-threads-wrapper {
        top: 5px;
        position: relative;
    }
    

    Also removed this block

    #materialThreadViewButton {
    }
    

    Not needed 🙂

    There are are two checks - one tests the screen estate and positions the menu item depending on size, and the other will see if the user is logged in or not, and if they are, it uses ul#menu-logged-in else it uses ul#menu-logged-out

    But only for the mobile view because .bottom-bar is based on both logged in and logged out sessions

    Enjoy

  • Thank you Mark for the button in Smartphone.

    In nodeBB 3.5.0, we can use .bottombar-nav-left or .bottombar-nav-right because @baris have created this components follow-up to my topic.

    Maybe update the code at this moment because cleaner.

    See here:

    https://community.nodebb.org/post/96323

    @phenomlab said in Material View Support foir Stock NodeBB:

    There are are two checks - one tests the screen estate and positions the menu item depending on size, and the other will see if the user is logged in or not, and if they are, it uses ul#menu-logged-in else it uses ul#menu-logged-out

    Seems to be good.


    I have again one or 2 other modification like the scroll to top button .material class to add because the button is hard to see on small phone resolutions It blends in with the color of the block of the categories. Nothing insurmountable I think. I’m getting good results

    I’m happy, this code is starting to look like something 🙂

  • @DownPW great. I did see the 3.5.0 changes and they look like a good idea, but can’t comment until I’ve tried them.

  • you’re right as usual my friend 🙂

  • Test material view display on my smartphone. Seems I have a little work again 🙂

  • @DownPW Good luck - let me know if you need any help.

  • Seems to be good :

    image.png

    just the line from the timeline on the left that I can’t seem to display. But I note that it’s the same here on Smartphones

    I need to check and recheck now 😉


  • 50 Votes
    107 Posts
    3k Views

    @crazycells

    image.png

    image.png

  • 3 Votes
    7 Posts
    332 Views

    @phenomlab yes it’s a different theme. The other one was not offering much on editable sidebar. It was like flarum hahah

  • 20 Votes
    110 Posts
    9k Views

    @crazycells said in Setup OGProxy for use in NodeBB:

    are they cached for each user separately?

    No. It’s a shared cache

    @crazycells said in Setup OGProxy for use in NodeBB:

    additionally, this is also handling youtube videos etc, right?

    No. This is handled by nodebb-plugin-ns-embed

  • 6 Votes
    15 Posts
    707 Views

    No no, I said that in the sense that he told me it was simple ^^
    I was able to see that this was not the case by targeting the elements he had advised me.

  • Quote design CSS

    Solved Customisation
    15
    4 Votes
    15 Posts
    685 Views

    @DownPW yes, that does make sense actually. I forgot to mention the layout of Sudonix is custom so that would have an impact on the positioning.

    Good spot 🙂

  • New message CSS problem

    Unsolved Customisation
    11
    2 Votes
    11 Posts
    550 Views

    @DownPW hi. Sorry for digging up an old post, but I’m going through items still unresolved and was looking to get an understanding of where you are currently with this?

  • 5 Votes
    9 Posts
    2k Views

    @phenomlab

    Very very great Mark 😉
    Thanks again, It’s perfect now !

    –> I share my code that I modified.

    I’ve added French and English comments.
    If you see things to change Mark, don’t hesitate.

    As usual, all the access paths (FA icons, logo) will have to be modified according to your architecture.

    You can also very well add/remove time slots and change welcome messages to suit your needs.

    Widgets ACP/HTML Widget Footer Logo <center> <br><br> <img id="thislogo" src="path/to/my/image"> </center> Widget Welcome Message <!-- IF loggedIn --> <div class="getUsername">, <a href="/me"><span class="username"></span></a></div> <!-- ENDIF loggedIn --> CSS

    – I added the size font-weight: 900; in the CSS because otherwise some FA icon wasn’t displayed correctly and reduce margin :

    i#thisicon { font-family: "Font Awesome 5 Free"; font-style: normal; margin-right: 8px; font-weight: 900; } .getUsername { padding-top: 20px; text-align: right; } /*Smartphone*/ /*On désactive le message de bienvenue"*/ /*We disable the welcome message"*/ @media all and (max-width: 1024px) { .getUsername { display: none; } } JAVASCRIPT // ------------------------------------------ // Welcome Message avec icône et Footer logo // Welcome Message with icon and Footer logo // ------------------------------------------ $(window).on('action:ajaxify.end', function (data) { //On récupère le username dans le DOM et on l'affiche //We retrieve the username from the DOM and display it function updateUsername() { $('.getUsername .username').text(app.user.username); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', updateUsername); } else { updateUsername(); } //On déclare les variables principales (themessage & thehours) ainsi que les variables secondaires correspondants aux plages horaires //We declare the main variables (themessage & thehours) as well as the secondary variables corresponding to the time slots var thehours = new Date().getHours(); var themessage; var wakeup = ('Good day'); var morning = ('Good morning'); var lunch = ('Bon appétit'); var afternoon = ('Good afternoon'); var drink = ('Cheers'); var evening = ('Good evening'); var night = ('Good night'); var welcome = ('Welcome'); var matched = false; //On peux ici tester le résultat du code en spécifiant une heure (!!!IMPORTANT: Commenter une fois le script testé!!!) //Here we can test the result of the code by specifying a time (!!!IMPORTANT: Comment once the script has been tested!!!) //thehours = 20 //On déclare les plages horaires avec les icones FA et les logos //We declare the time slots with FA icons and logos path if (thehours >= 0 && thehours < 6) { themessage = night; theicon = "fa-solid fa-moon"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 6 && thehours < 8) { themessage = wakeup; theicon = "fa-solid fa-mug-hot"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 8 && thehours < 12) { themessage = morning; theicon = "fa-solid fa-sun"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 12 && thehours < 13) { themessage = lunch; theicon = "fas fa-hamburger"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 13 && thehours < 16) { themessage = afternoon; theicon = "fa-solid fa-sun"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 16 && thehours < 18) { themessage = welcome; theicon = "fa-solid fa-rocket"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 18 && thehours < 19) { themessage = drink; theicon = "fa-solid fa-wine-glass"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 19 && thehours < 20) { themessage = lunch; theicon = "fas fa-pizza-slice"; thelogo = "/assets/customlogo/XXX.png"; } else if (thehours >= 20 && thehours < 24) { themessage = evening; theicon = "fa-solid fa-tv"; thelogo = "/assets/customlogo/XXX.png"; } // Si la page active est un topic, on désactive/cache le message de bienvenue // If the active page is a topic, we deactivate/hide the welcome message if (window.location.href.indexOf("topic") > -1) { console.log("This is a topic, so hide the user welcome message"); $('#thisuser').hide(); } // Sinon, on affiche le message en fonction, l'icone FA et son emplacement (prepend) // Otherwise, we display the message in function, the FA icon and its location (prepend) else { $('.getUsername').prepend("<i id='thisicon' class='" + theicon + "'></i>" + themessage); $("#thislogo").attr("src", thelogo); //$('.getUsername').prepend("<img id='thisicon' src='" + thelogo + "'></>" + themessage); } });
  • 0 Votes
    7 Posts
    728 Views

    @downpw ooops. Forgot that. Thanks for adding.