-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathGlobalTag.js
More file actions
138 lines (120 loc) · 4.31 KB
/
GlobalTag.js
File metadata and controls
138 lines (120 loc) · 4.31 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
// Copyright (c) 2017 Euan Ong
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
/*
global
_
*/
/*
exported
GlobalTag
*/
/**
* Converts the first character of a string to uppercase.
* Defined locally because GlobalTag.js runs inside the Planet iframe
* and does not have access to the toTitleCase exported by js/utils/utils.js.
* @param {string} str - The string to convert.
* @returns {string|undefined} The converted string or undefined if input is not a string.
*/
const toTitleCase = (str) => {
if (typeof str !== "string") return;
return str.charAt(0).toUpperCase() + str.slice(1);
};
class GlobalTag {
/*
this.tagNames = [
//.TRANS: On the Planet, we use labels to tag projects.
_("All Projects"),
//.TRANS: On the Planet, we use labels to tag projects.
_("My Projects"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Examples"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Music"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Art"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Math"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Interactive"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Design"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Game"),
//.TRANS: On the Planet, we use labels to tag projects.
_("media"),
//.TRANS: On the Planet, we use labels to tag projects.
_("sensors"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Effects"),
//.TRANS: On the Planet, we use labels to tag projects.
_("Code Snippet"),
];
*/
constructor(Planet) {
this.Planet = Planet;
this.id = null;
this.name = null;
this.func = null;
this.IsDisplayTag = null;
this.specialTag = null;
this.tagElement = null;
this.globalPlanet = Planet.GlobalPlanet;
this.selected = false;
this.selectedClass = null;
}
render() {
const tag = document.createElement("div");
tag.classList.add("chipselect", "cursor");
if (this.selected) tag.classList.add(this.selectedClass);
tag.textContent = toTitleCase(_(this.name));
// eslint-disable-next-line no-unused-vars
tag.addEventListener("click", evt => {
this.onTagClick();
});
const elementTag = `${this.IsDisplayTag ? "primary" : "more"}chips`;
document.getElementById(elementTag).appendChild(tag);
this.tagElement = tag;
}
onTagClick() {
if (this.specialTag && !this.selected) this.globalPlanet.selectSpecialTag(this);
else {
this.selected ? this.unselect() : this.select();
this.globalPlanet.refreshTagList();
}
}
select() {
this.tagElement.classList.add(this.selectedClass);
this.selected = true;
}
unselect() {
this.tagElement.classList.remove(this.selectedClass);
this.selected = false;
}
init(obj) {
const Planet = this.Planet;
if (obj.id !== undefined) {
this.specialTag = false;
this.id = obj.id;
this.name = Planet.TagsManifest[this.id].TagName;
this.func = null;
this.IsDisplayTag = Planet.TagsManifest[this.id].IsDisplayTag === "1"; // ? "true":"false";
this.selectedClass = "selected";
} else {
this.specialTag = true;
this.IsDisplayTag = true;
this.id = null;
this.name = obj.name;
this.func = obj.func;
this.selectedClass = "selected-special";
}
this.render();
}
}