mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #687 from kiwix/langCatBoxFill
Add undefined check for humanFriendlyTitle
This commit is contained in:
commit
ceb46f1069
|
@ -53,8 +53,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const humanFriendlyTitle = (title) => {
|
const humanFriendlyTitle = (title) => {
|
||||||
|
if (typeof title === 'string' && title.length > 0) {
|
||||||
title = title.replace(/_/g, ' ');
|
title = title.replace(/_/g, ' ');
|
||||||
return htmlEncode(title[0].toUpperCase() + title.slice(1));
|
return htmlEncode(title[0].toUpperCase() + title.slice(1));
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function htmlEncode(str) {
|
function htmlEncode(str) {
|
||||||
|
@ -238,7 +242,8 @@
|
||||||
data.querySelectorAll('entry').forEach(entry => {
|
data.querySelectorAll('entry').forEach(entry => {
|
||||||
const title = getInnerHtml(entry, 'title');
|
const title = getInnerHtml(entry, 'title');
|
||||||
const value = getInnerHtml(entry, valueEntryNode);
|
const value = getInnerHtml(entry, valueEntryNode);
|
||||||
optionStr += `<option value="${value}">${humanFriendlyTitle(title)}</option>`;
|
const hfTitle = humanFriendlyTitle(title);
|
||||||
|
optionStr += (hfTitle != '') ? `<option value="${value}">${hfTitle}</option>` : '';
|
||||||
});
|
});
|
||||||
document.querySelector(nodeQuery).innerHTML += optionStr;
|
document.querySelector(nodeQuery).innerHTML += optionStr;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue