Skip to content

Material View Support for Stock NodeBB

Unsolved Let's Build It
  • Hello @phenomlab

    like thread view in topics and in Chat, I got the idea of having the same principle for the material view in the home page, the recent Topics view, unread, inside topics etc…

    We could call it Material View

    The idea would be to have a button in the right sidebar (User Bar) to activate the Material view or not. The container to use would therefore be [component="sidebar/right]

    This should of course not interact with the Thread view mode in the topics nor with the Stock code of nodeBB

    To not interfere with the other 2 codes, we could name the CSS class to add .mview or .material for example

    This is the desired result if you activate the Material view button :

    – Home Page :
    a039760d-3601-4afc-a694-47de36fe4a1c-image.png

    – Recent, unread, etc…
    fc3c540e-455f-4e9a-93bc-d58ec1e2c44d-image.png

    – Topic (without thread View)
    4c790ca3-9095-4f10-b319-de6c6b4741ff-image.png

    Here the CSS code ofr apply this Chnage without Javascript Code, just CSS :

    // ------------------------------------------
    // Thread CATEGORIES & TOPIC (TEST)
    // ------------------------------------------
    
    /* Home Page and Recent */
    @media (min-width: 576px) {
    [component=post], [component="category/topic"], [component="categories/category"], li[component="chat/message"], [component="chat/recent/room"], div#users-container a {
        background: var(--bs-post-category-wrapper);
        background: #f7f7f7;
        border-radius: var(--bs-post-category-wrapper-radius);
        border-radius: 0.375rem;
        margin-bottom: var(--bs-post-category-wrapper-margin);
        margin-bottom: 20px;
        border: 1px solid var(--bs-border-color);
    }
    }
    
    @media (min-width: 576px){
    [component="category/topic"], [component="categories/category"] {
        margin-bottom: var(--bs-post-category-topic-margin);
        margin-bottom: 20px;
    }
    }
    
    @media (min-width: 576px) {
    ul.topics-list li, li[component="chat/message"], [component="chat/recent/room"], div#users-container a {
        padding: 0.75rem 0 !important;
        padding-left: 20px !important;
        padding-right: 20px !important;
    }
    }
    
    ul.topics-list li {
        border-bottom: 1px solid var(--bs-border-color);
    }
    
    @media (min-width: 1600px) {
    [component=category] > *, .categories-list > *, [component="groups/container"] > *, .users-container > * {
        transition: opacity 150ms linear 100ms, transform 150ms ease-in-out 100ms;
    }
    }
    
    @media (min-width: 1600px) {
    [component=category] > *, .categories-list > *, [component="groups/container"] > *, .users-container > * {
        visibility: visible;
    }
    }
    
    @media (min-width: 576px) {
    [component="categories/category"] {
        padding: 20px;
    }
    }
    
    /* Topics & Posts */
    .page-topic .topic .posts.timeline .timeline-event, .page-topic .topic .posts.timeline > [component="post/placeholder"], .page-topic .topic .posts.timeline > [component=post] {
        border-left: none;
        /*box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;*/
        transition: margin-left 0.3s ease, margin-right 0.3s ease;
        border: 1px solid var(--bs-border-color);
        background: #F7F7F7;
    }
    
    .post-footer.border-bottom.pb-2 {
        border-bottom: 0rem !important;
    }
    
    li.necro-post.text-muted.timeline-event.d-flex.gap-2.pt-4 {
        box-shadow: none !important;
        border-radius: 0rem !important;
        border: none;
        background: none !important;
    }
    
    .page-topic .topic .posts.timeline .timeline-event.highlight, .page-topic .topic .posts.timeline > [component="post/placeholder"].highlight, .page-topic .topic .posts.timeline > [component=post].highlight {
        border-radius: 0.375rem;
    }
    
    @media (min-width: 1200px) {
    ul[component=topic]:before {
        margin-left: 50px;
    }
    }
    
    
    
    @media (min-width: 1200px) {
    .posts-container:before {
        margin-left: 43px;
    }
    ul[component=topic]:after {
        margin-left: 43px;
    }
    }
    
    @media (min-width: 576px) {
    .page-topic .topic .posts.timeline [component="topic/event"].timeline-event .timeline-badge, .page-topic .topic .posts.timeline [component="topic/necro-post"].timeline-event .timeline-badge {
        margin-left: 1rem;
    }
    }
    
    a.post-index.text-muted.d-none.d-md-inline {
        margin-right: 5px;
    }
    
    .page-topic .topic .posts.timeline .timeline-event:last-child, .page-topic .topic .posts.timeline>[component="post/placeholder"]:last-child, .page-topic .topic .posts.timeline>[component=post]:last-child {
        padding-bottom: 0rem;
    }
    

    – A helping hand developing this would be super cool. Unless you don’t care at all and you don’t like the idea.

    – For now I have a beginning, the following code inspired by your previous codes but I don’t know if I’m on the right track

    // ------------------------------------------
    // material View Mode
    // ------------------------------------------
    
    function material() {
        $(document).ready(function () {
            // Check if the screen width is 460px or more
            if ($(window).width() >= 460) {
                // Check if the custom thread view button already exists
                if ($('#materialThreadViewButton').length === 0) {
                    // Create the button for custom thread view mode with custom IDs
                    var threadViewButton = $('<div class="material-threads-wrapper"><form class="form"><div class="form-check form-switch 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>');
                    
                    // Append the button to the right sidebar
                    $('[component="sidebar/right"]').append(threadViewButton);
                }
                
                // Check if there's a stored state for the checkbox and update it
                var storedState = localStorage.getItem('materialThreadViewState');
                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 Thread View Off" : "Material Thread 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
                    } else {
                        console.log('Material Thread view is inactive.');
                        // Remove the CSS rules here
                    }
                    
                    // 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');
            }
        });
    }
    
    // Attach the material function to relevant events
    $(window).on('action:ajaxify.end', function (data) {
        material();
    });
    
    $(window).on('action:posts.edited', function (data) {
        material();
    });
    
    $(window).on('action:posts.loaded', function (data) {
        material();
    });
    

    – Here the result :

    07d72e1d-8ca3-46f8-92ce-5beeeefc8c70-image.png

  • @DownPW don’t care? Are you nuts? I absolutely love this idea! Let me review and get back to you.

  • Ha ha !!!

    In any case my code does not work correctly 🙂

  • @DownPW nothing we can’t fix. Let me fire this up in dev and have a look.

  • @DownPW can you provide a screenshot of the layout you have? This would be useful as a guide.

  • – Home Page :

    – Recent, unread, etc…

    – Topic (without thread View)

  • It seems that the CSS class is added but that it does not work correctly when declared in the ACP.

    I wonder if we should not remove the resolution story and have the code applied regardless of the resolution used because Material mode can very well be used on Smartphones.

  • @DownPW On reviewing the screenshots again, this seems to be only an adjustment for the overall container width?

  • just background color, border etc…
    You have CSS I used for this result above in the topic

    but anyway, my code is not correct.

  • @DownPW It doesn’t work because you haven’t defined anything here 🙂

                    // 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
                    } else {
                        console.log('Material Thread view is inactive.');
                        // Remove the CSS rules here
                    }
    

    This is how I do it for the threads

    https://github.com/phenomlab/nodebb-harmony-chat-threading/blob/0cea943c2e7ab0f63d2b2eae38d64bc19b8242ec/functions.js#L22-L32

    Your CSS also needs to be more explicit. For example

    [component="category/topic"], [component="categories/category"] {
        margin-bottom: var(--bs-post-category-topic-margin);
        margin-bottom: 20px;
    }
    

    Would become

    [component="category/topic"].material, [component="categories/category"].material {
        margin-bottom: var(--bs-post-category-topic-margin);
        margin-bottom: 20px;
    }
    
  • I remenber I have already test this without good result.

    Maybe retest

  • @DownPW Did you review the classes as I mentioned?

  • @phenomlab said in Material View Support foir Stock NodeBB:

    @DownPW Did you review the classes as I mentioned?

    yes but added the wrong class name, it’s better now.

    I’m here at the moment.

    JS :

    // ------------------------------------------
    // material View Mode
    // ------------------------------------------
    
    function material() {
        $(document).ready(function () {
            // Check if the screen width is 460px or more
            if ($(window).width() >= 460) {
                // Check if the custom thread view button already exists
                if ($('#materialThreadViewButton').length === 0) {
                    // Create the button for custom thread view mode with custom IDs
                    var threadViewButton = $('<div class="material-threads-wrapper"><form class="form"><div class="form-check form-switch 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>');
                    
                    // Append the button to the right sidebar
                    $('[component="sidebar/right"]').append(threadViewButton);
                }
                
                // Check if there's a stored state for the checkbox and update it
                var storedState = localStorage.getItem('materialThreadViewState');
                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 Thread View Off" : "Material Thread 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=post]').addClass('material'); 
                        $('[component="category/topic"]').addClass('material'); 
                        $('[component="categories/category"]').addClass('material');
                    } else {
                        console.log('Material Thread view is inactive.');
                        // Remove the CSS rules here
                        $$('[component=post]').removeClass('material');
                        $('[component="category/topic"]').removeClass('material');
                        $('[component="categories/category"]').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');
            }
        });
    }
    
    // Attach the material function to relevant events
    $(window).on('action:ajaxify.end', function (data) {
        material();
    });
    
    $(window).on('action:posts.edited', function (data) {
        material();
    });
    
    $(window).on('action:posts.loaded', function (data) {
        material();
    });
    

    CSS :

    .material-threads-wrapper {
        display: flex;
        left: 5px !important;
        position: relative !important;
    }
    
    @media (min-width:460px) {
    
    [component=post].material, [component="category/topic"].material, [component="categories/category"].material { 
        background: #F7F7F7 !important;
        border-radius: 0.375rem;
        margin-bottom: 20px;
        padding-left: 20px;
        border: 1px solid var(--bs-border-color);
    }
    
    }
    

    – There are quite a few things left, for example:

    • if we scan the recent or unread ones, the rest is not in the background :

    f3fe08cf-fbc1-4f47-8497-866557c4ec25-image.png

    • And the block + timeline in the topics :
      35beb3bc-8871-4689-b31c-cd2c489907a4-image.png

    I would also like to change the button which is not suitable for a vertical display

    For the moment, I haven’t found for all of that but I’m looking for.

  • better with video :

    blink3.gif

  • @DownPW You’re missing a hook 🙂

    I’ve added this

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

    Works now !

  • @DownPW said in Material View Support foir Stock NodeBB:

    I would also like to change the button which is not suitable for a vertical display

    You could rotate it?

    .material-threads-wrapper {
        display: flex;
        left: 5px !important;
        position: relative !important;
        transform: rotate(45deg);
        margin-left: -2px;
        margin-top: 5px;
    }
    

    fc9f46cc-2235-47fe-a613-3baa9d5aa436-image.png

  • @DownPW could you pls share updated and enclosed codes for css and js?

  • @cagatay The code is not mature yet. There is still work to be done and phenomlab will have to validate it because I am not a developer

    @phenomlab said in Material View Support foir Stock NodeBB:

    You could rotate it?

    yep sure it’s better 🙂
    but I was thinking of a 2-state radio button like the form-switch because I believe Bootstrap offers it if I don’t say bullsh*t.

  • @DownPW said in Material View Support foir Stock NodeBB:

    but I was thinking of a 2-state radio button like the form-switch because I believe Bootstrap offers it if I don’t say bullsh*t.

    Something like this?

    https://jsfiddle.net/milanandfriends/p9AaY/

  • yes maybe, I had thought about that but just one button not two but why not :

    image.png

    https://getbootstrap.com/docs/5.0/forms/checks-radios/

    I’m not closed off I’m trying to see what could be better.


