-
Notifications
You must be signed in to change notification settings - Fork 2
/
js-lib.c
240 lines (228 loc) · 10.1 KB
/
js-lib.c
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* fontinfo
*
* Overview of Installed Fonts
*
* Copyright (C) 2013 Petr Gajdos (pgajdos at suse)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include "js-lib.h"
#include "filesystem.h"
#include "constants.h"
void js_write_script(config_t config, const char *js_fname, const char *script)
{
char dirname[FILEPATH_MAX];
char scriptname[FILEPATH_MAX];
FILE *js;
snprintf(dirname, FILEPATH_MAX, "%s/%s", config.dir, JS_SUBDIR);
create_dir(dirname);
snprintf(scriptname, FILEPATH_MAX, "%s/%s", dirname, js_fname);
js = open_write(scriptname, "js_write_script");
fprintf(js, script);
fclose(js);
return;
}
void js_write_script_specimen_view(config_t config, const char *js_fname)
{
js_write_script(config, js_fname,
"var cscript;\n"
"var cspecimen_type;\n"
"var specimen_id_suffix;\n"
"\n"
"function display_specimen(script, specimen_type)\n"
"{\n"
" var el;\n"
" var link_color;\n"
"\n"
" el = document.getElementById(cspecimen_type + script + specimen_id_suffix);\n"
" link_color = el.style.color;\n"
" /* turn off old */\n"
" el = document.getElementById(cspecimen_type + cscript + specimen_id_suffix);\n"
" el.style.display = 'none';\n"
" if (scripts.length > 1)\n"
" {\n"
" el = document.getElementById(cscript + 'SpecimenAnchor');\n"
" el.style.color = link_color;\n"
" }\n"
" if (specimen_types.length > 1)\n"
" {\n"
" el = document.getElementById(cspecimen_type + 'SpecimenAnchor');\n"
" el.style.color = link_color;\n"
" }\n"
"\n"
" cscript = script;\n"
" cspecimen_type = specimen_type;\n"
"\n"
" /* turn on new */\n"
" el = document.getElementById(cspecimen_type + cscript + specimen_id_suffix);\n"
" el.style.display = 'block';\n"
" if (scripts.length > 1)\n"
" {\n"
" el = document.getElementById(cscript + 'SpecimenAnchor');\n"
" el.style.color = 'black'\n"
" }\n"
" if (specimen_types.length > 1)\n"
" {\n"
" el = document.getElementById(cspecimen_type + 'SpecimenAnchor');\n"
" el.style.color = 'black'\n"
" }\n"
"}\n"
"\n"
"function initialize_specimen_tabs(scripts, specimen_types, id_suffix)\n"
"{\n"
" cscript = scripts.length > 0 ? scripts[0] : \""NO_SCRIPT"\";\n"
" cspecimen_type = specimen_types[0];\n"
" specimen_id_suffix = id_suffix\n"
" var el;\n"
" \n"
" if (scripts.length > 0 && specimen_types.length > 0)\n"
" {\n"
" document.write('<table><tr><td>');\n"
" }\n"
" \n"
" if (scripts.length > 0)\n"
" {\n"
" document.write('<table><tr>');\n"
" for (var i = 0; i < scripts.length; i++)\n"
" {\n"
" var script_wu = scripts[i].replace(/_/g, \" \");\n"
" document.write(\"<td><div class=\\\"my-3\\\"><button class=\\\"btn btn-secondary\\\"\"\n"
" + \"id='\" + scripts[i] + \"SpecimenAnchor' onclick=\\\"display_specimen('\"\n"
" + scripts[i] + \"', cspecimen_type)\\\">\" + script_wu + \"</button></div></td>\"); \n"
" if (i % 7 == 6)\n"
" {\n"
" document.write('</tr><tr>');\n"
" }\n"
" }\n"
" document.write('</tr></table>');\n"
" }\n"
" \n"
" if (scripts.length > 0 && specimen_types.length > 0)"
" {\n"
" document.write('</td><td> </td><td>');\n"
" }\n"
" if (specimen_types.length > 1)\n"
" {\n"
" document.write('<table><tr>');\n"
" for (var i = 0; i < specimen_types.length; i++)\n"
" {\n"
" document.write(\"<td><div class=\\\"my-3\\\"><button class=\\\"btn btn-primary\\\"\" + \n"
" \"id='\" + specimen_types[i] + \"SpecimenAnchor' \" + \n"
" \"onclick=\\\"display_specimen(cscript, '\" + specimen_types[i] + \"')\\\"\" +\n"
" \">\" + specimen_types[i] + \"</button></div></td>\");\n"
" }\n"
" document.write('</tr></table>');\n"
" }\n"
" \n"
" if (scripts.length > 0 && specimen_types.length > 0)\n"
" {\n"
" document.write('</td></tr></table>');\n"
" }\n"
" \n"
" if (scripts.length > 0)\n"
" {\n"
" el = document.getElementById(scripts[0] + \"SpecimenAnchor\");\n"
" el.style.color = 'black';\n"
" }\n"
" if (specimen_types.length > 1)\n"
" {\n"
" el = document.getElementById(specimen_types[0] + \"SpecimenAnchor\");\n"
" el.style.color = 'black';\n"
" }\n"
"}");
return;
}
void js_write_script_charset_view(config_t config, const char *js_fname)
{
js_write_script(config, js_fname,
"function charset_block_show(cell_id, html)\n"
"{\n"
" el = document.getElementById(cell_id);\n"
" el.innerHTML = html;\n"
" el.style.display = 'block';\n"
" charset_shown[cell_id] = 1;\n"
" el = document.getElementById(cell_id + 'Toggle');\n"
" el.innerHTML = '-'\n"
"}\n"
"\n"
"function charset_block_hide(cell_id)\n"
"{\n"
" el = document.getElementById(cell_id);\n"
" el.innerHTML = '';\n"
" el.style.display = 'none';\n"
" charset_shown[cell_id] = 0;\n"
" el = document.getElementById(cell_id + 'Toggle');\n"
" el.innerHTML = '+'\n"
"}\n"
"\n"
"function charset_block_toggle(cell_id, html)\n"
"{\n"
//" el.innerHTML = \"AHOJ<script src=\" + txt_file + \"></srcipt>\"\n"
" if (charset_shown[cell_id])\n"
" {\n"
" charset_block_hide(cell_id);\n"
" }\n"
" else\n"
" {\n"
" charset_block_show(cell_id, html);\n"
" }\n"
"}\n"
"\n"
"function charset_blocks_show()\n"
"{\n"
" for (var charset_block in charset_shown)\n"
" {\n"
" charset_block_show(charset_block, charset_html[charset_block]);\n"
" }\n"
"}\n"
"\n"
"function charset_blocks_hide()\n"
"{\n"
" for (var charset_block in charset_shown)\n"
" {\n"
" charset_block_hide(charset_block);\n"
" }\n"
"}\n");
return;
}
void js_write_script_family_search(config_t config, const char *js_fname)
{
js_write_script(config, js_fname,
"function filter_function() {\n"
" var req_family_name, filter, table, tr, td, anchor, i, family_name, all = 0;\n"
" req_family_name = document.getElementById(\"family_filter\");\n"
" filter = req_family_name.value.toUpperCase();\n"
" if (filter == 'ALL') {\n"
" all = 1\n"
" }\n"
" if (filter.length >= 3) {\n"
" table = document.getElementById(\"list_families\");\n"
" tr = table.getElementsByTagName(\"tr\");\n"
" for (i = 0; i < tr.length; i++) {\n"
" td = tr[i].getElementsByTagName(\"td\")[0];\n"
" anchor = td.getElementsByTagName(\"a\")[0];\n"
" family_name = anchor.textContent || anchor.innerText;\n"
" if (all || family_name.toUpperCase().indexOf(filter) > -1) {\n"
" tr[i].style.display = \"\";\n"
" } else {\n"
" tr[i].style.display = \"none\";\n"
" }\n"
" }\n"
" }\n"
"}\n");
return;
}