Files
mixtape/zero.Backoffice.UI/app/directives/v-placeholder.ts
T
2021-12-06 16:18:58 +01:00

33 lines
811 B
TypeScript

import { localize } from '../services/localization';
/**
* Localizes the given property and sets the inner-text of the node to its result
*/
export default (el, binding) =>
{
if (binding.value !== binding.oldValue || !el.innerText)
{
const hasValue = !!binding.value;
const isObject = typeof binding.value === 'object';
let value = hasValue ? (isObject ? binding.value.placeholder : binding.value) : null;
let result = null;
if (isObject && typeof value === 'function')
{
if (typeof binding.value.model === 'undefined')
{
// TODO throw warning
return;
}
result = value(binding.value.model);
}
else
{
result = value;
}
result = hasValue ? localize(result) : '';
el.setAttribute('placeholder', result);
}
};