-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathget-icon.js
More file actions
56 lines (56 loc) · 2.28 KB
/
get-icon.js
File metadata and controls
56 lines (56 loc) · 2.28 KB
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
/*
get a theme icon based on display_template or format
return svg sprite
*/
function getIcon(objectTemplate,objectFormat,svgType) {
var iconTemplate, iconId, iconTitle;
if (objectTemplate && objectTemplate != "") {
iconTemplate = objectTemplate;
} else if (objectFormat && objectFormat != "") {
iconTemplate = objectFormat;
} else {
iconTemplate = ""
}
// choose icon
if (iconTemplate.includes("image")) {
iconId = "icon-image";
iconTitle = "image file icon";
} else if (iconTemplate.includes("pdf")) {
iconId = "icon-pdf";
iconTitle = "pdf file icon";
} else if (iconTemplate.includes("video")) {
iconId = "icon-video";
iconTitle = "video file icon";
} else if (iconTemplate.includes("audio")) {
iconId = "icon-audio";
iconTitle = "audio file icon";
} else if (iconTemplate.includes("panorama")) {
iconId = "icon-panorama";
iconTitle = "panorama file icon";
} else if (iconTemplate.includes("markdown")) {
iconId = "icon-markdown";
iconTitle = "markdown file icon";
} else if (iconTemplate.includes("compound")) {
iconId = "icon-compound-object";
iconTitle = "compound object icon";
} else if (iconTemplate.includes("multiple")) {
iconId = "icon-multiple";
iconTitle = "multiple object icon";
} else if (iconTemplate.includes("record")) {
iconId = "icon-record";
iconTitle = "record object icon";
} else {
iconId = "icon-default";
iconTitle = "file icon";
}
if (svgType == "thumb") {
// svg sprite as thumb
return '<svg class="bi text-body img-fluid" fill="currentColor" role="img"><title>' + iconTitle + '</title><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#' + iconId + '"/></svg>';
} else if (svgType == "hidden") {
// svg as sprite with aria-hidden
return '<svg class="bi icon-sprite" aria-hidden="true"><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#' + iconId + '"/></svg>';
} else {
// svg as sprite
return '<svg class="bi icon-sprite" aria-label="' + iconTitle + '"><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#' + iconId + '"/></svg>';
}
}