|
86 | 86 | outTblHeadTr.classList.add('crm__o-table-head-row'); |
87 | 87 | outTblHeadThId.classList.add( |
88 | 88 | 'head-cell', |
89 | | - 'head-cell-icon', |
| 89 | + 'head-cell-with-icon', |
90 | 90 | 'crm__o-table-head-cell' |
91 | 91 | ); |
92 | 92 | outTblHeadThIdWrap.classList.add('head-cell__wrap', 'head-cell__wrap-id'); |
93 | 93 | outTblHeadThIdText.classList.add('head-cell__text', 'head-cell__text-id'); |
94 | | - outTblHeadThIdIcon.classList.add('head-cell__icon', 'head-cell__icon-id'); |
| 94 | + outTblHeadThIdIcon.classList.add( |
| 95 | + 'head-cell__icon', |
| 96 | + 'head-cell__icon-id', |
| 97 | + 'head-cell__icon-up' |
| 98 | + ); |
95 | 99 | outTblHeadThFIO.classList.add( |
96 | 100 | 'head-cell', |
97 | | - 'head-cell-icon', |
| 101 | + 'head-cell-with-icon', |
98 | 102 | 'crm__o-table-head-cell' |
99 | 103 | ); |
100 | 104 | outTblHeadThFIOWrap.classList.add('head-cell__wrap', 'head-cell__wrap-fio'); |
101 | 105 | outTblHeadThFIOText.classList.add('head-cell__text', 'head-cell__text-fio'); |
102 | | - outTblHeadThFIOIcon.classList.add('head-cell__icon', 'head-cell__icon-fio'); |
| 106 | + outTblHeadThFIOIcon.classList.add( |
| 107 | + 'head-cell__icon', |
| 108 | + 'head-cell__icon-fio', |
| 109 | + 'head-cell__icon-down' |
| 110 | + ); |
103 | 111 | outTblHeadThFIOSort.classList.add('head-cell__sort', 'head-cell__sort-fio'); |
104 | 112 | outTblHeadThCreationDT.classList.add( |
105 | 113 | 'head-cell', |
106 | | - 'head-cell-icon', |
| 114 | + 'head-cell-with-icon', |
107 | 115 | 'crm__o-table-head-cell' |
108 | 116 | ); |
109 | 117 | outTblHeadThDTWrap.classList.add('head-cell__wrap', 'head-cell__wrap-dt'); |
110 | 118 | outTblHeadThDTText.classList.add('head-cell__text', 'head-cell__text-dt'); |
111 | | - outTblHeadThDTIcon.classList.add('head-cell__icon', 'head-cell__icon-dt'); |
| 119 | + outTblHeadThDTIcon.classList.add( |
| 120 | + 'head-cell__icon', |
| 121 | + 'head-cell__icon-dt', |
| 122 | + 'head-cell__icon-down' |
| 123 | + ); |
112 | 124 | outTblHeadThChanges.classList.add( |
113 | 125 | 'head-cell', |
114 | | - 'head-cell-icon', |
| 126 | + 'head-cell-with-icon', |
115 | 127 | 'crm__o-table-head-cell' |
116 | 128 | ); |
117 | 129 | outTblHeadThChangeWrap.classList.add( |
|
124 | 136 | ); |
125 | 137 | outTblHeadThChangeIcon.classList.add( |
126 | 138 | 'head-cell__icon', |
127 | | - 'head-cell__icon-change' |
| 139 | + 'head-cell__icon-change', |
| 140 | + 'head-cell__icon-down' |
128 | 141 | ); |
129 | 142 | outTblHeadThContacts.classList.add('head-cell', 'crm__o-table-head-cell'); |
130 | 143 | outTblHeadThContactWrap.classList.add( |
|
240 | 253 |
|
241 | 254 | const searchFormInput = document.querySelector('.crm__search-form input'); // получение search-инпута |
242 | 255 | searchFormInputValidation(searchFormInput); |
| 256 | + |
| 257 | + // изменение направления стрелки/svg-icon, согласно прожатия по заглавной ячейке (при сортировке данных) |
| 258 | + const allHeaderRowCells = document.querySelectorAll( |
| 259 | + '.crm__o-table-head-cell' |
| 260 | + ); |
| 261 | + |
| 262 | + function changeIconDirection(event) { |
| 263 | + const headerRowCell = event.currentTarget; // фиксация всей/целиком "th" заглавной ячейки |
| 264 | + const cellIcon = headerRowCell.querySelector('.head-cell__icon'); // определение иконки внутри ячейки |
| 265 | + const cellSort = headerRowCell.querySelector('.head-cell__sort'); // определение доп. текста, типа "А-Я" |
| 266 | + |
| 267 | + // проверка/подтверждение наличия иконки (переключение) |
| 268 | + if (cellIcon) { |
| 269 | + cellIcon.classList.toggle('head-cell__icon-up'); |
| 270 | + cellIcon.classList.toggle('head-cell__icon-down'); |
| 271 | + } |
| 272 | + |
| 273 | + // проверка/подтверждение наличия доп. текста (замена) |
| 274 | + if (cellSort) { |
| 275 | + cellSort.textContent = cellSort.textContent === 'А-Я' ? 'Я-А' : 'А-Я'; |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + // организация прослушек "для каждой" заглавной ячейки |
| 280 | + allHeaderRowCells.forEach((cell) => { |
| 281 | + cell.addEventListener('click', (event) => changeIconDirection(event)); // передача события |
| 282 | + |
| 283 | + // отработка сортировки/сброса сортировки через TAB/Enter (изменение направления стелок) |
| 284 | + cell.addEventListener('keydown', (event) => { |
| 285 | + if (event.key === 'Enter') { |
| 286 | + event.preventDefault(); |
| 287 | + changeIconDirection(event); // передача события |
| 288 | + } |
| 289 | + }); |
| 290 | + }); |
243 | 291 | })(); |
0 commit comments