Skip to content

Material View Support for Stock NodeBB

Unsolved Let's Build It
  • @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.

  • 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


Related Topics
  • CSS code customization for the link preview plugin

    Solved Customisation
    4
    3 Votes
    4 Posts
    549 Views

    @crazycells said in CSS code customization for the link preview plugin:

    does OGProxy show the pdf previews as well?

    Not yet, but it could with a bit of additional code.

  • Threaded chat support for NodeBB

    Let's Build It
    35
    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

  • Widget | CSS customization

    Solved WordPress
    53
    17 Votes
    53 Posts
    3k Views

    @Sala the only way you can achieve this is to use a robots.txt file and disallow access to those links.

  • Setup OGProxy for use in NodeBB

    Moved Let's Build It
    110
    21 Votes
    110 Posts
    11k 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

  • tag icon in front of tags

    Solved Customisation
    5
    3 Votes
    5 Posts
    456 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.

  • Avatar on Topic Header

    Solved Customisation
    9
    0 Votes
    9 Posts
    630 Views

    @jac said in Avatar on Topic Header:

    @downpw said in Avatar on Topic Header:

    Great Plugin 🙂

    I make it a bit cleaner via this CSS code:

    /*------------------------------------------------------------------*/ /*---------------- nodebb-plugin-browsing-users -----------------*/ /*------------------------------------------------------------------*/ /*Space between the avatar and the RSS icon */ .topic [component="topic/browsing-users"] { margin-bottom: -5px; padding-left: 10px; } /*Space between avatars*/ .pull-left { float: left!important; padding-right: 5px; }

    Do you have a screenshot of how this looks with the CSS change?

    Just added this change, thanks @DownPW 🙂

  • Multiple link on one ico non Navbar

    Solved Customisation
    7
    2 Votes
    7 Posts
    498 Views

    yeah you’re right @phenomlab.
    Problem of NodeBB Version

  • NodeBB Design help

    Solved Customisation
    8
    2 Votes
    8 Posts
    931 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.