chansung commited on
Commit
3993884
β€’
1 Parent(s): ac6931b

Create js.py

Browse files
Files changed (1) hide show
  1. constants/js.py +96 -0
constants/js.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ UPDATE_SEARCH_RESULTS = f"""
2
+ function search(searchIn, maxResults = 3) {{
3
+ if (searchIn.trim().length > 0) {{
4
+ const results = [];
5
+ let titles = {list(titles)};
6
+ for (const title of titles) {{ // Assuming 'titles' is an array defined elsewhere
7
+ if (results.length > 10) {{
8
+ break;
9
+ }} else {{
10
+ if (title.toLowerCase().includes(searchIn.toLowerCase())) {{ // JavaScript's equivalent to Python's 'in'
11
+ results.push(title);
12
+ }}
13
+ }}
14
+ }}
15
+ // Handle UI elements (Explanation below)
16
+ const resultElements = [1,2,3,4,5,6,7,8,9,10].map(index => {{
17
+ return results[index - 1] || '';
18
+ }});
19
+ if (resultElements[0] == '') {{
20
+ document.getElementById('search_r1').style.display = 'none';
21
+ }} else {{
22
+ document.getElementById('search_r1').style.display = 'block';
23
+ }}
24
+ if (resultElements[1] == '') {{
25
+ document.getElementById('search_r2').style.display = 'none';
26
+ }} else {{
27
+ document.getElementById('search_r2').style.display = 'block';
28
+ }}
29
+ if (resultElements[2] == '') {{
30
+ document.getElementById('search_r3').style.display = 'none';
31
+ }} else {{
32
+ document.getElementById('search_r3').style.display = 'block';
33
+ }}
34
+ if (resultElements[3] == '') {{
35
+ document.getElementById('search_r4').style.display = 'none';
36
+ }} else {{
37
+ document.getElementById('search_r4').style.display = 'block';
38
+ }}
39
+ if (resultElements[4] == '') {{
40
+ document.getElementById('search_r5').style.display = 'none';
41
+ }} else {{
42
+ document.getElementById('search_r5').style.display = 'block';
43
+ }}
44
+ if (resultElements[5] == '') {{
45
+ document.getElementById('search_r6').style.display = 'none';
46
+ }} else {{
47
+ document.getElementById('search_r6').style.display = 'block';
48
+ }}
49
+ if (resultElements[6] == '') {{
50
+ document.getElementById('search_r7').style.display = 'none';
51
+ }} else {{
52
+ document.getElementById('search_r7').style.display = 'block';
53
+ }}
54
+ if (resultElements[7] == '') {{
55
+ document.getElementById('search_r8').style.display = 'none';
56
+ }} else {{
57
+ document.getElementById('search_r8').style.display = 'block';
58
+ }}
59
+ if (resultElements[8] == '') {{
60
+ document.getElementById('search_r9').style.display = 'none';
61
+ }} else {{
62
+ document.getElementById('search_r9').style.display = 'block';
63
+ }}
64
+ if (resultElements[9] == '') {{
65
+ document.getElementById('search_r10').style.display = 'none';
66
+ }} else {{
67
+ document.getElementById('search_r10').style.display = 'block';
68
+ }}
69
+ return resultElements;
70
+ }} else {{
71
+ document.getElementById('search_r1').style.display = 'none';
72
+ document.getElementById('search_r2').style.display = 'none';
73
+ document.getElementById('search_r3').style.display = 'none';
74
+ document.getElementById('search_r4').style.display = 'none';
75
+ document.getElementById('search_r5').style.display = 'none';
76
+ document.getElementById('search_r6').style.display = 'none';
77
+ document.getElementById('search_r7').style.display = 'none';
78
+ document.getElementById('search_r8').style.display = 'none';
79
+ document.getElementById('search_r9').style.display = 'none';
80
+ document.getElementById('search_r10').style.display = 'none';
81
+ return ['', '', '', '', '', '', '', '', '', '']
82
+ }}
83
+ }}
84
+ """
85
+
86
+ UPDATE_IF_TYPE = f"""
87
+ function chage_if_type(if_type) {{
88
+ if (if_type == 'Q&As') {{
89
+ document.getElementById('chat_block').style.display = 'none';
90
+ document.getElementById('qna_block').style.display = 'block';
91
+ }} else {{
92
+ document.getElementById('chat_block').style.display = 'block';
93
+ document.getElementById('qna_block').style.display = 'none';
94
+ }}
95
+ }}
96
+ """