Start working on the Stats Viewer application
This commit is contained in:
parent
cb3bc7c86c
commit
91863d85a8
18 changed files with 422 additions and 1 deletions
6
module/handlebarsHelpers/_index.mjs
Normal file
6
module/handlebarsHelpers/_index.mjs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { options } from "./options.mjs";
|
||||
|
||||
export default {
|
||||
// #region Complex
|
||||
"st-options": options,
|
||||
};
|
||||
33
module/handlebarsHelpers/options.mjs
Normal file
33
module/handlebarsHelpers/options.mjs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* @typedef {object} Option
|
||||
* @property {string} [label]
|
||||
* @property {string|number} value
|
||||
* @property {boolean} [disabled]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string | number} selected
|
||||
* @param {Array<Option | string>} opts
|
||||
* @param {any} meta
|
||||
*/
|
||||
export function options(selected, opts) {
|
||||
selected = Handlebars.escapeExpression(selected);
|
||||
const htmlOptions = [];
|
||||
|
||||
for (let opt of opts) {
|
||||
if (typeof opt === `string`) {
|
||||
opt = { label: opt, value: opt };
|
||||
};
|
||||
opt.value = Handlebars.escapeExpression(opt.value);
|
||||
htmlOptions.push(
|
||||
`<option
|
||||
value="${opt.value}"
|
||||
${selected === opt.value ? `selected` : ``}
|
||||
${opt.disabled ? `disabled` : ``}
|
||||
>
|
||||
${ opt.label }
|
||||
</option>`,
|
||||
);
|
||||
};
|
||||
return new Handlebars.SafeString(htmlOptions.join(`\n`));
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue