2016-04-05 17:57:26 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-10 10:23:27 +02:00
|
|
|
const views = require('../util/views.js');
|
2016-04-05 17:57:26 +02:00
|
|
|
const handlebars = require('handlebars');
|
|
|
|
const misc = require('./misc.js');
|
|
|
|
|
2016-04-06 22:34:21 +02:00
|
|
|
handlebars.registerHelper('reltime', function(time) {
|
2016-04-05 17:57:26 +02:00
|
|
|
return new handlebars.SafeString(
|
2016-04-10 10:23:27 +02:00
|
|
|
views.makeNonVoidElement(
|
|
|
|
'time',
|
|
|
|
{datetime: time, title: time},
|
|
|
|
misc.formatRelativeTime(time)));
|
2016-04-05 17:57:26 +02:00
|
|
|
});
|
2016-04-06 22:34:21 +02:00
|
|
|
|
2016-04-09 22:18:01 +02:00
|
|
|
handlebars.registerHelper('thumbnail', function(url) {
|
|
|
|
return new handlebars.SafeString(
|
2016-04-10 22:13:01 +02:00
|
|
|
views.makeNonVoidElement('span', {
|
2016-04-10 10:23:27 +02:00
|
|
|
class: 'thumbnail',
|
|
|
|
style: 'background-image: url(\'{0}\')'.format(url)
|
|
|
|
}, views.makeVoidElement('img', {alt: 'thumbnail', src: url})));
|
2016-04-09 22:18:01 +02:00
|
|
|
});
|
|
|
|
|
2016-04-06 22:34:21 +02:00
|
|
|
handlebars.registerHelper('toLowerCase', function(str) {
|
|
|
|
return str.toLowerCase();
|
|
|
|
});
|
2016-04-10 10:23:27 +02:00
|
|
|
|
|
|
|
handlebars.registerHelper('radio', function(options) {
|
|
|
|
return new handlebars.SafeString('{0}{1}'.format(
|
|
|
|
views.makeVoidElement('input', {
|
|
|
|
id: options.hash.id,
|
|
|
|
name: options.hash.name,
|
|
|
|
value: options.hash.value,
|
|
|
|
type: 'radio',
|
2016-04-10 15:55:56 +02:00
|
|
|
checked: options.hash.selectedValue === options.hash.value,
|
2016-04-10 10:23:27 +02:00
|
|
|
required: options.hash.required,
|
|
|
|
}),
|
|
|
|
views.makeNonVoidElement('label', {
|
|
|
|
for: options.hash.id,
|
|
|
|
class: 'radio',
|
|
|
|
}, options.hash.text)));
|
|
|
|
});
|
|
|
|
|
|
|
|
handlebars.registerHelper('checkbox', function(options) {
|
|
|
|
return new handlebars.SafeString('{0}{1}'.format(
|
|
|
|
views.makeVoidElement('input', {
|
|
|
|
id: options.hash.id,
|
|
|
|
name: options.hash.name,
|
|
|
|
value: options.hash.value,
|
|
|
|
type: 'checkbox',
|
|
|
|
required: options.hash.required,
|
|
|
|
}),
|
|
|
|
views.makeNonVoidElement('label', {
|
|
|
|
for: options.hash.id,
|
|
|
|
class: 'checkbox',
|
|
|
|
}, options.hash.text)));
|
|
|
|
});
|
|
|
|
|
|
|
|
handlebars.registerHelper('select', function(options) {
|
|
|
|
return new handlebars.SafeString('{0}{1}'.format(
|
|
|
|
views.makeNonVoidElement(
|
|
|
|
'label', {for: options.hash.id}, options.hash.text),
|
|
|
|
views.makeNonVoidElement(
|
|
|
|
'select',
|
|
|
|
{id: options.hash.id, name: options.hash.name},
|
|
|
|
Object.keys(options.hash.keyValues).map(key => {
|
|
|
|
return views.makeNonVoidElement(
|
|
|
|
'option',
|
|
|
|
{value: key, selected: key === options.hash.selectedKey},
|
|
|
|
options.hash.keyValues[key]);
|
|
|
|
}).join(''))));
|
|
|
|
});
|
|
|
|
|
|
|
|
handlebars.registerHelper('input', function(options) {
|
|
|
|
return new handlebars.SafeString('{0}{1}'.format(
|
|
|
|
views.makeNonVoidElement(
|
|
|
|
'label', {for: options.hash.id}, options.hash.text),
|
|
|
|
views.makeVoidElement(
|
|
|
|
'input', {
|
|
|
|
type: options.hash.inputType,
|
|
|
|
name: options.hash.name,
|
|
|
|
id: options.hash.id,
|
|
|
|
value: options.hash.value || '',
|
|
|
|
required: options.hash.required,
|
|
|
|
pattern: options.hash.pattern,
|
|
|
|
placeholder: options.hash.placeholder,
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
|
|
|
handlebars.registerHelper('textInput', function(options) {
|
|
|
|
options.hash.inputType = 'text';
|
|
|
|
return handlebars.helpers.input(options);
|
|
|
|
});
|
|
|
|
|
|
|
|
handlebars.registerHelper('passwordInput', function(options) {
|
|
|
|
options.hash.inputType = 'password';
|
|
|
|
return handlebars.helpers.input(options);
|
|
|
|
});
|
|
|
|
|
|
|
|
handlebars.registerHelper('emailInput', function(options) {
|
|
|
|
options.hash.inputType = 'email';
|
|
|
|
return handlebars.helpers.input(options);
|
|
|
|
});
|
2016-04-10 22:13:01 +02:00
|
|
|
|
|
|
|
handlebars.registerHelper('alignFlexbox', function(options) {
|
|
|
|
return new handlebars.SafeString(
|
|
|
|
Array.from(misc.range(20))
|
|
|
|
.map(() => '<li class="flexbox-dummy"></li>').join(''));
|
|
|
|
});
|