How to open composer via clientside script and add category & tags


  • Hey! I called and opened the composer via GET-Params:

    https://nodebb.development.fail/recent?discord=question&tags=javascript,jquery,get,request

    URL is valid, so feel free to test it 🙏
    Open Composer


    • ?discord=question defines category questions
    • &tags=javascript,jquery,get,request tags added to composer as well -> javascript, jquery, get, request

    So: composer is opening automatically if:

    • ?discord=question is available. Also the category Questions is selected automatically. And tag list:
    • javascript,jquery,get,request should also be added automatically.

    But theres ohne thing: I dont have a question actually. 😄

    Bye Bye

    Prototype and Test-Code:

    
    $(window).on('action:ajaxify.end', function(event, data) {
    
        var urlParams = new URLSearchParams(window.location.search); //get all parameters
        var discord = urlParams.get('discord');
        
        var tags = [];
        
        if(tags = urlParams.get('tags')){
            tags = urlParams.get('tags').split(",");
        }
        
        
        
        if(discord){
            var cid;
            
            if(discord == "question"){
                cid = 1;
                app.newTopic(cid, tags);
            }
            
            if(discord == "tutorial"){
                cid = 2;
                app.newTopic(cid, tags);
            }
            
            if(discord == "showroom"){
                cid = 4;
                app.newTopic(cid, tags);
            }
            
            if(discord == "talk"){
                cid = 3;
                app.newTopic(cid, tags);
            }
        }
    	
    });
    

    To open composer use:

    • app.newTopic();

    To define category or tags use params of function:

    • app.newTopic(cid, tags);
      ->
      app.newTopic(1, ["javascript", "jquery", "get", "request"]);

    You can also use this snippet to add additional buttons to create new topic on specific category or tags. 👍

    Bye

  • GNU/Linux Gamers

    @dogs what does discord have to do with it? I tried using that link with different values and URL of course on my site, still didn't work. I'm sure it works for you, what am I missing?

  • GNU/Linux Gamers

    @dunlix @dogs I see that I am dumb. I should have read whole post before replying, Lol. I need to add custom JS when I will use this.


  • @dunlix yeah you should! 😂

    what does discord have to do with it? I tried using that link with different values and URL of course on my site, still didn't work. I'm sure it works for you, what am I missing?

    To be honest: Nothing.

    I am building a plugin for Discord integration..So the variable names are just placeholders if you want so.

    The important part is at the end of my main post.

    I hope that you find a slick way to use it for your community maybe. 🙂 👍

Suggested Topics

  • 1
  • 1
  • 1
  • 3
  • 14
| |