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.

  • SSO Plugin questions

    NodeBB Development
    0 Votes
    1 Posts

    I'm working with this SSO plugin skeleton: to create my own.

    I want to add a check to see if the user who is trying to connect to this 3rd party is already logged in to NodeBB, if so I would like to disregard the email address provided by the 3rd party sso and just add the other fields from the sso provider to his profile.

    The reason for this is becuase whenever a user is already logged in and tries to connect via SSO and that he is registered in that 3rd party with a different email address, NodeBB will create a new user.

    I can see that I need to add a check under the OAuth.login function but not sure how to check if there's currently a logged in session for this user.

  • 0 Votes
    6 Posts

    @baris Hi, i too have the same requirement, i understand that we have to write a plugin to use the hooks filter:user.updateProfile.

    Could you please provide any sample to write plugin and use this hook.

  • 0 Votes
    7 Posts

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

  • 0 Votes
    6 Posts

    i have the same issue , I have tried like below

    in requirejs file I have the below code
    function scripts() {
    return document.getElementsByTagName('script');
    if we remove this from requirejs file my eternal script is working fine, But some other exsisting functionalites are not working?