1 | define(function () { 'use strict';
|
2 |
|
3 | let showDialog, closeDialog;
|
4 |
|
5 | const evtShowDialog = (event) => {
|
6 |
|
7 | let curElement = event.target;
|
8 |
|
9 | let modalDialog = curElement.parentElement.querySelector('.hoo-mdldialog-outer');
|
10 | modalDialog.classList.remove('is-hidden');
|
11 | modalDialog.classList.add('is-visible');
|
12 |
|
13 | };
|
14 |
|
15 | const evtHideDialog = (event) => {
|
16 |
|
17 | let curElement = event.target;
|
18 |
|
19 | let modalDialog = curElement.closest('.hoo-mdldialog-outer');
|
20 |
|
21 | modalDialog.classList.remove('is-visible');
|
22 | modalDialog.classList.add('is-hidden');
|
23 |
|
24 | };
|
25 |
|
26 | const registerDialog = () => {
|
27 |
|
28 | showDialog = document.querySelectorAll('.show-dialog');
|
29 | closeDialog = document.querySelectorAll('.hoo-dlgheader-closer');
|
30 |
|
31 | if (showDialog) {
|
32 |
|
33 | showDialog.forEach(item => {
|
34 | item.addEventListener('click', evtShowDialog);
|
35 | });
|
36 |
|
37 | }
|
38 |
|
39 | if (closeDialog) {
|
40 |
|
41 | closeDialog.forEach(item => {
|
42 | item.addEventListener('click', evtHideDialog);
|
43 | });
|
44 | }
|
45 |
|
46 | };
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | const ariaSelect = (listItem) => {
|
56 |
|
57 | const csSelector = listItem;
|
58 | console.log('csSelector', csSelector);
|
59 | const csInput = csSelector.querySelector('input');
|
60 |
|
61 | const csList = csSelector.querySelector('ul');
|
62 |
|
63 | const csOptions = csList.querySelectorAll('li');
|
64 |
|
65 | csSelector.querySelectorAll('svg');
|
66 |
|
67 | const csStatus = document.querySelector('#custom-select-status');
|
68 |
|
69 | const aOptions = Array.from(csOptions);
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | let csState = "initial";
|
75 |
|
76 | csSelector.setAttribute('role', 'combobox');
|
77 | csSelector.setAttribute('aria-haspopup', 'listbox');
|
78 | csSelector.setAttribute('aria-owns', 'custom-select-list');
|
79 | csInput.setAttribute('aria-autocomplete', 'both');
|
80 | csInput.setAttribute('aria-controls', 'custom-select-list');
|
81 | csList.setAttribute('role', 'listbox');
|
82 | csOptions.forEach((option) => {
|
83 | option.setAttribute('role', 'option');
|
84 | option.setAttribute('tabindex', "-1");
|
85 | });
|
86 |
|
87 | csStatus.textContent = csOptions.length + " options available. Arrow down to browse or start typing to filter.";
|
88 |
|
89 |
|
90 |
|
91 | csSelector.addEventListener('click', function (e) {
|
92 | const currentFocus = findFocus();
|
93 | switch (csState) {
|
94 | case 'initial':
|
95 | toggleList('Open');
|
96 | setState('opened');
|
97 | break
|
98 | case 'opened':
|
99 |
|
100 | if (currentFocus === csInput) {
|
101 | toggleList('Shut');
|
102 | setState('initial');
|
103 | } else if (currentFocus.tagName === 'LI') {
|
104 |
|
105 | makeChoice(currentFocus);
|
106 | toggleList('Shut');
|
107 | setState('closed');
|
108 | }
|
109 | break
|
110 | case 'filtered':
|
111 |
|
112 | if (currentFocus.tagName === 'LI') {
|
113 | makeChoice(currentFocus);
|
114 | toggleList('Shut');
|
115 | setState('closed');
|
116 | }
|
117 |
|
118 | break
|
119 | case 'closed':
|
120 | toggleList('Open');
|
121 | setState('filtered');
|
122 | break
|
123 | }
|
124 | });
|
125 |
|
126 | csSelector.addEventListener('keyup', function (e) {
|
127 | doKeyAction(e.key);
|
128 | });
|
129 |
|
130 | document.addEventListener('click', function (e) {
|
131 | if (!e.target.closest('.hoo-select')) {
|
132 |
|
133 | toggleList('Shut');
|
134 | setState('initial');
|
135 | }
|
136 | });
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | function toggleList(whichWay) {
|
142 | if (whichWay === 'Open') {
|
143 | csList.classList.remove('hidden-all');
|
144 | csSelector.setAttribute('aria-expanded', 'true');
|
145 | } else {
|
146 | csList.classList.add('hidden-all');
|
147 | csSelector.setAttribute('aria-expanded', 'false');
|
148 | }
|
149 | }
|
150 |
|
151 | function findFocus() {
|
152 | const focusPoint = document.activeElement;
|
153 | return focusPoint
|
154 | }
|
155 |
|
156 | function moveFocus(fromHere, toThere) {
|
157 |
|
158 | const aCurrentOptions = aOptions.filter(function (option) {
|
159 | if (option.style.display === '') {
|
160 | return true
|
161 | }
|
162 | });
|
163 |
|
164 | if (aCurrentOptions.length === 0) {
|
165 | return
|
166 | }
|
167 | if (toThere === 'input') {
|
168 | csInput.focus();
|
169 | }
|
170 |
|
171 | switch (fromHere) {
|
172 | case csInput:
|
173 | if (toThere === 'forward') {
|
174 | aCurrentOptions[0].focus();
|
175 | } else if (toThere === 'back') {
|
176 | aCurrentOptions[aCurrentOptions.length - 1].focus();
|
177 | }
|
178 | break
|
179 | case csOptions[0]:
|
180 | if (toThere === 'forward') {
|
181 | aCurrentOptions[1].focus();
|
182 | } else if (toThere === 'back') {
|
183 | csInput.focus();
|
184 | }
|
185 | break
|
186 | case csOptions[csOptions.length - 1]:
|
187 | if (toThere === 'forward') {
|
188 | aCurrentOptions[0].focus();
|
189 | } else if (toThere === 'back') {
|
190 | aCurrentOptions[aCurrentOptions.length - 2].focus();
|
191 | }
|
192 | break
|
193 | default:
|
194 | const currentItem = findFocus();
|
195 | const whichOne = aCurrentOptions.indexOf(currentItem);
|
196 | if (toThere === 'forward') {
|
197 | const nextOne = aCurrentOptions[whichOne + 1];
|
198 | nextOne.focus();
|
199 | } else if (toThere === 'back' && whichOne > 0) {
|
200 | const previousOne = aCurrentOptions[whichOne - 1];
|
201 | previousOne.focus();
|
202 | } else {
|
203 | csInput.focus();
|
204 | }
|
205 | break
|
206 | }
|
207 | }
|
208 |
|
209 | function doFilter() {
|
210 | const terms = csInput.value;
|
211 | const aFilteredOptions = aOptions.filter(function (option) {
|
212 | if (option.innerText.toUpperCase().startsWith(terms.toUpperCase())) {
|
213 | return true
|
214 | }
|
215 | });
|
216 | csOptions.forEach(option => option.style.display = "none");
|
217 | aFilteredOptions.forEach(function (option) {
|
218 | option.style.display = "";
|
219 | });
|
220 | setState('filtered');
|
221 | updateStatus(aFilteredOptions.length);
|
222 | }
|
223 |
|
224 | function updateStatus(howMany) {
|
225 | csStatus.textContent = howMany + " options available.";
|
226 | }
|
227 |
|
228 | function makeChoice(whichOption) {
|
229 | const optionValue = whichOption.dataset.value;
|
230 | csInput.value = optionValue;
|
231 | moveFocus(document.activeElement, 'input');
|
232 |
|
233 | }
|
234 |
|
235 | function setState(newState) {
|
236 | switch (newState) {
|
237 | case 'initial':
|
238 | csState = 'initial';
|
239 | break
|
240 | case 'opened':
|
241 | csState = 'opened';
|
242 | break
|
243 | case 'filtered':
|
244 | csState = 'filtered';
|
245 | break
|
246 | case 'closed':
|
247 | csState = 'closed';
|
248 | }
|
249 |
|
250 | }
|
251 |
|
252 | function doKeyAction(whichKey) {
|
253 | const currentFocus = findFocus();
|
254 | switch (whichKey) {
|
255 | case 'Enter':
|
256 | if (csState === 'initial') {
|
257 |
|
258 | toggleList('Open');
|
259 | setState('opened');
|
260 | } else if (csState === 'opened' && currentFocus.tagName === 'LI') {
|
261 |
|
262 | makeChoice(currentFocus);
|
263 | toggleList('Shut');
|
264 | setState('closed');
|
265 | } else if (csState === 'opened' && currentFocus === csInput) {
|
266 |
|
267 | toggleList('Shut');
|
268 | setState('closed');
|
269 | } else if (csState === 'filtered' && currentFocus.tagName === 'LI') {
|
270 |
|
271 | makeChoice(currentFocus);
|
272 | toggleList('Shut');
|
273 | setState('closed');
|
274 | } else if (csState === 'filtered' && currentFocus === csInput) {
|
275 |
|
276 | toggleList('Open');
|
277 | setState('opened');
|
278 | } else {
|
279 |
|
280 | toggleList('Open');
|
281 | setState('filtered');
|
282 | }
|
283 | break
|
284 |
|
285 | case 'Escape':
|
286 |
|
287 |
|
288 |
|
289 | if (csState === 'opened' || csState === 'filtered') {
|
290 | toggleList('Shut');
|
291 | setState('initial');
|
292 | }
|
293 | break
|
294 |
|
295 | case 'ArrowDown':
|
296 | if (csState === 'initial' || csState === 'closed') {
|
297 |
|
298 | toggleList('Open');
|
299 | moveFocus(csInput, 'forward');
|
300 | setState('opened');
|
301 | } else {
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | toggleList('Open');
|
307 | moveFocus(currentFocus, 'forward');
|
308 | }
|
309 | break
|
310 | case 'ArrowUp':
|
311 | if (csState === 'initial' || csState === 'closed') {
|
312 |
|
313 |
|
314 | toggleList('Open');
|
315 | moveFocus(csInput, 'back');
|
316 | setState('opened');
|
317 | } else {
|
318 |
|
319 |
|
320 |
|
321 |
|
322 | moveFocus(currentFocus, 'back');
|
323 | }
|
324 | break
|
325 | default:
|
326 | if (csState === 'initial') {
|
327 |
|
328 | toggleList('Open');
|
329 | doFilter();
|
330 | setState('filtered');
|
331 | } else if (csState === 'opened') {
|
332 |
|
333 | doFilter();
|
334 | setState('filtered');
|
335 | } else if (csState === 'closed') {
|
336 |
|
337 | doFilter();
|
338 | setState('filtered');
|
339 | } else {
|
340 | doFilter();
|
341 | }
|
342 | break
|
343 | }
|
344 | }
|
345 |
|
346 | };
|
347 |
|
348 | const collapseAndExpand = (event) => {
|
349 |
|
350 | const parentRow = event.target.closest("tr");
|
351 |
|
352 |
|
353 | const parentTable = event.target.closest("table");
|
354 |
|
355 |
|
356 | const section = parentRow.dataset.sectionheader;
|
357 |
|
358 |
|
359 | let query = null;
|
360 |
|
361 | if (section === "all") {
|
362 | query = "tr[data-section]";
|
363 | } else {
|
364 | query = 'tr[data-section=' + section + ']';
|
365 | }
|
366 |
|
367 | const sectionRows = parentTable.querySelectorAll(query);
|
368 |
|
369 | for (let i = 0; i < sectionRows.length; i++) {
|
370 |
|
371 | const currentItem = sectionRows[i];
|
372 |
|
373 | if (currentItem.classList.contains('is-hidden')) {
|
374 |
|
375 | currentItem.classList.remove('is-hidden');
|
376 | currentItem.classList.add('is-visible');
|
377 | currentItem.setAttribute('aria-hidden', 'false');
|
378 | parentRow.setAttribute('aria-expanded', 'true');
|
379 |
|
380 | } else {
|
381 |
|
382 | currentItem.classList.add('is-hidden');
|
383 | currentItem.classList.remove('is-visible');
|
384 | currentItem.setAttribute('aria-hidden', 'true');
|
385 | parentRow.setAttribute('aria-expanded', 'false');
|
386 |
|
387 | }
|
388 |
|
389 | }
|
390 |
|
391 | if (section === "all") {
|
392 |
|
393 | let subSection = document.querySelectorAll("tbody tr.collapsable");
|
394 |
|
395 | if (parentRow.getAttribute('aria-expanded') === "true") {
|
396 |
|
397 | for (let i = 0; i < subSection.length; i++) {
|
398 |
|
399 | const currentItem = subSection[i];
|
400 |
|
401 | currentItem.setAttribute('aria-hidden', 'false');
|
402 | currentItem.setAttribute('aria-expanded', 'true');
|
403 |
|
404 | }
|
405 |
|
406 | } else {
|
407 |
|
408 | for (let i = 0; i < subSection.length; i++) {
|
409 |
|
410 | const currentItem = subSection[i];
|
411 |
|
412 | currentItem.setAttribute('aria-hidden', 'true');
|
413 | currentItem.setAttribute('aria-expanded', 'false');
|
414 |
|
415 | }
|
416 |
|
417 | }
|
418 |
|
419 | }
|
420 |
|
421 | };
|
422 |
|
423 | const initCollapsability = () => {
|
424 |
|
425 | const collapseTable = document.querySelectorAll('.hoo-table.is-collapsable');
|
426 | collapseTable.forEach(table => {
|
427 |
|
428 | const collapseRow = table.querySelectorAll('.collapsable');
|
429 |
|
430 | collapseRow.forEach(tableRow => {
|
431 | tableRow.addEventListener('click', collapseAndExpand);
|
432 | });
|
433 |
|
434 | });
|
435 |
|
436 | };
|
437 |
|
438 | const position = {
|
439 | "left": "left",
|
440 | "right": "right",
|
441 | "top": "top",
|
442 | "bottom": "bottom"
|
443 | };
|
444 |
|
445 | const stickyOffsetFixup = (parent, selector, offset) => {
|
446 |
|
447 | const innerDefinition = parent.querySelectorAll(selector);
|
448 |
|
449 | for (let j = 0; j < innerDefinition.length; j++) {
|
450 |
|
451 | const innerElement = innerDefinition[j];
|
452 |
|
453 | if (offset === position.left) {
|
454 | innerElement.style[offset] = innerElement.offsetLeft + "px";
|
455 | }
|
456 | if (offset === position.right) {
|
457 | innerElement.style[offset] = innerElement.offsetRight + "px";
|
458 | }
|
459 | if (offset === position.top) {
|
460 | innerElement.style[offset] = innerElement.offsetTop + "px";
|
461 | }
|
462 | if (offset === position.bottom) {
|
463 | innerElement.style[offset] = innerElement.offsetBottom + "px";
|
464 | }
|
465 |
|
466 | }
|
467 |
|
468 | };
|
469 |
|
470 | const initSticky = () => {
|
471 |
|
472 | const allStickyTables = document.querySelectorAll("table.sticky");
|
473 |
|
474 | for (let i = 0; i < allStickyTables.length; i++) {
|
475 |
|
476 | const stickyTable = allStickyTables[i];
|
477 |
|
478 | stickyOffsetFixup(stickyTable, "tr td.is-sticky.left", position.left);
|
479 | stickyOffsetFixup(stickyTable, "tr th.is-sticky.left", position.left);
|
480 |
|
481 | }
|
482 | };
|
483 |
|
484 | const initTables = () => {
|
485 |
|
486 | initCollapsability();
|
487 | initSticky();
|
488 |
|
489 | };
|
490 |
|
491 | const elemPivotBar = '.hoo-pivotbar';
|
492 | const elemPivotButton = '.hoo-button-pivot';
|
493 | const dropDownPivotButton = '.hoo-navitem-text';
|
494 | const stateIsActive = 'is-active';
|
495 |
|
496 | const changePivot = (event) => {
|
497 | event.preventDefault();
|
498 |
|
499 | console.log(event.target);
|
500 |
|
501 | let currentButton = event.target.classList.contains(elemPivotButton.substr(1)) ? event.target : event.target.closest(elemPivotButton);
|
502 | if (!currentButton) {
|
503 | currentButton = event.target.classList.contains(dropDownPivotButton.substr(1)) ? event.target : event.target.closest(dropDownPivotButton);
|
504 | }
|
505 |
|
506 | const currentPivotBar = event.target.closest(elemPivotBar);
|
507 |
|
508 | const allButtons = currentPivotBar.querySelectorAll(elemPivotButton);
|
509 |
|
510 | allButtons.forEach(item => {
|
511 | item.classList.remove(stateIsActive);
|
512 | });
|
513 |
|
514 | currentButton.classList.add(stateIsActive);
|
515 |
|
516 | };
|
517 |
|
518 |
|
519 | const initPivot = () => {
|
520 |
|
521 |
|
522 | const pivotBarsButtons = document.querySelectorAll(`${elemPivotBar} ${elemPivotButton}`);
|
523 | pivotBarsButtons.forEach(pivotBarsButton => {
|
524 | pivotBarsButton.dataset.ref = pivotBarsButton.textContent.trim();
|
525 | pivotBarsButton.addEventListener('click', changePivot);
|
526 | });
|
527 |
|
528 | };
|
529 |
|
530 |
|
531 |
|
532 | const handleMenuItems = (event) => {
|
533 |
|
534 | console.log(event);
|
535 |
|
536 | let curNavItem = event.target;
|
537 | let curNavMenu = curNavItem.closest('.hoo-navitem');
|
538 |
|
539 | console.log(curNavMenu);
|
540 | console.log(curNavMenu.getAttribute('aria-expanded'));
|
541 | console.log(typeof curNavMenu.getAttribute('aria-expanded'));
|
542 |
|
543 | console.log(" LOOMA ::: ",
|
544 | curNavMenu.getAttribute('aria-expanded'),
|
545 | Boolean(curNavMenu.getAttribute('aria-expanded')),
|
546 | Boolean(curNavMenu.getAttribute('aria-expanded')) === true
|
547 | );
|
548 |
|
549 | if (curNavMenu.getAttribute('aria-expanded') === 'true') {
|
550 |
|
551 | curNavMenu.setAttribute('aria-expanded', false);
|
552 |
|
553 | } else {
|
554 |
|
555 | curNavMenu.setAttribute('aria-expanded', true);
|
556 |
|
557 | }
|
558 |
|
559 | };
|
560 |
|
561 | const initMenu = () => {
|
562 |
|
563 | let menuItems = document.querySelectorAll('.hoo-navitem[aria-expanded]');
|
564 |
|
565 | menuItems.forEach(item => {
|
566 |
|
567 | item.addEventListener('click', handleMenuItems);
|
568 |
|
569 | });
|
570 |
|
571 |
|
572 | };
|
573 |
|
574 | const overflowItems = [];
|
575 | const defaultOffset = 40;
|
576 |
|
577 | |
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 | const getOverflowItems = (targetWidth, children, curContainer, itemIndex) => {
|
584 |
|
585 | let curOverFlowItems = overflowItems[itemIndex].filter(item => {
|
586 | return item.overallWidth > targetWidth - defaultOffset;
|
587 | });
|
588 |
|
589 | let curItems = overflowItems[itemIndex].filter(item => {
|
590 | return item.overallWidth < targetWidth - defaultOffset;
|
591 | });
|
592 |
|
593 |
|
594 | let overflowControl = curContainer.querySelector('.hoo-buttonicon-overflow .hoo-buttonflyout');
|
595 |
|
596 | if (overflowControl && overflowControl.children.length < curOverFlowItems.length) {
|
597 |
|
598 | for (let i = 0; i < curOverFlowItems.length; i++) {
|
599 |
|
600 | if (curContainer.querySelector("[data-ref=" + curOverFlowItems[i].ref + "]") !== null) {
|
601 |
|
602 | let listItem = document.createElement('li');
|
603 |
|
604 |
|
605 | listItem.appendChild(
|
606 | curContainer.querySelector("[data-ref=" + curOverFlowItems[i].ref + "]")
|
607 | );
|
608 |
|
609 |
|
610 | overflowControl.appendChild(listItem);
|
611 |
|
612 | }
|
613 |
|
614 | }
|
615 | }
|
616 |
|
617 |
|
618 | if(overflowControl.children.length !== 0){
|
619 |
|
620 | var buttonEnabled = overflowControl.closest('.hoo-buttonicon-overflow');
|
621 |
|
622 | if(buttonEnabled){
|
623 | buttonEnabled.classList.add('is-active');
|
624 | }
|
625 |
|
626 | } else {
|
627 |
|
628 | var buttonEnabled = overflowControl.closest('.hoo-buttonicon-overflow');
|
629 |
|
630 | if(buttonEnabled){
|
631 | buttonEnabled.classList.remove('is-active');
|
632 | }
|
633 |
|
634 | }
|
635 |
|
636 | if (overflowControl && overflowControl.children.length > curOverFlowItems.length) {
|
637 |
|
638 | for (let i = 0; i < curItems.length; i++) {
|
639 |
|
640 | if (overflowControl.querySelector("[data-ref=" + curItems[i].ref + "]") !== null) {
|
641 |
|
642 | let overflowElement = overflowControl.querySelector("[data-ref=" + curItems[i].ref + "]");
|
643 |
|
644 |
|
645 | curContainer.appendChild(overflowElement);
|
646 |
|
647 | }
|
648 |
|
649 | }
|
650 |
|
651 | }
|
652 |
|
653 |
|
654 | |
655 |
|
656 |
|
657 | for(let i = 0; i < overflowControl.children.length; i++){
|
658 |
|
659 | if(overflowControl.children[i].children.length === 0){
|
660 |
|
661 | overflowControl.children[i].remove();
|
662 |
|
663 | }
|
664 |
|
665 | }
|
666 |
|
667 |
|
668 | };
|
669 |
|
670 |
|
671 | |
672 |
|
673 |
|
674 | const entryHandler = (entry, index) => {
|
675 |
|
676 | let childButtons = entry.target.parentElement.querySelectorAll('.hoo-overflow > *');
|
677 |
|
678 | getOverflowItems(entry.target.parentElement.clientWidth, childButtons, entry.target, index);
|
679 |
|
680 | };
|
681 |
|
682 | |
683 |
|
684 |
|
685 |
|
686 |
|
687 | const overflow = (entries, observer) => {
|
688 |
|
689 |
|
690 | entries.forEach((item, index) => {
|
691 |
|
692 | initOverflowElements(item.target.children, index);
|
693 |
|
694 | entryHandler(item, index);
|
695 |
|
696 | });
|
697 |
|
698 | };
|
699 |
|
700 | |
701 |
|
702 |
|
703 |
|
704 |
|
705 | const initOverflowElements = (children, index) => {
|
706 |
|
707 | let overallWidth = 0;
|
708 |
|
709 | if (overflowItems.length <= index) {
|
710 |
|
711 | overflowItems[index] = [];
|
712 |
|
713 | for (let i = 0; i < children.length; i++) {
|
714 |
|
715 | overallWidth += children[i].clientWidth;
|
716 |
|
717 | if (!children[i].classList.contains("hoo-buttonicon-overflow")) {
|
718 |
|
719 | let currentItem = {
|
720 | chlld: children[i],
|
721 | ref: "ref-" + index + "-" + i,
|
722 | width: children[i].clientWidth,
|
723 | overallWidth: overallWidth
|
724 | };
|
725 |
|
726 | children[i].dataset.ref = currentItem.ref;
|
727 |
|
728 | overflowItems[index].push(currentItem);
|
729 |
|
730 | }
|
731 |
|
732 | }
|
733 |
|
734 | }
|
735 |
|
736 | };
|
737 |
|
738 |
|
739 | const init = () => {
|
740 |
|
741 | let items = document.querySelectorAll('.hoo-overflow');
|
742 |
|
743 | if (items.length !== 0) {
|
744 |
|
745 | const ofObserver = new ResizeObserver(overflow);
|
746 |
|
747 | items.forEach(item => {
|
748 |
|
749 | ofObserver.observe(item);
|
750 |
|
751 | });
|
752 |
|
753 | }
|
754 |
|
755 | };
|
756 |
|
757 | const splitButtonReg = (classSelector, handleWith) => {
|
758 |
|
759 | let allSplitButtons = document.querySelectorAll(classSelector);
|
760 |
|
761 | allSplitButtons.forEach(element => {
|
762 |
|
763 | element.addEventListener('click', (event) => {
|
764 | handleWith(event);
|
765 | });
|
766 |
|
767 | });
|
768 |
|
769 | };
|
770 |
|
771 | const _btnFlyOut = (curSplitButton, parentElement) => {
|
772 |
|
773 |
|
774 |
|
775 | let ariaPressed = curSplitButton.getAttribute('aria-pressed');
|
776 | if (ariaPressed === undefined) {
|
777 | curSplitButton.setAttribute('aria-pressed', true);
|
778 | } else {
|
779 | curSplitButton.setAttribute('aria-pressed', !ariaPressed);
|
780 | }
|
781 |
|
782 | parentElement.classList.toggle('show-flyout');
|
783 |
|
784 | };
|
785 |
|
786 | const buttonClick = (event) => {
|
787 |
|
788 | let curSplitButton = event.target;
|
789 | let parentElement = curSplitButton.parentElement;
|
790 |
|
791 | _btnFlyOut(curSplitButton, parentElement);
|
792 |
|
793 | };
|
794 |
|
795 | const splitButtonClick = (event) => {
|
796 |
|
797 | console.log("\nEVENT: splitButtonClick");
|
798 | let curSplitButton = event.target;
|
799 | let parentElement = curSplitButton.parentElement;
|
800 |
|
801 | _btnFlyOut(curSplitButton, parentElement);
|
802 |
|
803 | };
|
804 |
|
805 | const animateDeleteAndSlide = (event) => {
|
806 |
|
807 |
|
808 | let eventTarget = event.target;
|
809 | let animationClass = eventTarget.parentElement.dataset.animation;
|
810 |
|
811 |
|
812 | eventTarget.classList.add(animationClass);
|
813 |
|
814 | let computedStyles = window.getComputedStyle(eventTarget);
|
815 | let animationDuration = parseFloat(computedStyles.getPropertyValue('animation-duration')) * 1000;
|
816 |
|
817 |
|
818 | console.log(
|
819 | computedStyles,
|
820 | computedStyles.getPropertyValue('animation-duration'),
|
821 | animationDuration
|
822 |
|
823 |
|
824 | );
|
825 |
|
826 | setTimeout(
|
827 | () => {
|
828 | eventTarget.remove();
|
829 | }, animationDuration
|
830 | );
|
831 |
|
832 | };
|
833 |
|
834 | const animateAddAndSlide = (event) => {
|
835 |
|
836 | let eventTarget = event.target;
|
837 |
|
838 | let animationClass = eventTarget.parentElement.dataset.animation;
|
839 |
|
840 |
|
841 | eventTarget.classList.add(animationClass);
|
842 |
|
843 | let newDomElement = document.importNode(eventTarget, true);
|
844 | newDomElement.classList.add(animationClass);
|
845 |
|
846 | let computedStyles = window.getComputedStyle(newDomElement);
|
847 | let animationDuration = parseFloat(computedStyles.getPropertyValue('animation-duration')) * 1000;
|
848 |
|
849 |
|
850 | event.target.parentElement.appendChild(newDomElement);
|
851 |
|
852 | newDomElement.addEventListener('click', animateAddAndSlide);
|
853 |
|
854 | console.log(
|
855 | computedStyles,
|
856 | computedStyles.getPropertyValue('animation-duration'),
|
857 | animationDuration
|
858 |
|
859 |
|
860 | );
|
861 |
|
862 | setTimeout(
|
863 | () => {
|
864 | newDomElement.classList.remove('anim-add-slide');
|
865 | }, animationDuration
|
866 | );
|
867 |
|
868 | };
|
869 |
|
870 | const registerAnimation = (classname, handleWith) => {
|
871 |
|
872 | let animAtionBlocks = document.querySelectorAll(classname + ' > .sg-anim-block');
|
873 |
|
874 | animAtionBlocks.forEach(element => {
|
875 | element.addEventListener('click', handleWith);
|
876 | });
|
877 |
|
878 | };
|
879 |
|
880 | const registerAriaSelect = () => {
|
881 |
|
882 | let selects = document.querySelectorAll('.hoo-select');
|
883 |
|
884 |
|
885 |
|
886 | if (selects) {
|
887 | selects.forEach((item, idx) => {
|
888 | ariaSelect(item);
|
889 | });
|
890 | }
|
891 | };
|
892 |
|
893 |
|
894 | const afterLoaded = () => {
|
895 |
|
896 | splitButtonReg('.hoo-buttonsplit > .hoo-buttonsplit-carret', splitButtonClick);
|
897 | splitButtonReg('.hoo-buttonsplit-primary > .hoo-buttonsplit-carret', splitButtonClick);
|
898 | splitButtonReg('button.hoo-buttonicon-overflow', buttonClick);
|
899 |
|
900 | splitButtonReg('button.hoo-buttoncmd', buttonClick);
|
901 | splitButtonReg('button.hoo-buttoncmdbar', buttonClick);
|
902 | splitButtonReg('button.hoo-buttonicon-flyout', buttonClick);
|
903 | splitButtonReg('button.hoo-buttoncontext', buttonClick);
|
904 |
|
905 |
|
906 | registerAnimation('.anim-deleteNslide', animateDeleteAndSlide);
|
907 | registerAnimation('.anim-addNslide', animateAddAndSlide);
|
908 |
|
909 | registerDialog();
|
910 | registerAriaSelect();
|
911 |
|
912 |
|
913 | initTables();
|
914 |
|
915 | initPivot();
|
916 |
|
917 | initMenu();
|
918 |
|
919 | init();
|
920 |
|
921 | setTimeout(() => {
|
922 | let tmpHidden = document.querySelectorAll('.tmp-hidden');
|
923 |
|
924 | console.log(tmpHidden);
|
925 |
|
926 | tmpHidden.forEach(item => {
|
927 | item.addEventListener("focus", (event) => {
|
928 |
|
929 | event.target.classList.remove('.tmp-hidden');
|
930 |
|
931 | console.log(tmpHidden);
|
932 |
|
933 | });
|
934 | });
|
935 | }, 1000);
|
936 |
|
937 |
|
938 | };
|
939 |
|
940 | window.onload = afterLoaded();
|
941 |
|
942 | });
|