search closest article, if element doesn't have an id

This commit is contained in:
ItsVipra 2023-07-11 14:26:03 +02:00
parent f726843809
commit ff78899cc7

View file

@ -215,13 +215,18 @@ async function addProplate(element) {
* @returns {string}
*/
function getID(element) {
const id = element.dataset.id;
let id = element.dataset.id;
if (!id) {
// We don't have a status ID, pronouns might not be in cache
warn(
"The element passed to addProplate does not have a data-id attribute, although it should have one.",
"The element passed to addProplate does not have a data-id attribute, searching for article.",
element,
);
//if we couldn't get an id from the div try the closest article
const ArticleElement = element.closest("article");
if (ArticleElement) {
id = getID(ArticleElement);
}
}
return id;
}