forked from simonwiles/palladio-webcomponents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
palladio-gallery-component.js
61 lines (54 loc) · 1.69 KB
/
palladio-gallery-component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import galleryComponentStyles from "bundle-text:./palladio-gallery-component.css";
import PalladioWebcomponentBase from "./palladio-webcomponent-base.js";
const defaultTemplate = `
<a target="_blank" class="link">
<div class="card">
<div class="image"></div>
<div class="title"></div>
<div class="subtitle"></div>
<div class="text"></div>
</div>
</a>
`;
window.customElements.define(
"palladio-gallery",
class extends PalladioWebcomponentBase {
constructor() {
super();
this.visType = "listView";
this.inlineStylesheets = [galleryComponentStyles];
}
onDataLoaded() {
const {
imgurlDim,
linkDim,
sortDim,
subtitleDim,
textDim,
titleDim,
} = this.settings;
const container = document.createElement("div");
container.classList.add("palladio-gallery");
if (sortDim) {
// Need some logic here to sort on non-string types
this.rows.sort((a, b) => a[sortDim].localeCompare(b[sortDim]));
}
this.rows.forEach((row) => {
const node = document
.createRange()
.createContextualFragment(defaultTemplate);
if (row[linkDim]) node.querySelector(".link").href = row[linkDim];
if (row[imgurlDim])
node.querySelector(
".image",
).style.backgroundImage = `url(${row[imgurlDim]})`;
node.querySelector(".title").innerText = row[titleDim];
node.querySelector(".subtitle").innerText = row[subtitleDim];
node.querySelector(".text").innerText = row[textDim];
container.appendChild(node);
});
this.body.innerHTML = "";
this.body.appendChild(container);
}
},
);