-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcustomelements.js
More file actions
162 lines (129 loc) · 4.78 KB
/
customelements.js
File metadata and controls
162 lines (129 loc) · 4.78 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
class DownloadElement extends HTMLElement {
constructor() {
super();
const link = this.getAttribute("url");
const title = this.getAttribute("title");
const icon = this.getAttribute("icon");
const anchor = document.createElement("a");
anchor.setAttribute("part", "dl");
anchor.classList.add("dl");
anchor.href = link;
anchor.target = "_blank";
// Container
const container = document.createElement("div");
container.classList.add("download");
// Icon section
const icondiv = document.createElement("div");
icondiv.classList.add("icon");
const iconSpan = document.createElement("span");
iconSpan.classList.add("material-symbols-sharp");
iconSpan.classList.add("notranslate");
iconSpan.textContent = icon;
icondiv.appendChild(iconSpan);
// File & title section
const file = document.createElement("div");
file.classList.add("file");
const fileTitle = document.createElement("span");
fileTitle.textContent = title;
file.appendChild(fileTitle);
const fileName = document.createElement("b");
fileName.textContent = GetFilenameFromURL(link);
file.appendChild(fileName);
// Add icon/file blocks into main wrapper div
container.appendChild(icondiv);
container.appendChild(file);
// Then add it into <A>
anchor.appendChild(container);
// Return
this.appendChild(anchor);
}
}
class ArticleHeader extends HTMLElement {
constructor() {
super();
const name = this.getAttribute("name");
const icon = this.getAttribute("icon");
const category = this.getAttribute("category");
let wrapper = document.createElement("div");
wrapper.classList.add("ArticleHeader");
let icondiv = document.createElement("div");
icondiv.classList.add("icon");
let iconspan = document.createElement("span");
iconspan.classList.add("material-symbols-sharp");
iconspan.classList.add("notranslate");
let datadiv = document.createElement("div")
datadiv.classList.add("description");
let cat = document.createElement("span");
let header = document.createElement("h1");
iconspan.textContent = icon;
cat.textContent = category;
header.textContent = name;
datadiv.appendChild( cat );
datadiv.appendChild( header );
icondiv.appendChild( iconspan );
wrapper.appendChild( icondiv );
wrapper.appendChild( datadiv );
this.appendChild( wrapper );
}
}
class ArticleRef extends HTMLElement {
constructor()
{
super();
const link = this.getAttribute( "link" );
this.classList.add("ref");
this.onclick = function() {
DisplayCategory( link );
}
}
}
class NavigationItem extends HTMLElement {
constructor()
{
super();
let internalName = this.getAttribute( "link" );
let icon = this.getAttribute( "icon" );
let a = document.createElement( "a" );
let span = document.createElement( "span" );
span.classList.add( "material-symbols-sharp" );
span.classList.add( "notranslate" );
span.textContent = icon;
let displayname = document.createElement( "k" ); // this isn't real lol
displayname.textContent = this.textContent;
this.innerHTML = '';
this.appendChild( span );
this.appendChild( displayname );
this.setAttribute( "category", internalName );
this.onclick = function() {
DisplayCategory( internalName );
}
}
}
class Contributor extends HTMLElement
{
constructor()
{
super();
let name = this.getAttribute( "name" );
let url = this.getAttribute( "url" ); // URL as any link to user's website, or GitHub link
let icon = this.getAttribute( "icon" ); // Expected to be URL too
let div = document.createElement( "div" );
let img = document.createElement( "img" );
let text = document.createElement( "div" );
img.setAttribute( "src", icon );
text.textContent = name;
text.classList.add( "name" );
div.classList.add( "contributor" );
div.appendChild( img );
div.appendChild( text );
this.appendChild( div );
this.onclick = function() {
window.open( url, "_blank" );
}
}
}
customElements.define( "download-file", DownloadElement );
customElements.define( "article-header", ArticleHeader );
customElements.define( "article-ref", ArticleRef );
customElements.define( "nav-item", NavigationItem );
customElements.define( "contributor-tag", Contributor );