Update mod.js (#270)

This commit is contained in:
Ryo Hilmawan 2020-11-19 03:09:17 +07:00 committed by GitHub
parent 7949d6e451
commit 0064ae35dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -177,13 +177,14 @@ module.exports = {
: `${iconData.sourceUrl}/${iconData.source}_${i}.${iconData.extension}`
: iconData.source[i];
const icon = createElement(`<div class="notion-icons--icon"><img src="${iconUrl}" /></div>`);
iconSetBody.append(icon);
garbageCollector.push(icon);
icon.addEventListener('click', () => setPageIcon(iconUrl));
// Make sure elements load
const icon = createElement(`<div class="notion-icons--icon"></div>`);
if (iconData.enhancerIcons) {
// Load sprite sheet
icon.innerHTML =
`<div style="width: 32px; height: 32px; background: url(${iconsUrl}${iconData.source}/sprite.png) 0 -${i * 32}px no-repeat; background-size: cover;"></div>`;
} else {
icon.innerHTML = `<img src="${iconUrl}" />`;
// Make sure icons load
promiseArray.push(
new Promise((resolve, reject) => {
icon.firstChild.onload = resolve;
@ -196,6 +197,11 @@ module.exports = {
);
}
iconSetBody.append(icon);
garbageCollector.push(icon);
icon.addEventListener('click', () => setPageIcon(iconUrl));
}
// Hide spinner after all icons finish loading
(async () => {
const spinner = iconSetToggle.querySelector('.notion-icons--spinner'),
@ -265,6 +271,7 @@ module.exports = {
if (notionIconsData && notionIconsData.icons) {
notionIconsData.icons.forEach(i => {
i.sourceUrl = i.sourceUrl || (iconsUrl + i.source);
i.enhancerIcons = true;
iconSets.push( renderIconSet(i) );
});
}