Browse Source

Fix empty card texts with images, fix dimensions for shared image card results

main
indigane 4 years ago committed by GitHub
parent
commit
ed38ac3d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      card-sort.html

12
card-sort.html

@ -288,6 +288,7 @@
function createCard(text, categoryGrid) { function createCard(text, categoryGrid) {
const targetGrid = categoryGrid || uncategorizedCardsGrid; const targetGrid = categoryGrid || uncategorizedCardsGrid;
const itemElement = document.importNode(cardTemplate.content.children[0], true); const itemElement = document.importNode(cardTemplate.content.children[0], true);
const cardElement = itemElement.querySelector('.card');
const hasImage = text.match(cardImageRegex); const hasImage = text.match(cardImageRegex);
if (hasImage) { if (hasImage) {
const [textBefore, imageUrl, textAfter] = text.split(cardImageRegex); const [textBefore, imageUrl, textAfter] = text.split(cardImageRegex);
@ -300,7 +301,7 @@
} }
const imageElement = document.createElement('img'); const imageElement = document.createElement('img');
imageElement.className = 'card-image'; imageElement.className = 'card-image';
imageElement.onload = () => uncategorizedCardsGrid.refreshItems().layout(); imageElement.onload = () => targetGrid.refreshItems().layout();
imageElement.src = imageUrl; imageElement.src = imageUrl;
cardChildElements.push(imageElement); cardChildElements.push(imageElement);
if (textAfter.trim()) { if (textAfter.trim()) {
@ -309,11 +310,12 @@
span.appendChild(document.createTextNode(textAfter)); span.appendChild(document.createTextNode(textAfter));
cardChildElements.push(span); cardChildElements.push(span);
} }
itemElement.querySelector('.card').replaceChildren(...cardChildElements); cardElement.replaceChildren(...cardChildElements);
} }
else { else {
itemElement.querySelector('.card').textContent = text; cardElement.textContent = text;
} }
cardElement.setAttribute('data-text', text);
targetGrid.show( targetGrid.show(
targetGrid.add([itemElement], { targetGrid.add([itemElement], {
active: false, active: false,
@ -389,12 +391,12 @@
} }
data[categoryName] = []; data[categoryName] = [];
for (const cardElement of categoryElement.querySelectorAll('.card')) { for (const cardElement of categoryElement.querySelectorAll('.card')) {
data[categoryName].push(cardElement.textContent); data[categoryName].push(cardElement.getAttribute('data-text'));
} }
} }
data[uncategorizedKey] = []; data[uncategorizedKey] = [];
for (const cardElement of document.querySelectorAll('.uncategorized-cards .card')) { for (const cardElement of document.querySelectorAll('.uncategorized-cards .card')) {
data[uncategorizedKey].push(cardElement.textContent); data[uncategorizedKey].push(cardElement.getAttribute('data-text'));
} }
data[settingsFlagsKey] = saveSettings(settings); data[settingsFlagsKey] = saveSettings(settings);
} }

Loading…
Cancel
Save