Skip to content

Smart Widgets

Solved Configure
  • I have an idea for a smart Widget,

    1. Without getting into the details of that yet, here is a more basic widget idea as an example.
      Lets say my html /js widget says
      ctx.fillText(“Hello”)
      Is there a global variable that the js can access to get say, current logged in name?
      So in this example, you could put
      ctx.fillText(“Hello”+userName) in the widget code.

    2. I notice Sudonix has a Yellow box widget ‘Looks like your connection was lost…’
      What js command is used in the Widget to pick up when connection drops?

  • @Panda said in Smart Widgets:

    Is there a global variable that the js can access to get say, current logged in name?
    So in this example, you could put
    ctx.fillText(“Hello”+userName) in the widget code.

    Yes, if you visit this site on a desktop, you’ll see that there is a footer bar that uses this exact function to display the logged in username.

    More detail here
    https://sudonix.org/topic/314/bottom-footer-navbar-button-extend/17?_=1685477223864

    I notice Sudonix has a Yellow box widget ‘Looks like your connection was lost…’
    What js command is used in the Widget to pick up when connection drops

    It’s a command from NodeBB core that uses socket.io

  • Thanks, I read through those posts. I tend to do more in js on canvas than CSS etc, and definitely dont want to use Jquery!
    So in my simple ctx.fillText(‘name=’+ …
    example what variable holds the username? Or is it more complicated than that?

  • Pandaundefined Panda has marked this topic as solved on
  • @Panda said in Smart Widgets:

    So in my simple ctx.fillText(‘name=’+ …
    example what variable holds the username? Or is it more complicated than that?

    You could expose it this way

        function updateUsername() {
            $('.getUsername .username').text(app.user.username);
            $('.topicUsername').text(app.user.username);
        }
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', updateUsername);
        } else {
            updateUsername();
        }
    

    So in your use case, it would be

    ctx.fillText('name='+app.user.username);
    
  • @Panda said in Smart Widgets:

    definitely dont want to use Jquery!

    Any specific reason for this?

  • I like to do things Vanilla unless there is real need for a library.
    Thats what I most disliked about Nextjs, even a basic project starts with a directory full of autogenerated files, and I had so many times when nothing was working.
    What would be the non-JQ way of doing this please?
    $(‘.getUsername .username’).text(app.user.username);

    chatgpt tells me
    document.querySelector(‘.getUsername.username’).textContent=app.user.username

    So that seems just as easy, so why use JQ?

  • @Panda said in Smart Widgets:

    So that seems just as easy, so why use JQ?

    Because the library is already loaded in NodeBB, and forms a major part of the platform.

    https://community.nodebb.org/topic/17117/what-s-next-after-v3/17?_=1685522832798

  • Thanks. it worked. Actually It turned out
    ct1.fillText(app.user.username … etc
    worked without even running that function to ‘expose it’
    So why is that, or conversely why would the function to expose username ever be required, as it seems app.user is already an available global object?

  • @Panda said in Smart Widgets:

    So why is that, or conversely why would the function to expose username ever be required, as it seems app.user is already an available global object?

    It is, yes, but not if you are using it outside of a widget. The function I wrote is also historical and comes from the 2.x train 🙂


Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation 💗

  • nodebb error logs

    Bugs
    6
    4 Votes
    6 Posts
    177 Views

    I just wanted to ask because I don’t have much knowledge about the new installation.
    Thank you for the explanatory answer.

  • 1 Votes
    1 Posts
    111 Views
    No one has replied
  • Where are widgets stored?

    Solved Configure
    3
    1 Votes
    3 Posts
    171 Views

    @phenomlab Thanks, have DMed you

  • Further Widgets question

    Solved Configure
    4
    1 Votes
    4 Posts
    151 Views

    @Panda category is for a category in its own, so for example, “fruit” whereas categories is the page that contains all categories as a list.

  • 0 Votes
    5 Posts
    194 Views

    @mventures Yes, exactly. The other icon will restart NodeBB whilst the first icon I referenced will rebuild (recompile) it.

    The huge strength of NodeBB over Flarum (for example) is that the code is precompiled, and called once at boot. PHP’s code has to repeatedly reload code from source making it much slower.

  • 13 Votes
    22 Posts
    1k Views

    Been playing with the user profile page this afternoon. Thought I’d post a video as I’m really pleased with how this came out

  • 1 Votes
    2 Posts
    611 Views

    @eveh Welcome board 🙂

    The code you are referring to is custom written as no such functionality exists under NodeBB. However, adding the functionality is relatively trivial. Below are the required steps

    Navigate to /admin/appearance/customise#custom-header Add the below code to your header, and save once completed <ol id="mainbanner" class="breadcrumb"><li id="addtext">Your Title Goes Here</li></ol> Navigate to /admin/appearance/customise#custom-js and add the below code, then save $(document).ready(function() { $(window).on('action:ajaxify.end', function(data) { // Initialise mainbanner ID, but hide it from view $('#mainbanner').hide(); var pathname = window.location.pathname; if (pathname === "/") { $("#addtext").text("Your Title"); $('#mainbanner').show(); } else {} // If we want to add a title to a sub page, uncomment the below and adjust accordingly //if (pathname === "/yourpath") { //$("#addtext").text("Your Title"); //$('#mainbanner').show(); //} }); }); Navigate to /admin/appearance/customise#custom-css and add the below CSS block .breadcrumb { right: 0; margin-right: auto; text-align: center; background: #0086c4; color: #ffffff; width: 100vw; position: relative; margin-left: -50vw; left: 50%; top: 50px; position: fixed; z-index: 1020; }

    Note, that you will need to adjust your CSS code to suit your own site / requirements.

  • 4 Votes
    25 Posts
    2k Views

    Topic open
    https://sudonix.com/topic/207/nodebb-help-for-my-custom-css