Fallen London Wiki:Calculators
Fallen London Wiki uses a calculator script adapted from Runescape Wiki (GPLv3): MediaWiki:Common.js/calc.js.
Runescape Wiki has its own documentation for the script; yet the adapted version has a number of differences.
The scope of calculator forms:
- Provide a convenient user interface for template and module function evaluations
- Validate inputs
- Cache previous inputs in localStorage, if it is available
- Automatically reevaluate the result on input changes, if configured so
Configuration[edit]
General format[edit]
<pre class="jcConfig">
line 1
line 2
line 3
...
</pre>
<div id="FORM_ID"></div>
<div id="RESULT_ID"></div>
Each line has the form of key = value.
Supported keys[edit]
name[edit]
The entry is optional; the default value is Calculator.
namevalue is the header-like text shown above the calculator form. Note that wikitext is not evaluated inside ofpre.
form, result[edit]
Both entries are required.
formvalue is a string. The valid characters are: lettersA-Za-z, digits0-9, separators_-. The first symbol must be a letter. The string is the HTML id of the corresponding form (marked asFORM_IDabove); therefore it must be unique in the page in case there are multiple calculators.resultvalue is a string. The valid characters are: lettersA-Za-z, digits0-9, separators_-. The first symbol must be a letter. The string is the HTML id of the corresponding calculator output (marked asRESULT_IDabove); therefore it must be unique in the page in case there are multiple calculators.
template, module, modulefunc[edit]
One of template, module entries is required.
modulefunc is optional; the default value is main.
templatevalue is a wiki page name of the template which is to be evaluated by the form. You may omit theTemplate:prefix.modulevalue is a wiki page name of the Lua module containing the function to be evaluated by the form.modulefuncvalue is the name of the module function to be evaluated. Only used ifmoduleis specified.
suggestns[edit]
The entry is optional.
suggestnsvalue is a,-separated list of wiki namespace names or ids. If the form contains inputs ofarticletype, only the pages from the specified namespaces will be suggested.
autosubmit[edit]
The entry is optional; the default value is off.
autosubmitvalue is one of the following:off,option,on.off: autosubmit is disabled and cannot be enabled.option: a toggle switching autosubmit is shown below the submit button.on: autosubmit is enabled and cannot be disabled.
When autosubmit is enabled, editing an input triggers form submission and result reevaluation. Avoid enabling it if the result might be computationally expensive.
param[edit]
The entry is expected to be repeated multiple times, each entry is parsed independently.
paramvalue is a|-separated list of strings. A variable number of arguments can be specified; missing values will be interpreted as empty. For further details, see the next section.
Supported parameters[edit]
Parameter value format: param|label|default|type|range|toggles|help
paramis the name of the argument passed to the template or to the module function. If it is a numbered argument, specify its number explicitly.labelis the label displayed to the user alongside the input.defaultis the default value associated with the input.togglesis the specification of which other inputs are to be enabled/disabled depending on the value of this input:- Can be applied to parameters of types
select,buttonselect,combobox,check,toggleswitch,togglebutton,int,number. - The format of
togglesis: a;-separated list of toggle entries; - The format of a toggle entry is:
values=ids; - The format of
valuesis: a,-separated list of possible values of this input;- If the values are not specified explicitly in
rangesfor the element, usetrue/falsefor inputs of typescheck,toggleswitch,togglebutton. For inputs of typesint,number,floatyou can also usenot0for non-zero values.- You can omit the
values=part entirely for the listed inputs; it will be interpreted astrueornot0.
- You can omit the
- If the values are not specified explicitly in
- The format of
idsis: a,-separated list of ids (paramvalues) of input elements enabled with the specified values. - Only the inputs with ids specified in
togglewill be affected; if one is specified, it will be disabled with all values for which the corresponding id is not explicitly marked as enabled.
- Can be applied to parameters of types
helpis the HTML text shown (if non-empty) in a tooltip near the input.
The rest of parameters may be interpreted differently depending on type:
string[edit]
This is the default input type. Shows a textbox.
range is ignored.
article[edit]
Shows a textbox; auto-completion shows suggestions based on the suggestns value.
Only existing page names are considered valid.
range is ignored.
int[edit]
Shows a textbox with +/- buttons. Only integer numbers are considered valid.
range specifies the valid value range in the format: min-max.
- Negative values are allowed:
-3--1is a range from-3to-1. - If
minormaxare omitted, they are assumed to be negative/positive infinities.
Optionally, you may use the min-max;step;bstep format:
- Valid values must be multiples of
stepvalue. Default:1forint,0.01fornumber,float. bstepis the step of +/- buttons.
number, float[edit]
Those types are equivalent. Shows a textbox with +/- buttons. Only real numbers are considered valid.
range is the same as for int.
check, toggleswitch, togglebutton[edit]
The types are essentially equivalent and differ only in visual representation:
checkis a checkbox.toggleswitchis a toggle.togglebuttonis a button that can be toggled on and off.
range has the form ENABLED,DISABLED if there are no ; characters in the string; otherwise, ENABLED;DISABLED (, may be used both in ENABLED and DISABLED in this case).
select, buttonselect, combobox[edit]
The types are essentially equivalent and differ only in visual representation:
selectis a drop-down list.buttonselectis a group of buttons aligned in a horizontal row.comboboxis a textbox with auto-completion; only the predefined values are valid.
range is a ,-separated list of recognised values if there are no ; characters in the string; otherwise, a ;-separated list (, may be used in individual entries in this case).
fixed[edit]
Like string, but cannot be edited.
range is ignored.
[edit]
Like string, but cannot be edited or seen.
range is ignored.
group[edit]
The specified inputs are grouped. These inputs must be below the group entry.
Groups may be specified in toggles.
range is a ,-separated list of input ids.
Examples[edit]
See the page source for configuration.
Different parameters[edit]
<pre class="jcConfig">
name = Different parameters test
template = T
form = parameters1
result = result1
suggestns = 0
param = 1|String parameter|T
param = 2|Int parameter (2-4)|3|int|2-4
param = 3|Float parameter (-3.4 - -0.9)|-1.1|number|-3.4--0.9
param = 4|Acticle parameter||article
param = selects|Selects||group|5,6,7
param = 5|Select parameter|item 1|select|item 1,item 2,item 3
param = 6|Buttonselect parameter|-1|buttonselect|-1,-2,-3
param = 7|Combobox parameter||combobox|aaa,aab,aba,abb,baa,bab,bba,bbb
param = toggles|Toggles||group|8,9,Style
param = 8|Check parameter||check|check1,check0
param = 9|Togglebutton parameter||togglebutton|togglebutton1,togglebutton0
param = Style|Style as values?||toggleswitch|Val,Var||If enabled, the arguments will not be grey and in brackets
</pre>
<div id="parameters1">Loading...</div>
<div id="result1"></div>
yields
name = Different parameters test template = T form = parameters1 result = result1 suggestns = 0 param = 1|String parameter|T param = 2|Int parameter (2-4)|3|int|2-4 param = 3|Float parameter (-3.4 - -0.9)|-1.1|number|-3.4--0.9 param = 4|Acticle parameter||article param = selects|Selects||group|5,6,7 param = 5|Select parameter|item 1|select|item 1,item 2,item 3 param = 6|Buttonselect parameter|-1|buttonselect|-1,-2,-3 param = 7|Combobox parameter||combobox|aaa,aab,aba,abb,baa,bab,bba,bbb param = toggles|Toggles||group|8,9,Style param = 8|Check parameter||check|check1,check0 param = 9|Togglebutton parameter||togglebutton|togglebutton1,togglebutton0 param = Style|Style as values?||toggleswitch|Val,Var||If enabled, the arguments will not be grey and in brackets
Toggled inputs[edit]
name = Toggled inputs test template = T form = parameters2 result = result2 param = 1||T|hidden param = tog|Parameters|0|buttonselect|0,1,2|1=2;2=2,3 param = 2|Parameter 1| param = 3|Parameter 2|
Modules & optional autosubmit[edit]
name = Module & optional autosubmit test module = String modulefunc = len form = parameters3 result = result3 autosubmit = option param = 1|String|
Autosubmit[edit]
name = Autosubmit test template = T form = parameters4 result = result4 autosubmit = on param = 1|String|