Related Topics
  • NodeBB Twitter / X embeds

    Let's Build It
    31
    19 Votes
    31 Posts
    588 Views

    @OT I honestly am not able to replicate this. Can you PM me a link to a post on your forum with the specific issue so I can have a look?

  • CSS border gradients

    Blog
    10
    2 Votes
    10 Posts
    467 Views

    ah f5 need 🙂

  • 11 Votes
    14 Posts
    836 Views

    @dave1904 excellent news. Thanks for the feedback

  • Detect if user is admin

    General
    2
    0 Votes
    2 Posts
    486 Views

    @pwsincd I think you can use userData.isAdmin = isAdmin; if I’m not mistaken - see
    https://community.nodebb.org/topic/15128/how-to-hide-whitelist-user-field-only-to-owner-or-admin?_=1648802303112 for an example

  • 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); } });
  • tag icon in front of tags

    Solved Customisation
    5
    3 Votes
    5 Posts
    468 Views

    @phenomlab said in tag icon in front of tags:

    @crazycells Are you using Font Awesome Free ? If so, try this

    span.tag:before { content: "\f02b"; font-family: "Font Awesome 5 Free"; margin-right: 5px; margin-left: 5px; font-weight: 900; }

    yeap, this worked 👍 thanks a lot.

  • Bug Navbar CSS

    Solved Customisation
    3
    1 Votes
    3 Posts
    362 Views

    Not better way.

    Thanks.

  • Discourse Design Change

    Customisation
    25
    7 Votes
    25 Posts
    2k Views

    @phenomlab okay