Source
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* JQuery class that adds interactivity of vertical accordion for CList element.
*
* @event collapse - Event fires when accordion section is collapsed.
* @property {object} section - section object.
*
* @event expand - Event fires when accordion section is expanded.
* @property {object} section - section object.
*/
jQuery(function($) {
"use strict";
var methods = {
/**
* Create CList based accordion.
*
* Supported options:
* - handler - selector of UI element to open/close accordion section.
* - section - selector of UI element for single accordion section.
* - body - selector of UI element that should be opened/closed.
* - active_class - CSS class that will be applied for active section.
* - closed_class - CSS class that will be applied for closed section.
*
* @param options
*/
init: function(options) {
options = $.extend({}, {
handler: '.list-accordion-item-head',
section: '.list-accordion-item',
active_class: 'list-accordion-item-opened',
closed_class: 'list-accordion-item-closed',
body: '.list-accordion-item-body'
}, options);
this.each(function() {
var accordion = $(this);
// Bind collapse/expend.
accordion
.data('options', options)
.on('click', options['handler'], function() {
var section = $(this).closest(options['section']);
if (section.hasClass(options['active_class'])) {
methods['collapseAll'].apply(accordion);
}
else {
methods['expandNth'].apply(accordion, [$(section).index()]);