-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Filter.js
103 lines (85 loc) · 2.78 KB
/
Filter.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
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
class Filter {
constructor(name, heName, refList, heRefList) {
this.name = name;
this.heName = heName;
this.refList = refList;
this.heRefList = heRefList;
}
toString(lang) {
return lang === "hebrew" && this.heName ? this.heName : this.name;
}
displayRef() {
// return true if should display ref for results of this filter in TextList
return true;
}
listKey(i) {
// returns key that uniquely identifies this a ref from filter.refList in a list
return this.refList[i];
}
equals(filter) {
return this.name === filter.name;
}
clone() {
return new Filter(this.name, this.heName, Sefaria.util.clone(this.refList), Sefaria.util.clone(this.heRefList));
}
}
class LinkFilter extends Filter {
constructor(title, heTitle, collectiveTitle, heCollectiveTitle, refList, heRefList, category) {
super(title, heTitle, refList, heRefList);
this.collectiveTitle = collectiveTitle;
this.heCollectiveTitle = heCollectiveTitle;
this.category = category;
}
toString(lang) {
// make sure that you only display Hebrew is there is Hebrew
return lang === "hebrew" && (this.heCollectiveTitle || this.heName) ?
(this.heCollectiveTitle ? this.heCollectiveTitle : this.heName) : //NOTE backwards compatibility
(this.collectiveTitle ? this.collectiveTitle : this.name);
}
equals(filter) {
return this.name === filter.name && this.category === filter.category;
}
displayRef() {
return this.category === "Commentary" && this.name !== "Commentary";
}
listKey(i) {
return `${(typeof i !== 'undefined') ? this.refList[i] : ''}|${this.name}|${this.category}`;
}
clone() {
return new LinkFilter(
this.name,
this.heName,
this.collectiveTitle,
this.heCollectiveTitle,
Sefaria.util.clone(this.refList),
Sefaria.util.clone(this.heRefList),
this.category
);
}
}
class VersionFilter extends Filter {
constructor(versionTitle, versionTitleInHebrew, versionLanguage, ref) {
super(versionTitle, versionTitleInHebrew, [ref], [null]); // heRefList is not necessary because it will never be displayed
this.versionTitle = versionTitle;
this.versionTitleInHebrew = versionTitleInHebrew;
this.versionLanguage = versionLanguage;
}
listKey(i) {
return `${(typeof i !== 'undefined') ? this.refList[i] : ''}|${this.versionTitle}|${this.versionLanguage}`;
}
equals(filter) {
return this.versionTitle === filter.versionTitle && this.versionLanguage === filter.versionLanguage;
}
toString(lang) {
return lang === "hebrew" && this.heName ? this.heName : this.name;
}
clone() {
return new VersionFilter(
this.name,
this.heName,
this.versionLanguage,
this.refList[0]
);
}
}
export { Filter, LinkFilter, VersionFilter };