@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.
@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:
@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
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
@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
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!
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!
@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?
When you put this in a "fresh project" you run the script not in the scope of Vanilla. Vanilla first loads some scripts/libraries that need to exist in order that your script can be executed.
Don't learn js by using Visual Studio! Get the basics with a simple html file that references a simple js file. If you create a project in any IDE, it will most probably blow up and do magic that you can not understand if you are new to the IDE.
If you set up those basic files you can use VS as a nice file editor.
In order to mess around with js in Vanilla, you can set up a very simple plugin that includes a js file and then insert your test code there.
Oh ok, I just used VS because that's the only program I know of where I can write a js file. Basically, I figured I'd use VS to save the js file, then put it in the location you mentioned here:
@R_J said:
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:
Since this method isn't ideal, what is the name of the plugin where I can test my js code? Also, what do you recommend I use to actually save the file?
I don't know VS, I simply suspect that you cannot use a Project. Just use it to edit a single file. That's okay.
The VS debugger will not be able to help you: it does not "know" about the context the script is run. So you would have to open your browser and open up the page that contains your js file. It should be loaded when you start a new discussion.
Insert alert('YEAH!'); as the first line in your js to see if it is loaded and executed.
So you would have to open your browser and **open up the page that contains your js file. It should be loaded when you start a new discussion. **
Sorry for being a noob, but can you expand on this part a bit? Is this a method for debugging, by adding the script to a page and starting a new discussion?
I don't know much about the best way to debug JavaScript or even a good way to do so. I can just tell you what I do. I use Firefox with Firebug extension, but I guess you can do it with nearly all current browsers: open the developer console (however it is called) of your browsers, take a look at the scripts section there and at least Firebug allows you to debug code by setting breakpoints, do single step execution, etc.
So I write the plugin that adds my js to the page, edit the javascript file and load them up to the server (either remote or local test server). After enabling the plugin I open the page where this javascript should be added (the plugin should do this) and when I look at the html source code of the page, I check if the script is really loaded.
If yes, I can debug it in the browser and improve the js code (by editing the source, uploading, reloading page).
If not, my plugin is not working correctly (happens from time to time).
Ok, I understand! Only thing is, I would never be able to write my own plugin (at least not at this time). Is there one you have or can recommend? @R_J
Oh wait - in the beginning you wanted to add js to a plugin of mine to extend its functionality, right? And then I've shown you how to add your own js file to the plugin. And then you had problems with the VS debugger. And then I told you not to use that one.
So from my point of view it looks like you should already have my plugin "DiscussionPrefix", you should already know how to add a js file to it, know how to debug the javascript.
So I'm not sure any more if I know what exactly you try to achieve, so it's really hard for me to recommend you anything... :-/
@R_J Lol! It seems that you and I are confusing each other. Ok great. So I'll just add the script to your plugin where it needs to go, and then debug it from within firefox. I thought you were saying there is a specific plugin where I could add this js file to a page and debug it from within the browser. In reality, you were just saying to get this added where I needed it, then debug it from there. Ok I'll give this a shot, thank you!
Comments
@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:
Edit: I'm not sure why the first line isn't embedded, but it's there.
And? What's happening?
Not too much, I guess:
>
>
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.
What do you mean by "you've used something"?
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
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
I haven't use this plugin yet but thank you for making it! You're awesome!
@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
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!
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!
@R_J Ok so I've found the CategoryID's and this is what I've got:
$(document).ready(function () {
});
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
"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?
When you put this in a "fresh project" you run the script not in the scope of Vanilla. Vanilla first loads some scripts/libraries that need to exist in order that your script can be executed.
Don't learn js by using Visual Studio! Get the basics with a simple html file that references a simple js file. If you create a project in any IDE, it will most probably blow up and do magic that you can not understand if you are new to the IDE.
If you set up those basic files you can use VS as a nice file editor.
In order to mess around with js in Vanilla, you can set up a very simple plugin that includes a js file and then insert your test code there.
Oh ok, I just used VS because that's the only program I know of where I can write a js file. Basically, I figured I'd use VS to save the js file, then put it in the location you mentioned here:
Since this method isn't ideal, what is the name of the plugin where I can test my js code? Also, what do you recommend I use to actually save the file?
I don't know VS, I simply suspect that you cannot use a Project. Just use it to edit a single file. That's okay.
The VS debugger will not be able to help you: it does not "know" about the context the script is run. So you would have to open your browser and open up the page that contains your js file. It should be loaded when you start a new discussion.
Insert
alert('YEAH!');
as the first line in your js to see if it is loaded and executed.So you would have to open your browser and **open up the page that contains your js file. It should be loaded when you start a new discussion. **
Sorry for being a noob, but can you expand on this part a bit? Is this a method for debugging, by adding the script to a page and starting a new discussion?
I don't know much about the best way to debug JavaScript or even a good way to do so. I can just tell you what I do. I use Firefox with Firebug extension, but I guess you can do it with nearly all current browsers: open the developer console (however it is called) of your browsers, take a look at the scripts section there and at least Firebug allows you to debug code by setting breakpoints, do single step execution, etc.
So I write the plugin that adds my js to the page, edit the javascript file and load them up to the server (either remote or local test server). After enabling the plugin I open the page where this javascript should be added (the plugin should do this) and when I look at the html source code of the page, I check if the script is really loaded.
If yes, I can debug it in the browser and improve the js code (by editing the source, uploading, reloading page).
If not, my plugin is not working correctly (happens from time to time).
Ok, I understand! Only thing is, I would never be able to write my own plugin (at least not at this time). Is there one you have or can recommend? @R_J
I cannot recommend anything when you don't specify what you need ;-)
I would recommend to look at that when you want to get an overview what is possible: https://github.com/hgtonight/Plugin-TestingGround
Oh wait - in the beginning you wanted to add js to a plugin of mine to extend its functionality, right? And then I've shown you how to add your own js file to the plugin. And then you had problems with the VS debugger. And then I told you not to use that one.
So from my point of view it looks like you should already have my plugin "DiscussionPrefix", you should already know how to add a js file to it, know how to debug the javascript.
So I'm not sure any more if I know what exactly you try to achieve, so it's really hard for me to recommend you anything... :-/
@R_J Lol! It seems that you and I are confusing each other. Ok great. So I'll just add the script to your plugin where it needs to go, and then debug it from within firefox. I thought you were saying there is a specific plugin where I could add this js file to a page and debug it from within the browser. In reality, you were just saying to get this added where I needed it, then debug it from there. Ok I'll give this a shot, thank you!
Sounds more promising this way