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 💗

  • 2 Votes
    4 Posts
    174 Views

    @Panda said in Sidebar Widget is no longer on the side!:

    Ah, so sidebar wont work on mobile?

    Correct. If you review the docs on bootstrap, you’ll notice that it is designed on a grid system

    https://getbootstrap.com/docs/5.0/layout/grid/

    What I mean by changing the category is moving it on here to general as you posted it in bugs, when it isn’t.

  • 2 Votes
    26 Posts
    1k Views

    @Panda said in Interesting Widget code, but can’t fetch API:

    How did you drop that widget into the post there?
    I hadnt seen this BSgenerator anywhere on sudonix site, do you use it somewhere already?

    Yes, here

    https://sudonix.org/topic/414/corporate-bullshit-generator?_=1687774393044

    It’s not a “post” or “topic” in the common sense. It is actually a page in it’s own right and leverages nodebb-plugin-custom-pages. This in turn creates a new “route” which behaves like a page, meaning it is then exposed for widgets.

    @Panda said in Interesting Widget code, but can’t fetch API:

    Also can you explain more what you mean by calling the code externally. In my API call example, how would I go about doing that?

    By this, I mean create all the required code in an external JS file that is reachable by the NodeBB instance - so, in “public” for example - or in my case /public/js. The widget then “calls” that file and because it runs outside of the scope of NodeBB, you just need to return the values to the widget.

    Hope this makes sense?

  • 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.

  • 2 Votes
    2 Posts
    149 Views

    @cagatay this relates to a change the css classes used for the brand header meaning it will now float to the left instead of right.

    If you’d like to retain the original behavior, you can add this css class

    [data-widget-area="brand-header"] { justify-content: end; display: flex; }

    Further information here

    https://community.nodebb.org/topic/17090/manual-build-a-custom-header-in-harmony/19?_=1684069325296

  • NodeBB: Favicon upload issue

    Solved Configure
    12
    3 Votes
    12 Posts
    356 Views

    @phenomlab I am on a Mac, so I used the “Option + Command + I”, and then performed the steps. It loaded my favicon! I checked on Firefox which I haven’t used before, and it showed my favicon also! That’s fantastic and thank you for the help!

  • Gettin Erors NodeBB

    Solved Configure
    7
    0 Votes
    7 Posts
    327 Views

    @phenomlab no forum is working goods.
    there is no eror message since yestarday.

  • Adding fileWrite to nodebb code

    Solved Configure
    16
    5 Votes
    16 Posts
    590 Views

    @eveh this might be a question for the NodeBB Devs themselves. In all honesty, I’m not entirely sure without having to research this myself.