JS: Add code documentation

This commit is contained in:
Florian Strohmaier 2018-12-06 13:53:52 +01:00 committed by Johannes Meyer
parent 168cc33a69
commit d3e4fb6552
1 changed files with 25 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/*! Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
/*! Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
;(function(Icinga, $) {
@ -9,6 +9,13 @@
var defaultNumOfRows = 2;
var defaultHeight = 36;
/**
* Behavior for collapsible containers. Creates collapsible containers from `<div class="collapsible-container">…</div>`
* or <div class="collapsible-container"><div class="collapsible"></div></div>`
*
* @param icinga Icinga The current Icinga Object
*/
function CollapsibleContainer(icinga) {
Icinga.EventListener.call(this, icinga);
@ -18,6 +25,11 @@
CollapsibleContainer.prototype = new Icinga.EventListener();
/**
* Initializes all collapsible-container elements. Triggered on rendering of a container.
*
* @param event Event The `onRender` event triggered by the rendered container
*/
CollapsibleContainer.prototype.onRendered = function(event) {
$(event.target).find('.collapsible-container').each(function() {
var $this = $(this);
@ -56,6 +68,11 @@
});
};
/**
* Event handler for clocking collapsible control. Toggles the collapsed state of the respective container.
*
* @param event Event The `onClick` event triggered by the clicked collapsible-control element
*/
CollapsibleContainer.prototype.onControlClicked = function(event) {
var $target = $(event.target);
var $c = $target.closest('.collapsible-container, .collapsible-table-container');
@ -72,7 +89,13 @@
updateCollapsedState($c);
};
function updateCollapsedState($container, listener) {
/**
* Renders the collapse state of the given container. Adds or removes class `collapsible` to containers and sets the
* height.
*
* @param $container jQuery The given collapsible container element
*/
function updateCollapsedState($container) {
var $collapsible;
if ($container.hasClass('has-collapsible')) {
$collapsible = $container.find('.collapsible');