PageSourceSearch

https://economicus.ue.katowice.pl/javax.faces.resource/script/wcagFixes.js.seam?op_v=1786395210739

js ue.katowice.pl collected 2026-09-24 09:16:00 UTC 61,286 bytes, 1,521 lines download raw bytes

1(function () {
2    var global = this;
3    var focusOnInfoTabParamName = 'focusOnInfoTab';
4    var isMaterialTooltipExtended = false;
5    var setFocusLocalStorageItemName = 'setFocusAfterReloadToElementSelector';
6    var disableClickFlag = false;
7    var scrollTimer;
8
9    $(window).scroll(function () {
10        disableClickFlag = true;
11
12        clearTimeout(scrollTimer);
13
14        scrollTimer = setTimeout(function () {
15            disableClickFlag = false;
16        }, 250);
17    });
18
19    function i18n(key) {
20        return global.omegaI18n(key);
21    }
22
23    $.fn.changeElementType = function (newType) {
24        if (!this[0]) {
25            return;
26        }
27
28        var attrs = {};
29
30        $.each(this[0].attributes, function (idx, attr) {
31            attrs[attr.nodeName] = attr.nodeValue;
32        });
33
34        this.replaceWith(function () {
35            return $("<" + newType + "/>", attrs).append($(this).contents());
36        });
37    };
38
39    global.applyWcagFixes = function () {
40        //Hacky way to fix wcag errors in some third party components without sufficient builtin options
41        var lang = global.omegaCurrentLanguage;
42        fixMainPageHeading();
43
44        $(".ui-dialog-titlebar-maximize").attr("aria-label", i18n("dialog.maximize"));
45
46        initInfoTabs();
47        initFieldsetToggles();
48        applyTreeViewWcagFixes();
49        fixEdgeRowHoverBug();
50        fixSkipLinksFocusWithin();
51        hideEmptyListItems();
52        removeEmptyLists();
53        extendMaterialTooltip();
54        $("#entitiesT_paginator_bottom").attr("aria-label", i18n("resultList.pagination"));
55        checkFocusAfterPageReload(false);
56        fixAnchorsWithTargetBlank();
57    };
58
59    jQuery(document).ready(function () {
60        global.applyWcagFixes();
61        fixMdlMenu();
62        fixIOsDoubleClick();
63        checkFocusAfterPageReload(true);
64        setUpFocusAfterReloadToElementSelector(".clearSearchButton");
65    });
66
67    function fixAnchorsWithTargetBlank() {
68        // fallback fix for links with target=_blank
69        var title = i18n("wcag.targetblank.explanation").trim();
70        $("a[target='_blank']").each(function (index) {
71            if (!$(this).attr("title")) {
72                $(this).attr("title", title);
73            }
74        });
75
76        $("a > span.sr-only, a > span.visuallyhidden").each(function (index) {
77            if ($(this).text().trim() === title) {
78                var a = $(this).closest("a");
79                if (!a.attr("title") && (a.attr("target") === "_blank" || (a.attr("onclick") && a.attr("onclick").trim().endsWith("'blank')")))) {
80                    a.attr("title", title);
81                }
82                $(this).remove();
83            }
84        });
85    }
86
87    function setUpFocusAfterReloadToElementSelector(selector) {
88        $(selector)
89            .off("click.setFocusAfterReload")
90            .on("click.setFocusAfterReload", function () {
91                if (typeof localStorage === "undefined" || !localStorage) {
92                    return;
93                }
94
95                localStorage.setItem(setFocusLocalStorageItemName, selector);
96            });
97    }
98
99    function checkFocusAfterPageReload(remove) {
100        if (typeof localStorage === "undefined" || !localStorage) {
101            return;
102        }
103
104        var sel = localStorage.getItem(setFocusLocalStorageItemName);
105        if (sel) {
106            if (remove) {
107                localStorage.removeItem(setFocusLocalStorageItemName);
108            }
109
110            $(sel).focus();
111        }
112    }
113
114    function fixIOsDoubleClick() {
115        $("a")
116            .off("touchend.fixIOsDoubleClick")
117            .on("touchend.fixIOsDoubleClick", function (e) {
118                if (!e.ctrlKey && !disableClickFlag) {
119                    var el = $(this);
120                    var link = el.attr("href");
121                    window.location = link;
122                }
123            });
124    }
125
126    var autocompleteInputSizeById = {};
127
128    function fixRwd() {
129        var width = $(window).width();
130        $('input.ui-autocomplete-input').each(function (index) {
131            var $input = $(this);
132            var id = $input.attr('id') || '__index__' + index;
133
134            var origSize = autocompleteInputSizeById[id];
135            if (width < 550) {
136                if (!origSize) {
137                    autocompleteInputSizeById[id] = $input.attr('size');
138                }
139                $input.removeAttr('size');
140            } else {
141                if (origSize) {
142                    $input.attr('size', origSize);
143                }
144            }
145        });
146
147    }
148
149    $(window).off("resize.wcagFixes").on("resize.wcagFixes", fixRwd);
150    fixRwd();
151
152    function fixMainPageHeading() {
153        $('#omegaMainPageHeading .main-heading-placeholder').remove();
154        var text = $('#omegaMainPageHeading').text();
155        if (!text || !text.trim()) {
156            $('#omegaMainPageHeading').html(document.title);
157        }
158    }
159
160    function fixMdlMenu() {
161
162        $(".mdl-menu").off('keydown.currentlyShownMdlMenu click.currentlyShownMdlMenu').on('keydown.currentlyShownMdlMenu click.currentlyShownMdlMenu', function (e) {
163            if (e.key === "Escape") {
164                var $menu = $(this);
165                var $target = $('#' + $menu.attr('for'));
166                $target.attr("aria-expanded", "false")
167            }
168        });
169
170    }
171
172    function hideEmptyListItems() {
173        $('li:not(.li-show-empty)').filter(function () {
174            return $.trim($(this).html()) === '';
175        }).hide()
176    }
177
178    function removeEmptyLists() {
179        $('ul.ul-remove-if-empty').filter(function () {
180            return $.trim($(this).html()) === '';
181        }).remove()
182    }
183
184    function trimLastBreadcrumbItem() {
185        var $lastItem = $('.breadCrumb ul li:last-of-type');
186
187        var text = $lastItem.text().trim();
188        var maxLength = 100;
189        if (text.length > maxLength) {
190
191            var newText = "";
192            var tokens = text.split(/\s+/);
193            var nextToken;
194            while ((nextToken = tokens.shift()) !== undefined && newText.length + nextToken.length + 1 < maxLength - 3) {
195                newText += " " + nextToken;
196            }
197
198            if (newText.length < 20) {
199                newText = text.substring(0, maxLength-3).trim();
200            }
201
202            $lastItem.html(newText+"...");
203        }
204
205    }
206
207    trimLastBreadcrumbItem();
208    global.applyWcagFixes();
209
210    function initInfoTabs() {
211        if (getParameterByName(focusOnInfoTabParamName) === 'true') {
212            $('.infoTabs [role="tab"][tabindex="0"]').focus();
213        }
214
215        $('.infoTabs').each(function (index) {
216            var container = $(this);
217            var ajaxTabs = container.hasClass('infoTabs--ajax')
218            var tabs = container.find('[role="tab"]');
219
220            if (!ajaxTabs) {
221                tabs.unbind("click.tab", changeTabs);
222                tabs.bind("click.tab", changeTabs);
223            }
224
225            tabs.unbind("keydown.tab");
226            tabs.bind("keydown.tab", function (e) {
227
228                if (e.key === "Enter" || e.which === 13 || e.keyCode === 13) {
229                    if (!ajaxTabs) {
230                        changeTabs.call(this, e, true);
231                    }
232                    return;
233                }
234
235                if (e.keyCode === 39 || e.keyCode === 37) {
236                    var tabFocus = $(this).index();
237
238                    tabs[tabFocus].setAttribute("tabindex", -1);
239                    if (e.keyCode === 39) { // Move right
240                        tabFocus++;
241                        // If we're at the end, go to the start
242                        if (tabFocus >= tabs.length) {
243                            tabFocus = 0;
244                        }
245
246                    } else if (e.keyCode === 37) { // Move left
247                        tabFocus--;
248                        // If we're at the start, move to the end
249                        if (tabFocus < 0) {
250                            tabFocus = tabs.length - 1;
251                        }
252                    }
253
254                    tabs[tabFocus].setAttribute("tabindex", 0);
255                    tabs[tabFocus].focus();
256                }
257            });
258        })
259    }
260
261    function changeTabs(e, enterKey) {
262        e.preventDefault();
263
264        var link = $(this);
265        var href = link.attr('href');
266
267        if (enterKey) {
268            href += '&' + focusOnInfoTabParamName + '=true'
269        }
270
271        window.open(href, e.ctrlKey ? "_blank" : "_self")
272    }
273
274    function getParameterByName(name, url) {
275        if (!url) {
276            url = window.location.href;
277        }
278        name = name.replace(/[\[\]]/g, "\\$&");
279        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
280            results = regex.exec(url);
281        if (!results) return null;
282        if (!results[2]) return '';
283        return decodeURIComponent(results[2].replace(/\+/g, " "));
284    }
285
286    function initFieldsetToggles() {
287
288        var fieldsets = $('.ui-fieldset-toggleable:not(.wcag-upgraded)');
289
290        fieldsets.each(function (index) {
291            var fs = $(this);
292            var legend = fs.find('legend');
293            var content = fs.find('.ui-fieldset-content');
294            if (legend && content) {
295                var contentId = content.attr('id');
296                if (!contentId) {
297                    contentId = 'ui-fieldset-content-omega-' + index;
298                    content.attr('id', contentId);
299                }
300                legend.attr('aria-expanded', content.is(":visible"));
301                legend.attr('aria-controls', contentId);
302
303                legend.unbind("click.legend");
304                legend.bind("click.legend", function (e) {
305                    legend.attr('aria-expanded', legend.attr('aria-expanded') === 'true' ? 'false' : 'true');
306                });
307
308            }
309        })
310    }
311
312    function applyTreeViewWcagFixes() {
313        $(".ui-tree .ui-treenode-content").each(function (index) {
314            var node = $(this).closest('li.ui-treenode');
315            var selected = node.attr('aria-selected');
316            if (typeof selected === 'undefined') {
317                selected = $(this).attr('aria-selected');
318            }
319
320            node.removeAttr("role");
321
322
323            $(this)
324                .find("ul")
325                .removeAttr("role");
326
327            var expandable = !!node.find('.ui-tree-toggler').length;
328
329            $(this).attr('aria-selected', selected).removeAttr('aria-checked');
330            var nodeLabel = $(this).find('.ui-treenode-label');
331            nodeLabel.attr('aria-selected', selected).removeAttr('aria-checked');
332
333            if (!expandable) {
334                nodeLabel.removeAttr('aria-expanded');
335                $(this).removeAttr('aria-expanded');
336            } else {
337                if (typeof nodeLabel.attr('aria-expanded') === 'undefined') {
338                    nodeLabel.attr('aria-expanded', $(this).attr('aria-expanded'))
339                } else {
340                    $(this).attr('aria-expanded', nodeLabel.attr('aria-expanded'))
341                }
342            }
343
344
345        });
346
347        // $('.ui-menuitem-link ').attr('tabindex', "0");
348    }
349
350    global.applyTreeViewWcagFixes = applyTreeViewWcagFixes;
351
352    function fixEdgeRowHoverBug() {
353        $(".resultDataListPanel .entitiesDataList .ui-dataview-row") //TODO hover still not working properly
354            .off('mouseenter mouseleave focusin focusout')
355            .on('mouseenter focusin', function () {
356                $(this).addClass('with-hover-or-focus')
357            })
358            .on('mouseleave focusout', function () {
359                $(this).removeClass('with-hover-or-focus')
360            })
361
362    }
363
364    function fixSkipLinksFocusWithin() {
365        $("ul.omega-skip-link-list, ul.omega-skip-link-list a")
366            .off('focusin focusout')
367            .on('focusin', function () {
368                $(this).addClass('focus-within')
369            })
370            .on('focusout', function () {
371                $(this).removeClass('focus-within')
372            })
373
374    }
375
376    function removeUnnecessaryAttributesFromControls() {
377        $('#topToolbar').removeAttr('role');
378        $('#hideFiltersDataListButtonId').removeAttr('role');
379
380        if (PrimeFaces.widget.Toolbar) {
381            PrimeFaces.widget.Toolbar = PrimeFaces.widget.Toolbar.extend({
382                init: function (cfg) {
383                    this._super(cfg);
384                    this.jq.removeAttr('role');
385                }
386            });
387        }
388
389        if (PrimeFaces.widget.CommandButton) {
390            PrimeFaces.widget.CommandButton = PrimeFaces.widget.CommandButton.extend({
391                init: function (cfg) {
392                    this._super(cfg);
393                    PrimeFaces.skinButton(this.jq);
394                    this.jq.removeAttr('role');
395                }
396            });
397        }
398    }
399
400    removeUnnecessaryAttributesFromControls();
401
402    function extendMaterialTooltip() {
403
404        if (!isMaterialTooltipExtended && typeof MaterialTooltip !== 'undefined') {
405            isMaterialTooltipExtended = true;
406            MaterialTooltip.prototype.superInit = MaterialTooltip.prototype.init;
407            var hideDelay = 800;
408
409
410            var visibleMdlPopups = [];
411            $(document).off('keydown.currentlyShownMdlTooltips').on('keydown.currentlyShownMdlTooltips', function (e) {
412                if (e.key === "Escape") {
413                    e.preventDefault();
414                    hideVisibleMdlPopups();
415                }
416            });
417
418            function hideVisibleMdlPopups(excluded) {
419                visibleMdlPopups.forEach(function (t) {
420                    if (excluded === t) {
421                        return;
422                    }
423                    t._isInPopup = false;
424                    t.hideTooltipExt();
425                });
426            }
427
428            MaterialTooltip.prototype.init = function () {
429
430                if (this.element_) {
431                    var $this = this;
432                    var element_ = $(this.element_).detach();
433                    $('body').append(element_);
434                    this.element_ = element_.get(0);
435                    var forElId = this.element_.getAttribute('for') || this.element_.getAttribute('data-mdl-for');
436                    if (forElId) {
437                        this.forElement_ = document.getElementById(forElId);
438                    }
439                    if (this.forElement_) {
440                        var ce = this.forElement_;
441                        while ((ce = ce.parentNode) && ce.children.length === 1) { //rebind for element for direct anchor parent, if exists
442                            if (ce.tagName.toLowerCase() === 'a') {
443                                this.forElement_ = ce;
444                                break;
445                            }
446                        }
447
448                        var focusableElements = ['a', 'button', 'select', 'input', 'textarea'];
449                        if (!this.forElement_.hasAttribute('tabindex') && focusableElements.indexOf(ce.tagName.toLowerCase()) < 0) {
450                            this.forElement_.setAttribute('tabindex', '0');
451                        }
452
453                        this.boundMouseEnterHandler = this.handleMouseEnterExt.bind(this);
454
455                        $(this.forElement_).off('focus.MaterialTooltip').on('focus.MaterialTooltip', this.boundMouseEnterHandler);
456                        $(this.forElement_).off('focusout.MaterialTooltip').on('focusout.MaterialTooltip', this.hideTooltipExt.bind(this));
457
458                        this.boundMouseLeaveAndScrollHandler = this.mouseLeaveAndScrollHandler.bind(this);
459                        this.forElement_.addEventListener('mouseenter', this.boundMouseEnterHandler, false);
460                        this.forElement_.addEventListener('touchend', this.boundMouseEnterHandler, false);
461                        this.forElement_.addEventListener('mouseleave', this.boundMouseLeaveAndScrollHandler, false);
462
463
464                        $(this.element_).off('mouseover.tooltipMdl mouseleave.tooltipMdl')
465                            .on('mouseover.tooltipMdl', function (e) {
466                                $this.isInPopup = true;
467                            })
468                            .on('mouseleave.tooltipMdl', function () {
469                                $this.isInPopup = false;
470                                $this.hideTooltipExt();
471                            });
472
473                        window.addEventListener('scroll', this.boundMouseLeaveAndScrollHandler, true);
474                        window.addEventListener('touchstart', this.boundMouseLeaveAndScrollHandler);
475                    }
476                }
477            };
478            MaterialTooltip.prototype.handleMouseEnterExt = function () {
479                hideVisibleMdlPopups(this);
480                if (this.timeout) {
481                    clearTimeout(this.timeout);
482                }
483                this.handleMouseEnter_.apply(this, arguments);
484                visibleMdlPopups.push(this);
485            };
486
487            MaterialTooltip.prototype.mouseLeaveAndScrollHandler = function (event) {
488                if (event.type === 'scroll') {
489                    this.hideTooltipExt(event);
490                    return;
491                }
492                var $this = this;
493                if (this.timeout) {
494                    clearTimeout(this.timeout);
495                }
496                this.timeout = setTimeout(function () {
497                    if (!$this.isInPopup) {
498                        $this.hideTooltipExt();
499                    }
500
501                }, hideDelay);
502
503            };
504            MaterialTooltip.prototype.hideTooltipExt = function (event) {
505                const index = visibleMdlPopups.indexOf(this);
506                if (index > -1) {
507                    visibleMdlPopups.splice(index, 1);
508                }
509                this.hideTooltip_(event);
510            }
511        }
512    }
513
514    extendMaterialTooltip();
515
516
517    //https://github.com/primefaces/primefaces/blob/master/src/main/resources/META-INF/resources/primefaces/tooltip/tooltip.js
518    if (PrimeFaces.widget.Tooltip) {
519        PrimeFaces.widget.Tooltip = PrimeFaces.widget.Tooltip.extend({
520
521            init: function (cfg) {
522                cfg.showEvent = cfg.showEvent ? cfg.showEvent : 'mouseover.tooltip focus';
523                cfg.hideEvent = cfg.hideEvent ? cfg.hideEvent : 'mouseout.tooltip focusout';
524                cfg.hideDelay = cfg.hideDelay || 400;
525                this._super(cfg);
526
527            },
528            show: function () {
529                var $this = this;
530                $(document).off('keydown.currentlyShownTooltip').on('keydown.currentlyShownTooltip', function (e) {
531                    if (e.key === "Escape" && $this.isVisible()) {
532                        e.preventDefault();
533                        $this.isInPopup = false;
534                        $this._hide();
535                    }
536                });
537
538                this._super();
539            },
540
541            /**
542             * Sets up all event listeners on the target component that are required for the tooltip.
543             * @private
544             */
545            bindTarget: function () {
546                var revertDescribedBy = true; // TODO add param
547                this.target = PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(this.cfg.target);
548                var prevDescribedBy = this.target.attr("aria-describedby");
549
550                this._super();
551                var $this = this;
552                this.isInPopup = false;
553                this.jq.off(this.cfg.showEvent + ' ' + this.cfg.hideEvent)
554                    .on(this.cfg.showEvent, function (e) {
555                        $this.isInPopup = true;
556                    })
557                    .on(this.cfg.hideEvent + '.tooltip', function () {
558                        $this.isInPopup = false;
559                        $this.hide();
560                    });
561
562                if (revertDescribedBy) {
563                    if (prevDescribedBy) {
564                        this.target.attr("aria-describedby", prevDescribedBy);
565                    } else {
566                        this.target.removeAttr("aria-describedby");
567                    }
568                }
569
570            },
571
572            hide: function () {
573                var $this = this;
574                this.clearTimeout();
575
576                if (this.cfg.hideDelay) {
577                    this.timeout = setTimeout(function () {
578                        if (!$this.isInPopup) {
579                            $this._hide();
580                        }
581
582                    }, this.cfg.hideDelay);
583                } else {
584                    this._hide();
585                }
586            }
587        });
588    }
589
590
591    //https://github.com/primefaces/primefaces/blob/master/src/main/resources/META-INF/resources/primefaces/dialog/dialog.js
592    if (PrimeFaces.widget.Dialog) {
593        PrimeFaces.widget.Dialog = PrimeFaces.widget.Dialog.extend({
594            init: function (cfg) {
595                this._super(cfg);
596                this.jq.removeAttr('role');
597
598                this.jq.find('.ui-dialog-titlebar-close .ui-icon')
599                    .removeClass('ui-icon ui-icon-closethick')
600                    .addClass('fa fa-fw fa-close')
601                    .attr('aria-hidden', 'true');
602                this.jq.find('.ui-dialog-titlebar-close')
603                    .attr("type", "button")
604                    .removeAttr("role")
605                    .removeAttr("aria-label")
606                    .removeAttr("href")
607                    .addClass('iconCommandButton');
608                this.jq.find('.ui-dialog-titlebar-close').changeElementType('button');
609                this.closeIcon = this.jq.find('.ui-dialog-titlebar-close');
610
611                var lang = global.omegaCurrentLanguage;
612                var isPl = lang === 'pl';
613                this.closeIcon.append($('<span class="visuallyhidden"/>').text(isPl ? 'Zamknij' : 'Close'));
614                var $this = this;
615                this.closeIcon.off('click').on('click', function (e) {
616                    $this.hide();
617                    e.preventDefault();
618                });
619            },
620            postShow: function () {
621                if (this.cfg.fitViewport) {
622                    this.fitViewport();
623                }
624
625                this.callBehavior('open');
626
627                PrimeFaces.invokeDeferredRenders(this.id);
628
629                //execute user defined callback
630                if (this.cfg.onShow) {
631                    this.cfg.onShow.call(this);
632                }
633
634                this.jq.attr({
635                    'aria-hidden': false
636                    , 'aria-live': 'off'
637                });
638
639                this.applyFocus();
640
641                $(".omega-main-layout-wrapper").attr('aria-hidden', 'true');
642            },
643
644            hide: function () {
645                $(".omega-main-layout-wrapper").attr('aria-hidden', 'false');
646                this._super.apply(this, arguments);
647
648            }
649        });
650    }
651
652    //https://github.com/primefaces/primefaces/blob/master/src/main/resources/META-INF/resources/primefaces/autocomplete/autocomplete.js
653    if (PrimeFaces.widget.AutoComplete) {
654        PrimeFaces.widget.AutoComplete = PrimeFaces.widget.AutoComplete.extend({
655            init: function (cfg) {
656                this._super(cfg);
657                this.jq.removeAttr('role');
658            },
659
660            showSuggestions: function (query) {
661                this._super(query);
662                this.items.removeAttr('role');
663            },
664
665            /**
666             * Sets up all keyboard related event listeners.
667             * @private
668             */
669            bindKeyEvents: function () {
670                this._super();
671                var $this = this;
672                this.input.off('keyup.autoComplete').on('keyup.autoComplete', function (e) {
673                    var keyCode = $.ui.keyCode,
674                        key = e.which;
675
676                    if (PrimeFaces.env.isIE(9) && (key === keyCode.BACKSPACE || key === keyCode.DELETE)) {
677                        $this.processKeyEvent(e);
678                    }
679
680                    if ($this.cfg.queryEvent === 'enter' && (key === keyCode.ENTER)) {
681                        if ($this.itemSelectedWithEnter)
682                            $this.itemSelectedWithEnter = false;
683                        else
684                            $this.search($this.input.val());
685                    }
686
687                    if ($this.panel.is(':visible')) {
688                        if (key === keyCode.ESCAPE) {
689                            $this.hide();
690                        } else if (key === keyCode.UP || key === keyCode.DOWN) {
691                            var highlightedItem = $this.items.filter('.ui-state-highlight');
692                            if (highlightedItem.length) {
693                                // highlightedItem.focus();
694                                var label = highlightedItem.data('item-label');
695
696                                if (!label) {
697                                    markHiddenChildrenForRemoval(highlightedItem);
698                                    var clone = highlightedItem.clone();
699                                    clone.find('.__invisible-elements__').remove();
700                                    label = clone.text();
701                                }
702
703                                label = "sugestia: " + label; //todo translation
704                                $this.displayAriaStatus(label);
705                            }
706                        }
707                    }
708
709                    $this.checkMatchedItem = true;
710                    $this.isTabPressed = false;
711
712                }).off('keydown.autoComplete').on('keydown.autoComplete', function(e) {
713                    var keyCode = $.ui.keyCode;
714
715                    $this.suppressInput = false;
716                    if($this.panel.is(':visible')) {
717                        var highlightedItem = $this.items.filter('.ui-state-highlight');
718
719                        switch(e.which) {
720                            case keyCode.UP:
721                                var prev = highlightedItem.length == 0 ? $this.items.eq(0) : highlightedItem.prevAll('.ui-autocomplete-item:first');
722
723                                if(prev.length == 1) {
724                                    highlightedItem.removeClass('ui-state-highlight');
725                                    prev.addClass('ui-state-highlight');
726
727                                    if($this.cfg.scrollHeight) {
728                                        PrimeFaces.scrollInView($this.panel, prev);
729                                    }
730
731                                    if($this.cfg.itemtip) {
732                                        $this.showItemtip(prev);
733                                    }
734                                }
735
736                                e.preventDefault();
737                                break;
738
739                            case keyCode.DOWN:
740                                var next = highlightedItem.length == 0 ? $this.items.eq(0) : highlightedItem.nextAll('.ui-autocomplete-item:first');
741
742                                if(next.length == 1) {
743                                    highlightedItem.removeClass('ui-state-highlight');
744                                    next.addClass('ui-state-highlight');
745
746                                    if($this.cfg.scrollHeight) {
747                                        PrimeFaces.scrollInView($this.panel, next);
748                                    }
749
750                                    if($this.cfg.itemtip) {
751                                        $this.showItemtip(next);
752                                    }
753                                }
754
755                                e.preventDefault();
756                                break;
757
758                            case keyCode.ENTER:
759                                if ($this.timeout) {
760                                    $this.deleteTimeout();
761                                }
762
763                                if (highlightedItem.length > 0) {
764                                    $this.preventInputChangeEvent = true;
765                                    highlightedItem.trigger("click");
766                                    $this.itemSelectedWithEnter = true;
767                                }else{
768                                    return; //submit form if nothing is selected
769                                }
770
771                                e.preventDefault();
772                                e.stopPropagation();
773
774                                break;
775
776                            case 18: //keyCode.ALT:
777                            case 224:
778                                break;
779
780                            case keyCode.TAB:
781                                if(highlightedItem.length && $this.cfg.autoSelection) {
782                                    highlightedItem.trigger('click');
783                                } else {
784                                    $this.hide();
785                                    if ($this.timeout) {
786                                        $this.deleteTimeout();
787                                    }
788                                }
789                                $this.isTabPressed = true;
790                                break;
791                        }
792                    }
793                    else {
794                        switch(e.which) {
795                            case keyCode.TAB:
796                                if ($this.timeout) {
797                                    $this.deleteTimeout();
798                                }
799                                $this.isTabPressed = true;
800                                break;
801
802                            case keyCode.ENTER:
803                                if($this.cfg.queryEvent === 'enter' || ($this.timeout > 0) || $this.querying) {
804                                    e.preventDefault();
805                                }
806
807                                if($this.cfg.queryEvent !== 'enter') {
808                                    $this.isValid($(this).val(), true);
809                                }
810                                break;
811
812                            case keyCode.BACKSPACE:
813                                if ($this.cfg.multiple && !$this.input.val().length) {
814
815                                    if (e.metaKey||e.ctrlKey||e.shiftKey) {
816                                        $this.removeAllItems();
817                                    } else {
818                                        $this.removeItem(e, $(this).parent().prev());
819                                    }
820
821                                    e.preventDefault();
822                                }
823                                break;
824                        };
825                    }
826
827                });
828
829                function markHiddenChildrenForRemoval(elem) {
830                    elem.find(':hidden').addClass('__invisible-elements__');
831                    elem.find('.visuallyhidden').addClass('__invisible-elements__');
832                    elem.find('.sr-only').addClass('__invisible-elements__');
833                    elem.find('*').filter(function () {
834                        return $(this).css('opacity') === '0' || $(this).css('transform') === 'matrix(0, 0, 0, 0, 0, 0)' || $(this).css('transform') === 'scale(0)';
835                    }).addClass('__invisible-elements__');
836                    return elem;
837                }
838            }
839
840
841        });
842    }
843
844    //https://github.com/primefaces/primefaces/blob/master/src/main/resources/META-INF/resources/primefaces/overlaypanel/overlaypanel.js
845    if (PrimeFaces.widget.OverlayPanel) {
846        PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.OverlayPanel.extend({
847
848            align: function (target) {
849                this._super(target);
850            },
851
852            /**
853             * Brings up the overlay panel if it is currently hidden, or hides it if it is currently displayed.
854             */
855            toggle: function () {
856                this._super();
857            },
858
859            show: function (target) {
860                var $this = this;
861                $(document).off('keydown.currentlyShownOverlay').on('keydown.currentlyShownOverlay', function (e) {
862                    if (e.key === "Escape" && $this.isVisible()) {
863                        e.preventDefault();
864                        $this.hide();
865                        if ($this.target) {
866                            $($this.target).focus()
867                        }
868
869                    }
870                });
871
872                this._super(target);
873
874            },
875        });
876    }
877
878    //https://github.com/primefaces/primefaces/blob/8.0/src/main/resources/META-INF/resources/primefaces/tree/tree.base.js
879    //https://github.com/primefaces/primefaces/blob/8.0/src/main/resources/META-INF/resources/primefaces/tree/tree.vertical.js
880    if (PrimeFaces.widget.VerticalTree) {
881        PrimeFaces.widget.VerticalTree = PrimeFaces.widget.VerticalTree.extend({
882            init: function (cfg) {
883                this._super(cfg);
884                var $this = this;
885                this.cfg.collapsedIcon = "toggle-icon fa fa-fw fa-chevron-right";
886                this.cfg.expandedIcon = "toggle-icon fa fa-fw fa-chevron-down";
887                this.jq.find('li.ui-treenode').each(function () {
888                    var node = $(this);
889                    var label = $this.getCustomNodeLabel(node);
890                    if (label && label.length && label.attr('id')) {
891                        node.find('.ui-tree-toggler').attr('aria-labelledby', label.attr('id'));
892                    }
893                });
894                if (this.isCheckboxSelection() || this.jq.attr('tabindex') === '-2') {
895                    this.jq.removeAttr('tabindex')
896                }
897            },
898
899            nodeClick: function (event, nodeContent) {
900                if ($(event.target).is(':not(.ui-tree-toggler):not(.toggle-icon)')) {
901                    var node = nodeContent.parent(),
902                        selectable = nodeContent.hasClass('ui-tree-selectable');
903
904                    if (this.cfg.onNodeClick) {
905                        var retVal = this.cfg.onNodeClick.call(this, node, event);
906                        if (retVal === false) {
907                            return;
908                        }
909                    }
910
911                    if (selectable && this.cfg.selectionMode) {
912                        var selected = this.isNodeSelected(node),
913                            metaKey = event.metaKey || event.ctrlKey,
914                            shiftKey = event.shiftKey;
915
916                        if (this.isCheckboxSelection()) {
917                            this.toggleCheckboxNode(node);
918                        } else {
919                            if (selected && (metaKey)) {
920                                this.unselectNode(node);
921                            } else {
922                                if (this.isSingleSelection() || (this.isMultipleSelection() && !metaKey)) {
923                                    this.unselectAllNodes();
924                                }
925
926                                if (this.isMultipleSelection() && shiftKey && this.cursorNode && (this.cursorNode.parent().is(node.parent()))) {
927                                    var parentList = node.parent(),
928                                        treenodes = parentList.children('li.ui-treenode'),
929                                        currentNodeIndex = treenodes.index(node),
930                                        cursorNodeIndex = treenodes.index(this.cursorNode),
931                                        startIndex = (currentNodeIndex > cursorNodeIndex) ? cursorNodeIndex : currentNodeIndex,
932                                        endIndex = (currentNodeIndex > cursorNodeIndex) ? (currentNodeIndex + 1) : (cursorNodeIndex + 1);
933
934                                    for (var i = startIndex; i < endIndex; i++) {
935                                        var treenode = treenodes.eq(i);
936                                        if (treenode.is(':visible')) {
937                                            if (i === (endIndex - 1))
938                                                this.selectNode(treenode);
939                                            else
940                                                this.selectNode(treenode, true);
941                                        }
942                                    }
943                                } else {
944                                    this.selectNode(node);
945                                    this.cursorNode = node;
946                                }
947                            }
948                        }
949
950                        if ($(event.target).is(':not(:input:enabled)')) {
951                            PrimeFaces.clearSelection();
952                            this.focusNode(node);
953                        }
954                    }
955                }
956            },
957            expandNode: function (node) {
958                var $this = this;
959
960                if (this.cfg.dynamic) {
961                    if (this.cfg.cache && $this.getNodeChildrenContainer(node).children().length > 0) {
962                        this.showNodeChildren(node);
963
964                        return;
965                    }
966
967                    if (node.data('processing')) {
968                        PrimeFaces.debug('Node is already being expanded, ignoring expand event.');
969                        return;
970                    }
971
972                    node.data('processing', true);
973
974                    var options = {
975                        source: this.id,
976                        process: this.id,
977                        update: this.id,
978                        formId: this.cfg.formId,
979                        params: [
980                            {name: this.id + '_expandNode', value: $this.getRowKey(node)}
981                        ],
982                        onsuccess: function (responseXML, status, xhr) {
983                            PrimeFaces.ajax.Response.handle(responseXML, status, xhr, {
984                                widget: $this,
985                                handle: function (content) {
986                                    var nodeChildrenContainer = this.getNodeChildrenContainer(node);
987                                    nodeChildrenContainer.append(content);
988
989                                    this.showNodeChildren(node);
990
991                                    if (this.cfg.draggable) {
992                                        this.makeDraggable(nodeChildrenContainer.find('.ui-treenode-content'));
993                                    }
994
995                                    if (this.cfg.droppable) {
996                                        this.makeDropPoints(nodeChildrenContainer.find('li.ui-tree-droppoint'));
997                                        this.makeDropNodes(nodeChildrenContainer.find('.ui-treenode-droppable'));
998                                    }
999                                }
1000                            });
1001
1002                            return true;
1003                        },
1004                        oncomplete: function () {
1005                            node.removeData('processing');
1006                        }
1007                    };
1008
1009                    if (this.hasBehavior('expand')) {
1010                        this.callBehavior('expand', options);
1011                    } else {
1012                        PrimeFaces.ajax.Request.handle(options);
1013                    }
1014                } else {
1015                    this.showNodeChildren(node);
1016                    this.fireExpandEvent(node);
1017                }
1018            },
1019
1020            bindEvents: function () {
1021                var $this = this,
1022                    togglerSelector = '.ui-tree-toggler',
1023                    nodeLabelSelector = '.ui-tree-selectable .ui-treenode-label',
1024                    nodeContentSelector = '.ui-treenode-content';
1025
1026                this.jq.off('click.tree-toggle', togglerSelector)
1027                    .on('click.tree-toggle', togglerSelector, null, function (e) {
1028                        var toggleIcon = $(this),
1029                            node = toggleIcon.closest('li');
1030
1031                        if (toggleIcon.attr("aria-expanded") === 'false')
1032                            $this.expandNode(node);
1033                        else
1034                            $this.collapseNode(node);
1035                    });
1036
1037                if (this.cfg.highlight && this.cfg.selectionMode) {
1038                    this.jq.off('mouseout.tree mouseover.tree', nodeLabelSelector)
1039                        .on('mouseout.tree', nodeLabelSelector, null, function () {
1040                            var label = $(this);
1041
1042                            label.removeClass('ui-state-hover');
1043
1044                            if ($this.isCheckboxSelection()) {
1045                                label.siblings('div.ui-chkbox').children('div.ui-chkbox-box').removeClass('ui-state-hover');
1046                            }
1047                        })
1048                        .on('mouseover.tree', nodeLabelSelector, null, function () {
1049                            var label = $(this);
1050
1051                            $(this).addClass('ui-state-hover');
1052
1053                            if ($this.isCheckboxSelection()) {
1054                                label.siblings('div.ui-chkbox').children('div.ui-chkbox-box').addClass('ui-state-hover');
1055                            }
1056                        });
1057                }
1058
1059                if (this.isCheckboxSelection()) {
1060                    var checkboxSelector = '.ui-chkbox-box:not(.ui-state-disabled)';
1061                    this.jq.off('mouseout.tree-checkbox mouseover.tree-checkbox click.tree-checkbox', checkboxSelector)
1062                        .on('mouseout.tree-checkbox', checkboxSelector, null, function () {
1063                            $(this).removeClass('ui-state-hover').parent().siblings('.ui-treenode-label').removeClass('ui-state-hover');
1064                        })
1065                        .on('mouseover.tree-checkbox', checkboxSelector, null, function () {
1066                            $(this).addClass('ui-state-hover').parent().siblings('.ui-treenode-label').addClass('ui-state-hover');
1067                        });
1068                }
1069
1070                this.jq.off('click.tree-content', nodeContentSelector)
1071                    .on('click.tree-content', nodeContentSelector, null, function (e) {
1072                        $this.nodeClick(e, $(this));
1073                    });
1074
1075                if (this.cfg.filter) {
1076                    this.filterInput = this.jq.find('.ui-tree-filter');
1077                    PrimeFaces.skinInput(this.filterInput);
1078
1079                    this.filterInput.on('keydown.tree-filter', PrimeFaces.utils.blockEnterKey)
1080                        .on('keyup.tree-filter', function (e) {
1081                            if (PrimeFaces.utils.ignoreFilterKey(e)) {
1082                                return;
1083                            }
1084
1085                            if ($this.filterTimeout) {
1086                                clearTimeout($this.filterTimeout);
1087                            }
1088
1089                            $this.filterTimeout = setTimeout(function () {
1090                                $this.filter();
1091                                $this.filterTimeout = null;
1092                            }, 300);
1093                        });
1094                }
1095
1096                this.jq.on('scroll.tree', function (e) {
1097                    $this.saveScrollState();
1098                });
1099
1100                this.bindKeyEvents();
1101            },
1102
1103            toggleCheckboxNode: function (node) {
1104                var $this = this,
1105                    checkbox = node.find('> .ui-treenode-content > .ui-chkbox'),
1106                    checked = checkbox.find('> input').attr('checked') === 'checked';
1107
1108                this.toggleCheckboxState(checkbox, checked);
1109
1110                if (this.cfg.propagateDown) {
1111                    node.children('.ui-treenode-children').find('.ui-chkbox').each(function () {
1112                        $this.toggleCheckboxState($(this), checked);
1113                    });
1114
1115                    if (this.cfg.dynamic) {
1116                        this.removeDescendantsFromSelection(node.data('rowkey'));
1117                    }
1118                }
1119
1120                if (this.cfg.propagateUp) {
1121                    node.parents('li.ui-treenode-parent').each(function () {
1122                        var parentNode = $(this),
1123                            parentsCheckbox = parentNode.find('> .ui-treenode-content > .ui-chkbox'),
1124                            children = parentNode.find('> .ui-treenode-children > .ui-treenode');
1125
1126                        if (checked) {
1127                            if (children.filter('.ui-treenode-unselected').length === children.length)
1128                                $this.uncheck(parentsCheckbox);
1129                            else
1130                                $this.partialCheck(parentsCheckbox);
1131                        } else {
1132                            if (children.filter('.ui-treenode-selected').length === children.length)
1133                                $this.check(parentsCheckbox);
1134                            else
1135                                $this.partialCheck(parentsCheckbox);
1136                        }
1137                    });
1138                }
1139
1140                this.writeSelections();
1141
1142                if (checked)
1143                    this.fireNodeUnselectEvent(node);
1144                else
1145                    this.fireNodeSelectEvent(node);
1146            },
1147
1148            partialCheck: function (checkbox) {
1149                this._super(checkbox);
1150                var treeNode = checkbox.closest('.ui-treenode');
1151                treeNode.removeAttr('aria-checked');
1152                var input = checkbox.find('input');
1153                input.attr('checked', 'checked');
1154                input.prop('checked', true);
1155            },
1156
1157            check: function (checkbox) {
1158                this._super(checkbox);
1159                checkbox.siblings('.ui-treenode-label').addClass('ui-state-highlight').removeClass('ui-state-hover');
1160
1161                var treeNode = checkbox.closest('.ui-treenode');
1162                treeNode.removeAttr('aria-checked');
1163                var input = checkbox.find('input');
1164                input.attr('checked', 'checked');
1165                input.prop('checked', true);
1166            },
1167
1168            uncheck: function (checkbox) {
1169                this._super(checkbox);
1170                checkbox.siblings('.ui-treenode-label').removeClass('ui-state-highlight');
1171
1172                var treeNode = checkbox.closest('.ui-treenode');
1173                treeNode.removeAttr('aria-checked');
1174                var input = checkbox.find('input');
1175                input.removeAttr('checked');
1176                input.prop('checked', false);
1177            },
1178
1179            initDraggable: function () {
1180                this.makeDraggable(this.jq.find('.ui-treenode-content'));
1181            },
1182
1183            initDroppable: function () {
1184                this.makeDropPoints(this.jq.find('li.ui-tree-droppoint'));
1185                this.makeDropNodes(this.jq.find('.ui-treenode-droppable'));
1186                this.initDropScrollers();
1187            },
1188            makeDropPoints: function (elements) {
1189                var $this = this,
1190                    dragdropScope = this.cfg.dragdropScope || this.id;
1191
1192                elements.droppable({
1193                    hoverClass: 'ui-state-hover',
1194                    accept: '.ui-treenode-content',
1195                    tolerance: 'pointer',
1196                    scope: dragdropScope,
1197                    drop: function (event, ui) {
1198                        var dragSource = PF($(ui.draggable.data('dragsourceid')).data('widget')),
1199                            dropSource = $this,
1200                            dropPoint = $(this),
1201                            dropNode = dropPoint.closest('li.ui-treenode-parent'),
1202                            dropNodeKey = $this.getRowKey(dropNode),
1203                            transfer = (dragSource.id !== dropSource.id),
1204                            draggedSourceKeys = dragSource.draggedSourceKeys,
1205                            isDroppedNodeCopy = ($this.cfg.dropCopyNode && $this.shiftKey),
1206                            draggedNodes,
1207                            dragNodeKey;
1208
1209                        if (draggedSourceKeys) {
1210                            draggedNodes = dragSource.findNodes(draggedSourceKeys);
1211                        } else {
1212                            draggedNodes = [ui.draggable];
1213                        }
1214
1215                        if ($this.cfg.controlled) {
1216                            $this.droppedNodeParams = [];
1217                        }
1218
1219                        $this.invalidSourceKeys = [];
1220
1221                        for (var i = (draggedNodes.length - 1); i >= 0; i--) {
1222                            var draggedNode = $(draggedNodes[i]),
1223                                dragMode = ui.draggable.data('dragmode'),
1224                                dragNode = draggedNode.is('li.ui-treenode') ? draggedNode : draggedNode.closest('li.ui-treenode'),
1225                                dragNode = (isDroppedNodeCopy) ? dragNode.clone() : dragNode,
1226                                targetDragNode = $this.findTargetDragNode(dragNode, dragMode);
1227
1228                            dragNodeKey = $this.getRowKey(targetDragNode);
1229
1230                            if (!transfer && dropNodeKey && dropNodeKey.indexOf(dragNodeKey) === 0) {
1231                                return;
1232                            }
1233
1234                            if ($this.cfg.controlled) {
1235                                $this.droppedNodeParams.push({
1236                                    'ui': ui,
1237                                    'dragSource': dragSource,
1238                                    'dragNode': dragNode,
1239                                    'targetDragNode': targetDragNode,
1240                                    'dropPoint': dropPoint,
1241                                    'dropNode': dropNode,
1242                                    'transfer': transfer
1243                                });
1244                            } else {
1245                                $this.onDropPoint(ui, dragSource, dragNode, targetDragNode, dropPoint, dropNode, transfer);
1246                            }
1247                        }
1248
1249                        if (!draggedSourceKeys) {
1250                            draggedSourceKeys = [dragNodeKey];
1251                        }
1252                        draggedSourceKeys = draggedSourceKeys.filter(function (key) {
1253                            return $.inArray(key, $this.invalidSourceKeys) === -1;
1254                        });
1255
1256                        if (draggedSourceKeys && draggedSourceKeys.length) {
1257                            draggedSourceKeys = draggedSourceKeys.reverse().join(',');
1258                            $this.fireDragDropEvent({
1259                                'dragNodeKey': draggedSourceKeys,
1260                                'dropNodeKey': dropNodeKey,
1261                                'dragSource': dragSource.id,
1262                                'dndIndex': dropPoint.prevAll('li.ui-treenode').length,
1263                                'transfer': transfer,
1264                                'isDroppedNodeCopy': isDroppedNodeCopy
1265                            });
1266                        }
1267
1268                        dragSource.draggedSourceKeys = null;
1269                        $this.invalidSourceKeys = null;
1270
1271                        if (isDroppedNodeCopy) {
1272                            $this.initDraggable();
1273                        }
1274                    }
1275                });
1276            },
1277
1278            updateDragDropBindings: function (node) {
1279                //self droppoint
1280                node.after('<li class="ui-tree-droppoint ui-droppable"></li>');
1281                this.makeDropPoints(node.next('li.ui-tree-droppoint'));
1282
1283                //descendant droppoints
1284                var subtreeDropPoints = node.find('li.ui-tree-droppoint');
1285                if (subtreeDropPoints.hasClass('ui-droppable') && !this.shiftKey && !this.cfg.dropCopyNode) {
1286                    subtreeDropPoints.droppable('destroy');
1287                }
1288                this.makeDropPoints(subtreeDropPoints);
1289
1290                //descendant drop node contents
1291                var subtreeDropNodeContents = node.find('.ui-treenode-content');
1292                if (subtreeDropNodeContents.hasClass('ui-droppable') && !this.shiftKey && !this.cfg.dropCopyNode) {
1293                    subtreeDropNodeContents.droppable('destroy');
1294                }
1295                this.makeDropNodes(subtreeDropNodeContents);
1296
1297                if (this.cfg.draggable) {
1298                    subtreeDropNodeContents.data({
1299                        'dragsourceid': this.jqId,
1300                        'dragmode': this.cfg.dragMode
1301                    });
1302                }
1303            },
1304
1305            makeParent: function (node) {
1306                node.removeClass('ui-treenode-leaf').addClass('ui-treenode-parent');
1307                node.find('> .ui-treenode-content > .ui-treenode-leaf-icon').removeClass('ui-treenode-leaf-icon').addClass('ui-tree-toggler ui-icon ui-icon-triangle-1-e');
1308                node.children('.ui-treenode-children').append('<li class="ui-tree-droppoint ui-droppable"></li>');
1309                this.makeDropPoints(node.find('> ul.ui-treenode-children > li.ui-tree-droppoint'));
1310            },
1311
1312            getCustomNodeLabel: function (node) {
1313                return node.find('> .ui-treenode-content > .ui-treenode-label .custom-tree-node-label');
1314            },
1315
1316            getNodeLabel: function (node) {
1317                return node.find('> .ui-treenode-content > .ui-treenode-label');
1318            },
1319
1320
1321            collapseNode: function (node) {
1322                var _self = this,
1323                    nodeContent = node.find('> .ui-treenode-content'),
1324                    toggleIcon = nodeContent.find('> .ui-tree-toggler'),
1325                    nodeType = node.data('nodetype'),
1326                    nodeIcon = toggleIcon.nextAll('span.ui-treenode-icon'),
1327                    iconState = this.cfg.iconStates[nodeType],
1328                    childrenContainer = node.children('.ui-treenode-children');
1329
1330                toggleIcon = toggleIcon.find('> .toggle-icon');
1331                //aria
1332                nodeContent.find('> .ui-treenode-label').attr('aria-expanded', false);
1333                nodeContent.find('> .ui-tree-toggler').attr('aria-expanded', false);
1334
1335                toggleIcon.removeClass(_self.cfg.expandedIcon).addClass(_self.cfg.collapsedIcon);
1336
1337                if (iconState) {
1338                    nodeIcon.removeClass(iconState.expandedIcon).addClass(iconState.collapsedIcon);
1339                }
1340
1341                if (this.cfg.animate) {
1342                    childrenContainer.slideUp('fast', function () {
1343                        _self.postCollapse(node, childrenContainer);
1344                    });
1345                } else {
1346                    childrenContainer.hide();
1347                    this.postCollapse(node, childrenContainer);
1348                }
1349            },
1350
1351            //@Override
1352            showNodeChildren: function (node) {
1353                var nodeContent = node.find('> .ui-treenode-content'),
1354                    toggleIcon = nodeContent.find('> .ui-tree-toggler'),
1355                    nodeType = node.data('nodetype'),
1356                    nodeIcon = toggleIcon.nextAll('span.ui-treenode-icon'),
1357                    iconState = this.cfg.iconStates[nodeType];
1358
1359                toggleIcon = toggleIcon.find('> .toggle-icon');
1360
1361                //aria
1362                nodeContent.find('> .ui-treenode-label').attr('aria-expanded', true);
1363                nodeContent.find('> .ui-tree-toggler').attr('aria-expanded', true);
1364
1365                toggleIcon.removeClass(this.cfg.collapsedIcon).addClass(this.cfg.expandedIcon);
1366
1367                if (iconState) {
1368                    nodeIcon.removeClass(iconState.collapsedIcon).addClass(iconState.expandedIcon);
1369                }
1370
1371                if (this.cfg.animate) {
1372                    node.children('.ui-treenode-children').slideDown('fast');
1373                } else {
1374                    node.children('.ui-treenode-children').show();
1375                }
1376            },
1377
1378
1379        });
1380    }
1381
1382    // https://github.com/primefaces/primefaces/blob/10.0.0/src/main/resources/META-INF/resources/primefaces/fieldset/fieldset.js
1383    PrimeFaces.widget.Fieldset = PrimeFaces.widget.BaseWidget.extend({
1384
1385        /**
1386         * @override
1387         * @inheritdoc
1388         * @param {PrimeFaces.PartialWidgetCfg<TCfg>} cfg
1389         */
1390        init: function(cfg) {
1391            this._super(cfg);
1392
1393            this.legend = this.jq.children('.ui-fieldset-legend');
1394
1395            var $this = this;
1396
1397            if(this.cfg.toggleable) {
1398                this.content = this.jq.children('.ui-fieldset-content');
1399                this.toggler = this.legend.children('.ui-fieldset-toggler');
1400                this.stateHolder = $(this.jqId + '_collapsed');
1401
1402                //Add clickable legend state behavior
1403                this.legend.on('click', function(e) {
1404                    $this.toggle(e);
1405                })
1406                    .on('mouseover', function() {
1407                        $this.legend.toggleClass('ui-state-hover');
1408                    })
1409                    .on('mouseout', function() {
1410                        $this.legend.toggleClass('ui-state-hover');
1411                    })
1412                    .on('mousedown', function() {
1413                        $this.legend.toggleClass('ui-state-active');
1414                    })
1415                    .on('mouseup', function() {
1416                        $this.legend.toggleClass('ui-state-active');
1417                    })
1418                    .on('focus', function() {
1419                        $this.legend.toggleClass('ui-state-focus');
1420                    })
1421                    .on('blur', function() {
1422                        $this.legend.toggleClass('ui-state-focus');
1423                    })
1424                    .on('keydown', function(e) {
1425                        var key = e.which,
1426                            keyCode = $.ui.keyCode;
1427
1428                        if((key === keyCode.ENTER)) {
1429                            $this.toggle(e);
1430                            e.preventDefault();
1431                        }
1432                    });
1433            }
1434        },
1435
1436        /**
1437         * @override
1438         * @inheritdoc
1439         * @param {PrimeFaces.PartialWidgetCfg<TCfg>} cfg
1440         */
1441        refresh: function(cfg) {
1442            this._super(cfg);
1443
1444            this.loaded = false;
1445        },
1446
1447        /**
1448         * Toggles the content of this fieldset (collapsed or expanded).
1449         * @param {JQuery.TriggeredEvent} [e] Optional event that triggered the toggling.
1450         */
1451        toggle: function(e) {
1452            var $this = this,
1453                collapsed = this.cfg.collapsed;
1454
1455            if (!this.loaded && this.cfg.dynamic && collapsed) {
1456                this.loadContents();
1457            }
1458            else {
1459                this.updateToggleState(collapsed);
1460            }
1461
1462            this.content.slideToggle(this.cfg.toggleSpeed, 'easeInOutCirc', function() {
1463                $this.callBehavior('toggle');
1464            });
1465
1466            PrimeFaces.invokeDeferredRenders(this.id);
1467        },
1468
1469        /**
1470         * Updates the visual toggler state and saves its state
1471         * @private
1472         * @param {boolean} collapsed If this fieldset is now collapsed or expanded.
1473         */
1474        updateToggleState: function(collapsed) {
1475            if(collapsed) {
1476                this.toggler.removeClass('ui-icon-plusthick').addClass('ui-icon-minusthick');
1477            }
1478            else {
1479                this.toggler.removeClass('ui-icon-minusthick').addClass('ui-icon-plusthick');
1480            }
1481
1482            this.cfg.collapsed = !collapsed;
1483
1484            this.stateHolder.val(!collapsed);
1485        },
1486
1487        /**
1488         * Loads the contents of this fieldset panel dynamically via AJAX, if dynamic loading is enabled.
1489         * @private
1490         */
1491        loadContents: function() {
1492            var $this = this,
1493                options = {
1494                    source: this.id,
1495                    process: this.id,
1496                    update: this.id,
1497                    params: [
1498                        {name: this.id + '_contentLoad', value: true}
1499                    ],
1500                    onsuccess: function(responseXML, status, xhr) {
1501                        PrimeFaces.ajax.Response.handle(responseXML, status, xhr, {
1502                            widget: $this,
1503                            handle: function(content) {
1504                                this.content.html(content);
1505                                $this.loaded = true;
1506                            }
1507                        });
1508
1509                        return true;
1510                    },
1511                    oncomplete: function() {
1512                        $this.updateToggleState($this.cfg.collapsed);
1513                    }
1514                };
1515
1516            PrimeFaces.ajax.Request.handle(options);
1517        }
1518    });
1519})(window);
1520
1521

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.