Hey everyone, I have a question. I was writing a plugin with plugin parameters, and I noticed that the default plugins hard-code the name of the file into their script like this:
var parameters = PluginManager.parameters('SimpleMsgSideView');
That seems like it could cause a problem if a user does not name their version of the plugin the same way that you anticipate (e.g. if a person does not call their plugin "SimpleMsgSideView.js"), so I was thinking of doing this instead:
// Get Script Name, in case user unexpectedly altered it
var path = document.currentScript.src;
var scriptName = path.substring(path.lastIndexOf('/')+1).match(/^(.+?)(\.[^.]*$|$)/)[1];
// Set Parameters
var parameters = PluginManager.parameters(scriptName);
I don't really know JavaScript well enough to anticipate if that will always work though or whether there are situations where the currentScript method won't actually return the right file name, so I was wondering if anyone with more experience knows whether there is a better way to overcome my anticipated problem, or whether it really even is a problem.
Thanks!
It's only today that I saw this. Do you mean the ability to get the parameters without considering which file name is used?
you can do:
var params = $plugins.filter(function(p) { return p.description.contains('<ModernAlgebraPlugin>'); })[0].parameters;
Anything that is contained in there such as params, desc and filename will be contained.