Skip to content

Material View Support for Stock NodeBB

Unsolved Let's Build It
  • –> For now test function in production…
    I provide all JS and CSS code for all after… and after @phenomlab check and validate of course

    – EDIT :

    Can you correct the title of the topic please ?

  • @DownPW done. Fixed a typo

  • Hello @phenomlab

    I didn’t even notice because I never use this mode. But when I say never it’s so much that I forget that it’s possible to do it.

    When right sidebar is expand, the button is at the bottom of the sidebar like this :
    image.png

    –> For now, I resolve the problem by change var buttonContainer = $('[component="sidebar/right"]'); for var buttonContainer = $('[component="sidebar/drafts"]');

    // ------------------------------------------
    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 991px or more
                if ($(window).width() >= 991) {
                    // Check if the custom thread view button already exists in the right sidebar
                    var buttonContainer = $('[component="sidebar/drafts"]');
                    // 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);
            }
                }
    
    ..............
    

    it’s clearly better :

    c5c4df57-b33e-46ce-814b-18e514bf6933-image.png

    but if you have better solution (like add text if sidebar is expand for example) I take it 🙂

  • Seems this solution give me a new bug for tooltip

    image.png

    I have test this with no working :

    if (isChecked) {
           $('[component="sidebar/drafts"]').find('[data-toggle="tooltip"]').tooltip('dispose');
       } else {
           $('[component="sidebar/drafts"]').find('[data-toggle="tooltip"]').tooltip();
       }
    
  • @DownPW Seems to work fine for me?

  • @DownPW It doesn’t look right - the toggle switch is now located at the top of the menu

    a9e329a2-fff6-407c-bc08-9668b9b002c1-image.png

  • yep I test things at the moment

    I’m go back for you to see

    EDIT: You can test now @phenomlab

  • @DownPW Try this. Change the function to

    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 991px or more
                if ($(window).width() >= 991) {
                    // Check if the custom thread view button already exists in the right sidebar
                    //var buttonContainer = $('[component="sidebar/right"]ul#logged-in-menu');
                if ($("#logged-in-menu").length > 0) {
                    var buttonContainer = $('ul#logged-in-menu');
                    }
                else {
                    var buttonContainer = $('ul#logged-out-menu');
                }
                    // 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
                    
                // Remove any existing tooltips
        $(this).tooltip('dispose');
                    
                // 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');
                        $('#pageUp.show').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'); 
                        $('#pageUp.show').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');
            
        });
    }
    

    And modify this CSS to the below

    @media (min-width: 991px) {
    #materialThreadViewButton {
        border-radius: 7px;
        cursor: pointer;
        position: relative !important;
        z-index: 999;
        display: flex;
        left: 15px !important;
        top: 5px !important;
        transform: rotate(90deg) !important;
        }
    }
    

    Essentially, we have to change the positioning of the block to use the logged-in and logged-out ID’s

                // Check if the screen width is 991px or more
                if ($(window).width() >= 991) {
                    // Check if the custom thread view button already exists in the right sidebar
                    //var buttonContainer = $('[component="sidebar/right"]ul#logged-in-menu');
                if ($("#logged-in-menu").length > 0) {
                    var buttonContainer = $('ul#logged-in-menu');
                    }
                else {
                    var buttonContainer = $('ul#logged-out-menu');
                }
                    // Append the button to the selected container
                    buttonContainer.append(threadViewButton);
            } 
    
  • I tested the same thing but added a container like [component="sidebar/right"] or [component="sidebar/drafts"] or the sidebar right CSS class. it worked but it created other bugs

    I’m not sure I would have thought to do this without specifying a container and just use ul#logged-out-menu & ul#logged-in-menu ALONE, no component or CSS class 🙂

    Thanks @phenomlab

  • @DownPW The real issue here is that you should always bind (either append or prepend) to an ID rather than a class. You can guarantee in most cases that the ID is unique, whereas the class probably isn’t, and that’s what is causing your issue.

  • Oh yes, that’s what’s super cool, I learn something every day. Afterwards I start from so low in JS


  • 50 Votes
    107 Posts
    3k Views

    @crazycells

    image.png

    image.png

  • 19 Votes
    35 Posts
    2k Views

    @DownPW said in Threaded chat support for NodeBB:

    Better like this : add shadow and border-left on self answer

    Of course - you style to your own requirements and taste 🙂 I’ll commit that CSS we discussed yesterday also

  • 11 Votes
    14 Posts
    601 Views

    @dave1904 excellent news. Thanks for the feedback

  • 1 Votes
    11 Posts
    557 Views

    @DownPW yes, because of the modifications that Sudonix uses, you’ll need to tailor to fit your needs.

  • 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); } });
  • Bug Navbar CSS

    Solved Customisation
    3
    1 Votes
    3 Posts
    301 Views

    Not better way.

    Thanks.

  • NodeBB Design help

    Solved Customisation
    8
    2 Votes
    8 Posts
    829 Views

    @riekmedia I’ve applied some new CSS to your site. Can you reload the page and try again ?

    For the record, this is what I added

    #footer { background: #2d343e; border-top: 4px solid #2d343e; font-size: 0.9em; margin-top: 70px; padding: 80px 0 0; position: relative; clear: both; bottom: 0; left: 0; right: 0; z-index: 1000; margin-left: -15px; margin-right: -338px; }

    The /categories page seems a bit messed up, so looking at that currently

    EDIT - issued some override CSS in the CATEGORIES widget

    <!--- CSS fix for overspill on /categories page - DO NOT DELETE --> <style> #footer { margin-right: -45px; } </style>

    That should resolve the /categories issue.

  • CSS Help on my Flarum

    Solved Customisation
    5
    2 Votes
    5 Posts
    433 Views

    @mike-jones Yes, you’ll typically see this type of behaviour if there is another style that has higher priority in the sense that yours will be overridden. Using !important will override the higher preference, but should be used sparingly rather than everywhere.