add dropdown component
This commit is contained in:
@ -65,7 +65,7 @@
|
||||
|
||||
lgres.init(document.body, {
|
||||
template: '/res.json',
|
||||
callback: (res) => document.title = res.r('title', 'Default Title')
|
||||
callback: res => document.title = res.r('title', 'Default Title')
|
||||
}).then(res => {
|
||||
document.querySelector('#header').innerText = res.r('header', 'My Header');
|
||||
const msg = lgres.lang.unknownError;
|
||||
|
@ -66,6 +66,7 @@ async function refreshLgres(template, lgres) {
|
||||
Object.defineProperty(lgres, 'r', {
|
||||
writable: false,
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
value: function (key, defaultValue) {
|
||||
return getLanguage(this, key, defaultValue);
|
||||
}
|
||||
@ -76,16 +77,11 @@ async function refreshLgres(template, lgres) {
|
||||
|
||||
function getLanguage(lgres, key, defaultValue) {
|
||||
let value = lgres[key];
|
||||
if (value == null) {
|
||||
value = defaultValue;
|
||||
}
|
||||
return value;
|
||||
return value ?? defaultValue;
|
||||
}
|
||||
|
||||
function applyLanguage(dom, result) {
|
||||
if (dom == null) {
|
||||
dom = document.body;
|
||||
}
|
||||
dom ??= document.body;
|
||||
for (let text of dom.querySelectorAll('[data-lgid]')) {
|
||||
const key = text.getAttribute('data-lgid');
|
||||
if (text.tagName === 'INPUT') {
|
||||
|
@ -103,7 +103,7 @@ request.post('api/query', { id: 101 })
|
||||
.then(result => console.log(result.data));
|
||||
|
||||
request.upload('api/upload', data, {
|
||||
progress: (ev) => {
|
||||
progress: ev => {
|
||||
console.log(`loaded: ${ev.loaded}, total: ${ev.total}`);
|
||||
}
|
||||
})
|
||||
|
@ -26,10 +26,7 @@ function padStart(s, num, char) {
|
||||
if (nullOrEmpty(s) || isNaN(num) || num <= s.length) {
|
||||
return s;
|
||||
}
|
||||
if (char == null) {
|
||||
char = ' ';
|
||||
}
|
||||
return char.repeat(num - s.length);
|
||||
return (char ?? ' ').repeat(num - s.length);
|
||||
}
|
||||
|
||||
export {
|
||||
|
Reference in New Issue
Block a user