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