Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Vanilla 2.6 is here! It includes security fixes and requires PHP 7.0. We have therefore ALSO released Vanilla 2.5.2 with security patches if you are still on PHP 5.6 to give you additional time to upgrade.

Last Minute Development

This discussion is related to the Prefix Discussion addon.
R_JR_J Cheerleader & TroubleshooterMunich Moderator

Just wanted to chime in in the row of "my last plugin for this year". @Skisma asked for something like this and II thought it might be a good candidate for a 2014 last minute coding. I hope it is not too buggy because of the haste ;)

phreakhgtonightBleistivtx00peregrineZhaanmirX
«13

Comments

  • You are awesome @R_J‌! I'm downloading now and let you know how it is :)

  • @R_J‌ Thanks so much for developing this, this definitely gets me somewhere! Although I will note two things that would make this plugin perfect: For one, the prefix only displays when viewing the actual thread/discussion and not when viewing a list of threads/discussions. Also, it would be nice if i could specify certain prefixes to certain forums/categories..but this isn't too big a deal. The first thing would be a game changer though. If you ever get around to updating this these please let me know! Regardless, it really awesome you did this. Thanks a bunch.

    R_J
  • peregrineperegrine MVP
    edited December 2014

    @vrijvlinder said:
    Here is an icon :)

    I don't see a robot. r_j is not going to be happy :wink:

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinderR_JBleistivt
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Yes, I thought about that too... it is just too hard to come up with a robot theme about prefixes :(

  • [robot]

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
  • peregrineperegrine MVP
    edited December 2014

    @vrijvlinder said:
    wow that would have never occurred to me, thanks!

    thats why I'm here little sister.

    then tell r_j his girlfriend signed off on the interior design of the icon.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    I wonder what R_J 's girlfriend's name is... Maybe Sabine, Ute, Inga, Lina, Gisela, Marlene ?

  • peregrineperegrine MVP
    edited January 2015

    my gut tells me it is Isolda or Angelika or Adolfina or Bernadette or Alfreda or Elfrida or Luane or Magnilda

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    @>; @Skisma said:

    R_J‌ Thanks so much for developing this, this definitely gets me somewhere! Although I will note two things that would make this plugin perfect: For one, the prefix only displays when viewing the actual thread/discussion and not when viewing a list of threads/discussions.

    I had only tested it with the normal layout and only after your complain found out that it doesn't work with table layout. I think this is a bug and I filed it on GitHub.
    In order to make it work, you'd have to change one of the core files. Normally I strictly disencourage that but in this case, I'd say it is totally safe. Look at line 47 of /applications/vanilla/views/discussions/table_functions.php. It should read // $Sender->FireEvent('BeforeDiscussionName') and you only have to delete the two slashes at the beginning of the line in order to make the prefix visible in discussion lists.

    @Skisma said:
    Also, it would be nice if i could specify certain prefixes to certain forums/categories.

    That is far more complicated and sorry, I guess I'll never add this functionality. But I'll upload that plugin sooner or later to GitHub and just feel free to send in pull requests!

    By the way: I updated the plugin and now you can change the list separator. That way you can use "/" as a separator and put that in the prefixes list: ♣/♠/♥/♦ => ♣/♠/♥/♦
    You can also have fun with some Unicode characters: 🎁/🎂/🎃/🎅/🎆 => 🎁/🎂/🎃/🎅/🎆

    peregrineSkisma
  • @R_J‌ Awesome, thanks for the info! Yea I figured that second suggestion would be complex, don't worry about it man this is great enough!

    vrijvlinder
  • @R_J‌ Wow that was the simplest update to code I can think of, haha. It worked great and is now showing in discussion lists, however, without the brackets []. This really is no big deal though, the main thing is that they're showing.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    I just coded some brackets in the CSS because I have seen them in your screenshot. You could simply add them directly in the config screen: [Question];[Solved] or change the CSS so that they also appear in the table view:

    ...
    .Discussion .PrefixDiscussion:before, .DiscussionName .PrefixDiscussion:before{
        content: "[";
    }
    .Discussion .PrefixDiscussion:after, .DiscussionName  .PrefixDiscussion:after{
        content: "]";
    }
    

    or

    ...
    span.PrefixDiscussion:before {
        content: "[";
    }
    span.PrefixDiscussion:after {
        content: "]";
    }
    

    I'm no CSS hero so I couldn't tell what is "best", but either way should show the brackets also in the table view.

    You could also skip those brackets completely and do something like this instead:

    .SpQuestion {
      background-color: blue;
      color: white;
      padding: 1px;
      margin: 1px;
      border-radius: 2px;
    }
    

    or

    span.SpQuestion:before {
        content: "¿";
    }
    span.SpQuestion:after {
        content: "?";
    }
    span.SpSolved:after {
        content: ":-)";
    }
    
  • SkismaSkisma New
    edited January 2015

    @R_J‌ Awesome solutions! The first suggestion is so simple I never would have thought of, lol.

    I have one more question that I think might have to do with some CSS styling as well. Basically it's a solution for not being able to assign certain prefixes to certain categories.

    I'm wondering how I can add additional options to the list, but make them bold and unable to be selected. Doing this will allow me to organize my prefixes to their according forums. So it would look something like this when you click the dropdown menu (without the numbering):

    1. Forge Maps < Cannot Select
    2. H2A
    3. H3
    4. H4
    5. General Maps < Cannot Select
    6. Unreal
    7. Far Cry
    8. Project Spark
    9. Forge Discussion < Cannot Select
    10. WIP
    11. Tutorial
    12. Question
    13. Game Discussion < Cannot Select
    14. Destiny
    15. Call of Duty
    16. Evolve
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Not trivial. What you are speaking of are HTML OptGroups and Vanilla supports them with its function DropDownGroup so it basically could be done if the setup screen would allow arrays maybe in the form (Forge Maps)[H2A,H3,H4](General Maps)[Unreal,Far Cry,Project Spark].

    But that is not what you are looking for. You are looking for Category related selects. Maybe some lines of JavaScript could do the job. You would have to hard code the prefixes in your script but because it is your own customized solution, it might be okay that you sacrifice some flexibility.

    In order to load a custom JS you have to add a line to the plugin. Search for the line containing "AddCssFile" (around line 120) and add that line right below:
    $Sender->AddJsFile('prefixdiscussion.js', 'plugins/PrefixDiscussion');
    Afterwards create the directory/file /plugins/PrefixDiscussion/js/prefixdiscussion.js and use this for your custom JS. I'm no JavaScript super hero so here is only a rough draft and you have to get it working by yourself:

    $(document).ready(function() {
        var prefixes = new Array();
        prefixes[1]=['H2A','H3','H4'];
        prefixes[2]=['Unreal','Far Cry','Project Spark'];
        // ...
    
        $('#Form_CategoryID').on('change', function(e) {
            var prefixSelect = $('#Form_Prefix');
            prefixSelect.innerHTML = '<option value="-">-</option>';
            if (e.target.value >= 1 && e.target.value <= 4) {  // if you have 4 categories...
                $.each(prefixes[e.target.value], function(option) { 
                    prefixSelect.options[prefixSelect.options.length] = new Option(option, option);
                }); 
            }
        });
    });
    

    The main idea is to get the current chosen category from the dropdown, delete the prefix dropdown content and add a predefined array for that category to the prefix dropdown.

    hgtonightSkisma
  • @R_J Wow thanks for this! I will give it a shot and hope I don't break anything, lol. You explain this fairly well so I think I should be fine. So basically I'll do a new prefixes[#]=['prefix name', 'prefix name', 'prefix name']; for each category I have and replace the "4" on line 10 with the number of categories I actually have?

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Yes that's it. To be slightly more precise, you have to do it like so: prefixes[CategoryID]=['prefix name', 'prefix name', 'prefix name'];

    Be aware of category order number is not the category id since you can order the categories however you like. You can see CategoryID either in the database table GDN_Category or when you look at the links in the category settings screen.
    But you might have guessed that already.

  • SkismaSkisma New
    edited January 2015

    @R_J‌ Ok so I've finally decided to suck it up and give this a go. I only have 3 categories that really need to have prefixes, so I hope I did this right. Here's what I've got:

    $(document).ready(function() {
    
      var prefixes = new Array();
      prefixes[forge-maps]=['MCC: H2A','MCC: H3','MCC: H4','Halo 4','Reach','Halo 3'];
      prefixes[general-maps]=['Unreal Engine','Unity','UT','Minecraft','Far Cry','Project Spark'];
      prefixes[general-game-discussion]=['Destiny','Call of Duty','Smite','Evolve'];
    
      $('#Form_CategoryID').on('change', function(e) {
        var prefixSelect = $('#Form_Prefix');
        prefixSelect.innerHTML = '<option value="-">-</option>';
        if (e.target.value >= 1 && e.target.value <= 3) { 
          $.each(prefixes[e.target.value], function(option) {
            prefixSelect.options[prefixSelect.options.length] = new Option(option, option);
          });
        }
      });
    });
    

    Edit: I'm not sure why the first line isn't embedded, but it's there.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    @Skisma said:
    R_J‌ Ok so I've finally decided to suck it up and give this a go. I only have 3 categories that really need to have prefixes, so I hope I did this right. Here's what I've got:

    And? What's happening?

    Not too much, I guess:

    >

          prefixes[forge-maps]=['MCC: H2A','MCC: H3','MCC: H4','Halo 4','Reach','Halo 3'];
          prefixes[general-maps]=['Unreal Engine','Unity','UT','Minecraft','Far Cry','Project Spark'];
          prefixes[general-game-discussion]=['Destiny','Call of Duty','Smite','Evolve'];
    
    
    

    ...

            if (e.target.value >= 1 && e.target.value <= 3) { 
              $.each(prefixes[e.target.value], function(option) {
    

    >

    You need to have integer keys for your array and you've used something

  • @R_J Funny thing about that is I was doing that here at work and after posting I couldn't find an option to save as a js file...so I'm having to wait until tonight when I get home to actually save the file and upload it.

    @R_J said: You need to have integer keys for your array and you've used something

    What do you mean by "you've used something"?

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    prefixes[forge-maps]=...

    You have two ways to define an array element: either by using a number
    prefixes[1]=...
    or by using a string
    prefixes['forge-maps']=... (associative array)

    You can define a variable and use that as an array key

    var forge-maps = 1;
    prefixes[forge-maps]=...
    

    But you haven't defined forge-maps before using it, so you are using basically an undefined variable, which - I think - will evaluate to zero.
    If your code above doesn't throw an error, I suspect you have done that: prefixes[forge-maps] = prefixes[general-maps] = prefixes[general-game-discussion] = array('Destiny','Call of Duty','Smite','Evolve') = prefixes[0]

    Don't know enough about JavaScript to now how your code will fail, but as long as you do not use integer keys for your array, it will fail ;)

  • subdreamersubdreamer San Jose, CA
    edited January 2015

    I haven't use this plugin yet but thank you for making it! You're awesome! :smiley:

    R_J
  • @R_J‌ Ahh I see, that makes perfect sense! I'm taking some courses on codecademy so hopefully I'll get the hang of things soon :smile:

    My only concern now that I think about it is, I only have 3 categories that need prefixes. Although I have a total of 14 categories. I don't know if that's going to cause problems, but I guess I'll just test this out when I get home!

    R_J
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator
    edited January 2015

    Great you're taking this courses! But you are right: you have done some theory and now it is time to get your hands dirty ;)

    You are right: having 3 categories that behave differently will need some other logic in the if clause. I think you will learn best, if you try to find the solution by yourself. If you are stuck give a note and I'll be happy to lead you in the right direction!

    Skisma
  • @R_J‌ Ok so I've found the CategoryID's and this is what I've got:

    $(document).ready(function () {

    var prefixes = new Array();
    prefixes[9] = ['MCC: H2A', 'MCC: H3', 'MCC: H4', 'Halo 4', 'Reach', 'Halo 3'];
    prefixes[11] = ['Unreal Engine', 'Unity', 'UT', 'Minecraft', 'Far Cry', 'Project Spark'];
    prefixes[15] = ['Destiny', 'Call of Duty', 'Smite', 'Evolve'];
    
    $('#Form_CategoryID').on('change', function (e) {
        var prefixSelect = $('#Form_Prefix');
        prefixSelect.innerHTML = '<option value="-">-</option>';
        if (e.target.value >= 1 && e.target.value <= 3) {
            $.each(prefixes[e.target.value], function (option) {
                prefixSelect.options[prefixSelect.options.length] = new Option(option, option);
            });
        }
    });
    

    });

    But I get this error when running the debugger:

    Unhandled exception at line 1, column 1 in ms-appx://08d97063-3c93-4273-ada4-6c8d93e3d836/js/default.js

    0x800a1391 - JavaScript runtime error: '$' is undefined

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    "Unhandled exception at line 1, column 1 in ms-appx://08d97063-3c93-4273-ada4-6c8d93e3d836/js/default.js"

    Sorry, but I have nothing to do with that default.js

  • @R_J Hey I must have overlooked this a while back when I got caught up on setting up my ranks. I put this code in a fresh js project file in VS and ran the debugger, got the error above. Does anyone know what could be wrong here?

«13
Sign In or Register to comment.