Some questions on writing front-end scripts

NodeBB Development
  • Hello everyone.
    I'm writing a plugin for NodeBB. and some questions arises.

    1. I see many plugins have client.js, the purpose of writing this script is to put a short script which will run as soon as this component is loaded. Is it the true purpose of this file?

    2. in client.js, we could see

    $(document).ready(function() {
    // Some code

    example from nodebb-plugin-markdown

    But we could see another version which does not use this wrap instead expose those statements in global scope.
    The question is, which version is better or is recommended?

    Thanks in advance!✈

  • @jiangcaiyang $(document).ready just tells jQuery to execute the code in the given function after the document HTML as finished loading. It may not be necessary if the things you're doing don't need the document to be ready.

  • @PitaJ How many times will // Some code be executed if they are not inside $(document).ready? I know // Some code will be executed once inside $(document).ready.

    Another question, which will be executed first? the code inside $(document).ready or the one outside?

Suggested Topics

  • 0 Votes
    2 Posts

    We don't have any built in conditional support. There's the @first helper which works for when you only want to check if @index == 0. To do this, I'd suggest adding a helper for whatever condition you need.

  • 0 Votes
    3 Posts

    If it were a bot, I could assign it a token from the ACP. I am creating a third party application that interfaces with NodeBB. It needs to be able to inherently create new user accounts, and then also login as them (which is where logging in via a token would come into play). I suppose it would be possible to create an account via a socket connection directly, but I imagine I could have uses to some of the write API methods anyways.

    Is it possible to programmatically create user tokens for the Write API? If that's the case, I could use a socket to create the account, and then generate a JWT token specifically for that user rather than hacking something into the application itself. That would leave the only hurdle being logging in, but at that point I could just store encrypted login credentials in a config file, and login to the API using

  • 0 Votes
    1 Posts

    Greetings, I am trying to directly modify some files in the persona theme to include the slick carousel slider as a header. I've added it as an inline script in header.tpl and also changed my requirejs-config accordingly:

    require.config({ baseUrl: "{relative_path}/src/modules", waitSeconds: 3, urlArgs: "{config.cache-buster}", paths: { 'jquery': '../../vendor/jquery/js/jquery', 'forum': '../client', 'admin': '../admin', 'vendor': '../../vendor', 'mousetrap': '../../bower/mousetrap/mousetrap', 'slick': '' }, shim: { 'slick' : ['jquery'] } });

    I find that the slider and site is working fine only on a fresh page load/reload. On a click of any button to navigate, the slider breaks and i get these errors:

    Uncaught TypeError: $(...).timeago is not a function
    Uncaught TypeError: $(...).tooltip is not a function
    Uncaught TypeError: widgetAreas.find(...).timeago is not a function

    Probably suggesting that jQuery was loaded more than once. I'm inclined to think that this has got something to do with how I've changed the requirejs above. However leaving out the above change will lead to:

    Uncaught TypeError: Cannot read property 'fn' of undefined in slick.min.js

    Possibly suggesting the jQuery wasn't loaded?

    I've also looked and followed the tips here but nothing seems to work. I just feel that I'm really close to getting it done.

  • 1 Votes
    1 Posts

    Greetings folks.

    Is there a way to create a bunch of categories using a json file?

    If so what would that look like?

    For instance, lets say i wanted to use a json file to create a category for each state in the usa or every county in a single instead of doing it manually.

    What the best way to go about that?

  • 0 Votes
    7 Posts

    v0.6.x should be stable on Mongo again.