|
192 | 192 | font-weight: var(--caption-font-weight); |
193 | 193 | } |
194 | 194 |
|
| 195 | + .dot-badge { |
| 196 | + position: absolute; |
| 197 | + top: 0; |
| 198 | + left: 0; |
| 199 | + transform: translate(-50%, -50%); |
| 200 | + |
| 201 | + height: 1.5em; |
| 202 | + padding: 0 0.3em; |
| 203 | + min-width: calc(1.5em - 0.3em * 2); |
| 204 | + |
| 205 | + color: var(--fg-color); |
| 206 | + background: color-mix(in srgb, var(--bg-color), var(--fg-color) 10%); |
| 207 | + border-radius: 9999px; |
| 208 | + border: 3px solid var(--bg-color); |
| 209 | + |
| 210 | + justify-content: center; |
| 211 | + align-items: center; |
| 212 | + white-space: nowrap; |
| 213 | + line-height: 1; |
| 214 | + user-select: none; |
| 215 | + } |
| 216 | + |
195 | 217 | .header { |
196 | 218 | display: flex; |
197 | 219 | flex-direction: row; |
198 | 220 | align-items: center; |
| 221 | + |
199 | 222 | position: sticky; |
200 | 223 | z-index: 1000; |
201 | 224 | top: 0; |
|
249 | 272 | } |
250 | 273 | </style> |
251 | 274 | {% endmacro style %} |
252 | | -</html></title></head> |
| 275 | + |
253 | 276 | <!-- {# content #} --> |
254 | 277 |
|
255 | 278 | {{ self::style() }} |
256 | 279 |
|
257 | 280 | <script> |
| 281 | + function for_el_with_class(script, class_name, f) { |
| 282 | + function do_internal(element, class_name) { |
| 283 | + if (element.classList && element.classList.contains(class_name)) { |
| 284 | + f(element); |
| 285 | + } |
| 286 | + Array.from(element.children).forEach((child) => |
| 287 | + do_internal(child, class_name), |
| 288 | + ); |
| 289 | + } |
| 290 | + |
| 291 | + Array.from(script.parentNode.children).forEach((el) => |
| 292 | + do_internal(el, class_name), |
| 293 | + ); |
| 294 | + } |
| 295 | + |
258 | 296 | function show_with_class(script, class_name) { |
259 | | - Array.from(script.parentNode.children) |
260 | | - .filter(el => el.classList && el.classList.contains(class_name)) |
261 | | - .forEach(el => el.style.display = "flex"); |
| 297 | + for_el_with_class(script, class_name, (el) => (el.style.display = "flex")); |
| 298 | + } |
| 299 | + |
| 300 | + function hide_with_class(script, class_name) { |
| 301 | + for_el_with_class( |
| 302 | + script, |
| 303 | + class_name, |
| 304 | + (el) => (el.style.display = "hidden"), |
| 305 | + ); |
262 | 306 | } |
263 | 307 | </script> |
264 | 308 |
|
|
279 | 323 | xmlns="http://www.w3.org/2000/svg" |
280 | 324 | viewBox="0 0 16 16" |
281 | 325 | > |
282 | | - <path d="m 5.019531 0 c -1.332031 0 -2.273437 0.816406 -2.644531 1.554688 c -0.371094 0.738281 -0.355469 1.445312 -0.355469 1.445312 l 0.03125 12.472656 l 5.996094 -2.402344 l 6.003906 2.402344 l -0.03125 -12.476562 c 0 -0.003906 0.011719 -0.707032 -0.355469 -1.441406 c -0.371093 -0.738282 -1.3125 -1.554688 -2.644531 -1.554688 z m 0 2 h 6 c 0.695313 0.011719 1.003907 0.367188 1 1 l 0.023438 9.519531 l -3.996094 -1.601562 l -4.003906 1.601562 l -0.023438 -9.523437 c -0.007812 -0.648438 0.398438 -0.996094 1 -0.996094 z m 0 0" |
283 | | - fill="currentColor"/> |
| 326 | + <path |
| 327 | + d="m 5.019531 0 c -1.332031 0 -2.273437 0.816406 -2.644531 1.554688 c -0.371094 0.738281 -0.355469 1.445312 -0.355469 1.445312 l 0.03125 12.472656 l 5.996094 -2.402344 l 6.003906 2.402344 l -0.03125 -12.476562 c 0 -0.003906 0.011719 -0.707032 -0.355469 -1.441406 c -0.371093 -0.738282 -1.3125 -1.554688 -2.644531 -1.554688 z m 0 2 h 6 c 0.695313 0.011719 1.003907 0.367188 1 1 l 0.023438 9.519531 l -3.996094 -1.601562 l -4.003906 1.601562 l -0.023438 -9.523437 c -0.007812 -0.648438 0.398438 -0.996094 1 -0.996094 z m 0 0" |
| 328 | + fill="currentColor" |
| 329 | + /> |
284 | 330 | </svg> |
285 | 331 |
|
286 | 332 | <svg |
287 | 333 | id="bookmark-filled-symbolic" |
288 | 334 | xmlns="http://www.w3.org/2000/svg" |
289 | 335 | viewBox="0 0 16 16" |
290 | 336 | > |
291 | | - <path d="m 5.019531 0 c -1.332031 0 -2.273437 0.816406 -2.644531 1.554688 c -0.371094 0.738281 -0.355469 1.445312 -0.355469 1.445312 l 0.03125 12.472656 l 5.996094 -2.402344 l 6.003906 2.402344 l -0.03125 -12.476562 c 0 -0.003906 0.011719 -0.707032 -0.355469 -1.441406 c -0.371093 -0.738282 -1.3125 -1.554688 -2.644531 -1.554688 z m 0 0" |
292 | | - fill="currentColor"/> |
| 337 | + <path |
| 338 | + d="m 5.019531 0 c -1.332031 0 -2.273437 0.816406 -2.644531 1.554688 c -0.371094 0.738281 -0.355469 1.445312 -0.355469 1.445312 l 0.03125 12.472656 l 5.996094 -2.402344 l 6.003906 2.402344 l -0.03125 -12.476562 c 0 -0.003906 0.011719 -0.707032 -0.355469 -1.441406 c -0.371093 -0.738282 -1.3125 -1.554688 -2.644531 -1.554688 z m 0 0" |
| 339 | + fill="currentColor" |
| 340 | + /> |
293 | 341 | </svg> |
294 | 342 |
|
295 | 343 | <svg |
296 | 344 | id="copy-symbolic" |
297 | 345 | xmlns="http://www.w3.org/2000/svg" |
298 | 346 | viewBox="0 0 16 16" |
299 | 347 | > |
300 | | - <path d="m 0 3 c 0 -1.644531 1.355469 -3 3 -3 h 5 c 1.644531 0 3 1.355469 3 3 c 0 0.550781 -0.449219 1 -1 1 s -1 -0.449219 -1 -1 c 0 -0.570312 -0.429688 -1 -1 -1 h -5 c -0.570312 0 -1 0.429688 -1 1 v 5 c 0 0.570312 0.429688 1 1 1 c 0.550781 0 1 0.449219 1 1 s -0.449219 1 -1 1 c -1.644531 0 -3 -1.355469 -3 -3 z m 5 5 c 0 -1.644531 1.355469 -3 3 -3 h 5 c 1.644531 0 3 1.355469 3 3 v 5 c 0 1.644531 -1.355469 3 -3 3 h -5 c -1.644531 0 -3 -1.355469 -3 -3 z m 2 0 v 5 c 0 0.570312 0.429688 1 1 1 h 5 c 0.570312 0 1 -0.429688 1 -1 v -5 c 0 -0.570312 -0.429688 -1 -1 -1 h -5 c -0.570312 0 -1 0.429688 -1 1 z m 0 0" |
301 | | - fill="currentColor"/> |
| 348 | + <path |
| 349 | + d="m 0 3 c 0 -1.644531 1.355469 -3 3 -3 h 5 c 1.644531 0 3 1.355469 3 3 c 0 0.550781 -0.449219 1 -1 1 s -1 -0.449219 -1 -1 c 0 -0.570312 -0.429688 -1 -1 -1 h -5 c -0.570312 0 -1 0.429688 -1 1 v 5 c 0 0.570312 0.429688 1 1 1 c 0.550781 0 1 0.449219 1 1 s -0.449219 1 -1 1 c -1.644531 0 -3 -1.355469 -3 -3 z m 5 5 c 0 -1.644531 1.355469 -3 3 -3 h 5 c 1.644531 0 3 1.355469 3 3 v 5 c 0 1.644531 -1.355469 3 -3 3 h -5 c -1.644531 0 -3 -1.355469 -3 -3 z m 2 0 v 5 c 0 0.570312 0.429688 1 1 1 h 5 c 0.570312 0 1 -0.429688 1 -1 v -5 c 0 -0.570312 -0.429688 -1 -1 -1 h -5 c -0.570312 0 -1 0.429688 -1 1 z m 0 0" |
| 350 | + fill="currentColor" |
| 351 | + /> |
302 | 352 | </svg> |
303 | 353 | </div> |
304 | 354 |
|
|
308 | 358 | <div class="header"> |
309 | 359 | <div |
310 | 360 | class="content" |
311 | | - style="width: 100%; display: flex; flex-direction: row; gap: 16px; align-items: center" |
| 361 | + style=" |
| 362 | + width: 100%; |
| 363 | + display: flex; |
| 364 | + flex-direction: row; |
| 365 | + gap: 16px; |
| 366 | + align-items: center; |
| 367 | + " |
312 | 368 | > |
313 | | - <div style="padding: 16px 0; font-size: 2em; flex: 1"> |
| 369 | + <div style="padding: 8px 0; font-size: 2em; flex: 1"> |
314 | 370 | <ruby> |
315 | 371 | {%- for part in group.furigana_parts -%} |
316 | 372 | <span>{{- part[0] -}}</span><rt>{{- part[1] -}}</rt> |
317 | 373 | {%- endfor -%} |
318 | 374 | </ruby> |
319 | 375 | </div> |
320 | 376 |
|
321 | | - <div style="display: flex; flex-direction: column; gap: 8px"> |
| 377 | + <div |
| 378 | + style=" |
| 379 | + padding: 1.5em 0; |
| 380 | + display: flex; |
| 381 | + flex-direction: column; |
| 382 | + gap: 8px; |
| 383 | + " |
| 384 | + > |
322 | 385 | <!-- |
323 | 386 | {% if group.term.headword %} |
324 | 387 | {% set js_headword = group.term.headword | addslashes %} |
|
334 | 397 | {% set js_reading = "null" %} |
335 | 398 | {% endif %} |
336 | 399 |
|
337 | | - {% set fn_note_exists = config.fn_note_exists | replace(from="<js_headword>", to=js_headword) | replace(from="<js_reading>", to=js_reading) %} |
338 | | - {% set fn_add_note = config.fn_add_note | replace(from="<js_headword>", to=js_headword) | replace(from="<js_reading>", to=js_reading) %} |
| 400 | + {% set fn_num_existing_notes = config.fn_num_existing_notes | replace(from="<js_headword>", to=js_headword) | replace(from="<js_reading>", to=js_reading) %} |
| 401 | + {% set fn_add_new_note = config.fn_add_new_note | replace(from="<js_headword>", to=js_headword) | replace(from="<js_reading>", to=js_reading) %} |
| 402 | + {% set fn_add_duplicate_note = config.fn_add_duplicate_note | replace(from="<js_headword>", to=js_headword) | replace(from="<js_reading>", to=js_reading) %} |
339 | 403 | {% set fn_view_note = config.fn_view_note | replace(from="<js_headword>", to=js_headword) | replace(from="<js_reading>", to=js_reading) %} |
340 | 404 | --> |
341 | 405 |
|
342 | 406 | <div hidden class="add-note"> |
343 | 407 | <button |
344 | 408 | class="suggested-action" |
345 | | - onclick="{{ fn_add_note | safe }}" |
| 409 | + onclick=" |
| 410 | + { |
| 411 | + const on_add_note = () => { |
| 412 | +
|
| 413 | + }; |
| 414 | + } |
| 415 | +
|
| 416 | + {{ fn_add_new_note | safe }} |
| 417 | + " |
346 | 418 | > |
347 | 419 | <svg class="icon"> |
348 | 420 | <use href="#bookmark-outline-symbolic"></use> |
|
353 | 425 |
|
354 | 426 | <div hidden class="note-actions"> |
355 | 427 | <div style="display: flex; flex-direction: row; gap: 8px"> |
| 428 | + <div style="flex: 1; position: relative"> |
| 429 | + <button |
| 430 | + title="{{ config.s_add_duplicate_note }}" |
| 431 | + onclick="{{ fn_add_duplicate_note | safe }}" |
| 432 | + style="flex: 1; position: relative" |
| 433 | + > |
| 434 | + <svg class="icon"> |
| 435 | + <use href="#copy-symbolic"></use> |
| 436 | + </svg> |
| 437 | + </button> |
| 438 | + |
| 439 | + <div hidden class="multiple-notes dot-badge">?</div> |
| 440 | + </div> |
| 441 | + |
356 | 442 | <button |
357 | 443 | title="{{ config.s_view_note }}" |
358 | 444 | onclick="{{ fn_view_note | safe }}" |
|
362 | 448 | <use href="#bookmark-filled-symbolic"></use> |
363 | 449 | </svg> |
364 | 450 | </button> |
365 | | - |
366 | | - <button |
367 | | - title="{{ config.s_add_duplicate_note }}" |
368 | | - onclick="{{ fn_add_note | safe }}" |
369 | | - style="flex: 1" |
370 | | - > |
371 | | - <svg class="icon"> |
372 | | - <use href="#copy-symbolic"></use> |
373 | | - </svg> |
374 | | - </button> |
375 | 451 | </div> |
376 | 452 | </div> |
377 | 453 |
|
378 | 454 | <script> |
379 | 455 | { |
380 | 456 | const script = document.currentScript; |
381 | 457 |
|
382 | | - const note_exists_callback = exists => { |
383 | | - if (exists) { |
384 | | - show_with_class(script, 'note-actions') |
| 458 | + const on_num_existing_notes = (num) => { |
| 459 | + hide_with_class(script, "add-note"); |
| 460 | + hide_with_class(script, "note-actions"); |
| 461 | + hide_with_class(script, "multiple-notes"); |
| 462 | + |
| 463 | + if (num > 0) { |
| 464 | + show_with_class(script, "note-actions"); |
| 465 | + if (num > 1) { |
| 466 | + for_el_with_class(script, "multiple-notes", (el) => { |
| 467 | + el.style.display = "flex"; |
| 468 | + el.innerHTML = `${num}`; |
| 469 | + }); |
| 470 | + } |
385 | 471 | } else { |
386 | | - show_with_class(script, 'add-note') |
| 472 | + show_with_class(script, "add-note"); |
387 | 473 | } |
388 | 474 | }; |
389 | 475 |
|
390 | | - {{ fn_note_exists | replace(from="<js_callback>", to="note_exists_callback") | safe }}; |
| 476 | + // prettier-ignore |
| 477 | + {{ fn_num_existing_notes | replace(from="<js_callback>", to="on_num_existing_notes") | safe }} |
391 | 478 | } |
392 | 479 | </script> |
393 | 480 | </div> |
|
0 commit comments