UNPKG

altinn-designsystem

Version:

Altinn Design system based on Pattern Lab.

37 lines (31 loc) 990 B
// Toggles between two components. // Each toggable component needs to be referenced by id from data-switch-target attribute of switch var toggleSwitch = function() { var $allWithTarget = $('.switch-container input[data-switch-target]'); var allTargets = []; $.each($allWithTarget, function() { $.each($(this).data('switch-target'), function() { allTargets.push(this + ''); }); }); $allWithTarget.on('click', function() { var $currentSwitch = $(this); var switchTargets = $currentSwitch.data('switch-target'); $.each(switchTargets, function() { $('#' + this).show(); }); $.each(allTargets, function() { var hide = true; var outerTarget = this + ''; $.each(switchTargets, function() { var innerTarget = this + ''; if (outerTarget === innerTarget) { hide = false; } }); if (hide) { $('#' + this).hide(); } }); }); };