|
1 | | -// <td> under the mouse right now (if any) |
| 1 | +// <td> під вказівником прямо зараз (якщо є) |
2 | 2 | let currentElem = null; |
3 | 3 |
|
4 | 4 | table.onmouseover = function(event) { |
5 | | - // before entering a new element, the mouse always leaves the previous one |
6 | | - // if currentElem is set, we didn't leave the previous <td>, |
7 | | - // that's a mouseover inside it, ignore the event |
| 5 | + // перед переходом до нового елемента миша завжди залишає попередній |
| 6 | + // якщо вже встановлено currentElem, то ми не залишили попередній <td>, |
| 7 | + // і цей mouseover відбувається всередині, тому ігноруємо подію |
8 | 8 | if (currentElem) return; |
9 | 9 |
|
10 | 10 | let target = event.target.closest('td'); |
11 | 11 |
|
12 | | - // we moved not into a <td> - ignore |
| 12 | + // ми перейшли не в <td> - ігнорувати |
13 | 13 | if (!target) return; |
14 | 14 |
|
15 | | - // moved into <td>, but outside of our table (possible in case of nested tables) |
16 | | - // ignore |
| 15 | + // переміщено в <td>, але за межами нашої таблиці (можливо у випадку вкладених таблиць) |
| 16 | + // ігнорувати |
17 | 17 | if (!table.contains(target)) return; |
18 | 18 |
|
19 | | - // hooray! we entered a new <td> |
| 19 | + // ура! ми перейщли до нового <td> |
20 | 20 | currentElem = target; |
21 | 21 | onEnter(currentElem); |
22 | 22 | }; |
23 | 23 |
|
24 | 24 |
|
25 | 25 | table.onmouseout = function(event) { |
26 | | - // if we're outside of any <td> now, then ignore the event |
27 | | - // that's probably a move inside the table, but out of <td>, |
28 | | - // e.g. from <tr> to another <tr> |
| 26 | + // якщо ми зараз поза будь-яким <td>, тоді ігноруємо подію |
| 27 | + // це, мабуть, переміщення всередину таблиці, але поза <td>, |
| 28 | + // напр. від <tr> до іншого <tr> |
29 | 29 | if (!currentElem) return; |
30 | 30 |
|
31 | | - // we're leaving the element – where to? Maybe to a descendant? |
| 31 | + // покидаємо елемент – але куди? Може ідемо до дочірнього елемента? |
32 | 32 | let relatedTarget = event.relatedTarget; |
33 | 33 |
|
34 | 34 | while (relatedTarget) { |
35 | | - // go up the parent chain and check – if we're still inside currentElem |
36 | | - // then that's an internal transition – ignore it |
| 35 | + // піднімаємось батьківським ланцюжком і перевіряємо – чи ми все ще всередині currentElem |
| 36 | + // тоді це внутрішній перехід – ігноруємо його |
37 | 37 | if (relatedTarget == currentElem) return; |
38 | 38 |
|
39 | 39 | relatedTarget = relatedTarget.parentNode; |
40 | 40 | } |
41 | 41 |
|
42 | | - // we left the <td>. really. |
| 42 | + // ми залишили <td>. насправді. |
43 | 43 | onLeave(currentElem); |
44 | 44 | currentElem = null; |
45 | 45 | }; |
46 | 46 |
|
47 | | -// any functions to handle entering/leaving an element |
| 47 | +// будь-які функції для обробки входу/виходу з елемента |
48 | 48 | function onEnter(elem) { |
49 | 49 | elem.style.background = 'pink'; |
50 | 50 |
|
51 | | - // show that in textarea |
| 51 | + // показати це в textarea |
52 | 52 | text.value += `over -> ${currentElem.tagName}.${currentElem.className}\n`; |
53 | 53 | text.scrollTop = 1e6; |
54 | 54 | } |
55 | 55 |
|
56 | 56 | function onLeave(elem) { |
57 | 57 | elem.style.background = ''; |
58 | 58 |
|
59 | | - // show that in textarea |
| 59 | + // показати це в textarea |
60 | 60 | text.value += `out <- ${elem.tagName}.${elem.className}\n`; |
61 | 61 | text.scrollTop = 1e6; |
62 | 62 | } |
0 commit comments