User:KokoroSenshi/common.js: Difference between revisions
From Zelda Wiki, the Zelda encyclopedia
Fix?
KokoroSenshi (talk | contribs) (Refactored to be more general, though under simplified assumptions; not fully tested) |
KokoroSenshi (talk | contribs) (Fix?) |
||
Line 10: | Line 10: | ||
* Bugs: | * Bugs: | ||
* - The regex fails if there is an instance of {{Color| before it in the textarea? tho it's fine in the example webpage | * - The regex fails if there is an instance of {{Color| before it in the textarea? tho it's fine in the example webpage | ||
* - In addition, | * - In addition, when you start a "{{Color|", then pop over to a different "{{Color|", it'll show dropdown, but append to the first "{{Color|"" | ||
* | * | ||
*/ | */ | ||
Line 21: | Line 21: | ||
"Color", | "Color", | ||
function() { | function() { | ||
var self = this; | |||
$.get( "https://zelda.gamepedia.com/Template:Color?action=raw", function( data ) { | $.get( "https://zelda.gamepedia.com/Template:Color?action=raw", function( data ) { | ||
/** Store parameter options in instance variable */ | /** Store parameter options in instance variable */ | ||
params["1"] = readColorArrayFromString(data); | self.params["1"] = readColorArrayFromString(data); | ||
/** Callback */ | /** Callback */ | ||
registerStrategies(); | self.registerStrategies(); | ||
}); | }); | ||
Line 78: | Line 80: | ||
function TemplateStrategy(templateName, getParametersFunction) { | function TemplateStrategy(templateName, getParametersFunction) { | ||
var self = this; | |||
/** | /********************* | ||
** Public variables ** | |||
**********************/ | |||
this.templateName = templateName; | |||
this.params = {}; // params.<name_of_param> = array of options // should each param have a 'description' variable too? applicable to both preset options and open-ended | |||
this.strategies = []; | |||
/******************** | /******************** | ||
** Public methods ** | |||
********************/ | |||
/** | /** | ||
Line 93: | Line 97: | ||
*/ | */ | ||
this.register = function() { | this.register = function() { | ||
getParameters(); // Must have callback to registerStrategies() | self.getParameters(); // Must have callback to registerStrategies() | ||
}; | }; | ||
this.getParameters = getParametersFunction; | |||
var | this.registerStrategies = function() { | ||
var params = self.params; | |||
var strategies = self.strategies; | |||
/** | |||
/** Validate parameters */ | |||
console.log("params: "); | console.log("params: "); | ||
console.log(params); | console.log(params); | ||
Line 120: | Line 123: | ||
precedingParamRegex += "\\|[^\\|]*"; | precedingParamRegex += "\\|[^\\|]*"; | ||
} | } | ||
var strategy = createStrategy( | var strategy = self.createStrategy( | ||
templateName, | templateName, | ||
paramName, | paramName, | ||
Line 146: | Line 149: | ||
}; | }; | ||
this.createStrategy = function(name, param, match, search, template, replace) { | |||
var strategy = | var strategy = | ||
{ | { |