-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathissue-node-common.js
More file actions
39 lines (39 loc) · 1.04 KB
/
issue-node-common.js
File metadata and controls
39 lines (39 loc) · 1.04 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
const issueUtils = {
addTag: function (tag) {
if (this.hasTag(tag)) {
return;
}
const existingTags = this.getExistingTags();
existingTags.push(tag);
this.setTags(existingTags);
},
removeTag: function (tag) {
if (!this.hasTag(tag)) {
return;
}
const existingTags = this.getExistingTags();
const index = existingTags.indexOf(tag);
if (index > -1) {
// only splice array when item is found
existingTags.splice(index, 1); // 2nd parameter means remove one item only
}
this.setTags(existingTags);
},
setTags: function (tags) {
this.getTagInput().value = tags.join(", ");
},
hasTag: function (tag) {
return this.getExistingTags().includes(tag);
},
getTagInput: function () {
return document.getElementById("edit-taxonomy-vocabulary-9-und");
},
getExistingTags: function () {
const tagInput = this.getTagInput();
return tagInput.value
.split(", ")
.map((tag) => tag.trim())
.filter((tag) => tag.length > 0);
},
};
export { issueUtils };