xref: /OpenGrok/opengrok-web/src/main/webapp/js/repos-0.0.3.js (revision 7c0a1357931d754d4eed5bce3a80f71a2eb8dac2)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * See LICENSE.txt included in this distribution for the specific
9 * language governing permissions and limitations under the License.
10 *
11 * When distributing Covered Code, include this CDDL HEADER in each
12 * file and include the License file at LICENSE.txt.
13 * If applicable, add the following below this CDDL HEADER, with the
14 * fields enclosed by brackets "[]" replaced with your own identifying
15 * information: Portions Copyright [yyyy] [name of copyright owner]
16 *
17 * CDDL HEADER END
18 */
19
20/*
21 * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
22 */
23
24/*
25 * This file contains JavaScript code used by repos.jspf.
26 */
27
28(function ($) {
29    const Accordion = function ($parent, options) {
30        const inner = {
31            initialized: false,
32            options: {},
33            defaults: {
34                "showAllSelector": ".accordion_show_all",
35                "hideAllSelector": ".accordion_hide_all"
36            },
37            $panels: [],
38            determineButtonsVisibility: function() {
39                const decision = inner.$panels.filter(":visible").length === inner.$panels.length;
40                return {
41                    hide: decision ? inner.options.showAllSelector : inner.options.hideAllSelector,
42                    show: decision ? inner.options.hideAllSelector : inner.options.showAllSelector
43                };
44            },
45            init: function () {
46                inner.$panels = inner.options.parent.find(".panel-body-accordion");
47
48                inner.options.parent.find(".panel-heading-accordion").click(function (e) {
49                    $(this).parent().find(".panel-body-accordion").each(function () {
50                        if ($(this).data("accordion-visible")) {
51                            $(this).hide().
52                                    data("accordion-visible", false).
53                                    parent().
54                                    find(".panel-heading-accordion .fold").
55                                        removeClass('fold-up').
56                                        addClass('fold-down');
57                        } else {
58                            $(this).show().
59                                    data("accordion-visible", true).
60                                    parent().
61                                    find(".panel-heading-accordion .fold").
62                                        removeClass('fold-down').
63                                        addClass('fold-up');
64                        }
65                    });
66
67                    const btn = inner.determineButtonsVisibility();
68                    inner.options.parent.find(btn.hide).hide();
69                    inner.options.parent.find(btn.show).show();
70                    return false;
71                });
72
73                inner.options.parent.find(inner.options.showAllSelector).click(function (e) {
74                    inner.$panels.
75                            data("accordion-visible", true).
76                            show().
77                            parent().
78                            find(".panel-heading-accordion .fold").
79                                removeClass('fold-down').
80                                addClass('fold-up');
81                    inner.options.parent.find(inner.options.hideAllSelector).show();
82                    inner.options.parent.find(inner.options.showAllSelector).hide();
83                    return false;
84                });
85
86                inner.options.parent.find(inner.options.hideAllSelector).click(function (e) {
87                    inner.$panels.
88                            data("accordion-visible", false).
89                            hide().
90                            parent().
91                            find(".panel-heading-accordion .fold").
92                                removeClass('fold-up').
93                                addClass('fold-down');
94                    inner.options.parent.find(inner.options.hideAllSelector).hide();
95                    inner.options.parent.find(inner.options.showAllSelector).show();
96                    return false;
97                });
98
99
100                const btn = inner.determineButtonsVisibility();
101                inner.options.parent.find(btn.hide).hide();
102                inner.options.parent.find(btn.show).show();
103
104                inner.initialized = true;
105            }
106        };
107
108        const init = (function ($parent, options) {
109            if (inner.initialized) {
110                return;
111            }
112            inner.options = $.extend({}, {parent: $parent}, inner.defaults, options);
113            inner.init();
114        })($parent, options);
115    };
116
117    $.fn.accordion = function (options) {
118        return this.each(function () {
119            options = options || {};
120            return new Accordion($(this), options);
121        });
122    };
123})(jQuery);
124
125$(document).ready(function () {
126    $("#footer").addClass("main_page");
127
128    $(".projects").accordion();
129
130    $(".projects_select_all").click(function (e) {
131        $("#project .name");
132
133        if (!e.ctrlKey) {
134            $("#project").searchableOptionList().deselectAll();
135        }
136        $(this).closest('.panel').find('.name').each(function(){
137          $("#project").searchableOptionList().selectAll($(this).text());
138        });
139
140        return false;
141    });
142    domReadyHistory();
143});
144