Anonymous

User:KokoroSenshi/common.js: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Fix?
(Refactored to be more general, though under simplified assumptions; not fully tested)
(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, whenyou start a "{{Color|", then pop over to a different "{{Color|", it'll show dropdown, but append to the first "{{Color|""
  * - 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) {
/** Public variables */
var self = this;
this.templateName = templateName;
/** Private variables */
/*********************
var params = {}; // params.<name_of_param> = array of options // should each param have a 'description' variable too? applicable to both preset options and open-ended
** Public variables **
var strategies = [];
**********************/
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 **
** 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;
** Private methods **
*********************/
var getParameters = getParametersFunction;
this.registerStrategies = function() {
var params = self.params;
var registerStrategies = function() {
var strategies = self.strategies;
/** Parameters are in instance variable */
/** 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:
};
};
var createStrategy = function(name, param, match, search, template, replace) {
this.createStrategy = function(name, param, match, search, template, replace) {
var strategy =
var strategy =
{
{
3,972

edits