CoreFiles by mySites.guru
switcher.js56 lines, 1,426 bytes, from Joomla_4.0.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 3.10.0-alpha9
md5
5ca31a2189c11ea876921ef1bb46b622
sha1
201e34783d3e263c6255d95424694bb1faa42ec5
sha256
8bf0df658b882c33f0c563503dff6106a1d2034a8b7965aeb3643368f1a14bbd
/**
 * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

/**
 * Field switcher
 */

(function() {
	"use strict";

	document.addEventListener('DOMContentLoaded', function() {

		var switcher = document.querySelectorAll('.js-switcher');

		for (var i = 0; i < switcher.length; i++) {

			// Add the initial active class
			var nodes  = switcher[i].querySelectorAll('input'),
				parent = nodes[1].parentNode;

			if (nodes[1].checked) {
				nodes[1].parentNode.classList.add('active');
				parent.nextElementSibling.querySelector('.switcher-label-' + nodes[1].value).classList.add('active');
			}
			else
			{
				parent.nextElementSibling.querySelector('.switcher-label-' + nodes[0].value).classList.add('active');
			}

			// Add the active class on click
			switcher[i].addEventListener('click', function(event) {
				var el     = event.target,
					parent = el.parentNode,
					spans  = parent.nextElementSibling.querySelectorAll('span');

				for (var i = 0; i < spans.length; i++) {
					spans[i].classList.remove('active');
				}

				if (!el.classList.contains('active')) {
					parent.classList.add('active');
				}
				else {
					parent.classList.remove('active');
				}

				parent.nextElementSibling.querySelector('.switcher-label-' + el.value).classList.add('active');

			});

		}
	});

})();

No other release has this exact content. See every version of this file.