MediaWiki:Gadget-toggles.js

$(function {	// implements freeform toggle akin to Dynamic Tabs - only one section can be shown at a time	// assign class "optionfromlist-toggler" to each toggler to make them recognized at all	// assign attr "data-toggle-section" & this value as a class to each toggler	// to make them behave together (to support multiple unrelated sections per page)	// to start something hidden, add class toggle-section-hidden	// assign attrs data-toggler-show and data-toggler-hide to each	// assign classes of the values of the attr of show/hide to the content that you want it to control	$('.optionfromlist-toggler').each(function { $(this).click(function {			$this = $(this);			if($this.hasClass('active')) {				return;			}			var thisSection = $this.attr('data-toggle-section');			$('.' + thisSection).removeClass('active');			$this.addClass('active');			var toHide = $this.attr('data-toggler-hide');			var toShow = $this.attr('data-toggler-show');			var hiddenClass = $this.attr('data-toggler-hiddenclass');			hiddenClass = hiddenClass ? hiddenClass : 'toggle-section-hidden';			$(toHide).addClass(hiddenClass);			$(toShow).removeClass(hiddenClass);		}); });	// no "active" or "inactive" toggles here, otherwise behaves the same as above	$('.alwaysactive-toggler').each(function { $(this).click(function {			$this = $(this);			var toHide = $this.attr('data-toggler-hide');			var toShow = $this.attr('data-toggler-show');			var hiddenClass = $this.attr('data-toggler-hiddenclass');			hiddenClass = hiddenClass ? hiddenClass : 'toggle-section-hidden';			$(toHide).addClass(hiddenClass);			$(toShow).removeClass(hiddenClass);		}); });	$('.sections-toggler').each(function { $(this).click(function {			$this = $(this);			var toHide = $this.attr('data-toggler-hide');			var toShow = $this.attr('data-toggler-show');			var toHide_tbl = toHide.split(';');			var toShow_tbl = toShow.split(';');			var hiddenClass = $this.attr('data-toggler-hiddenclass');			hiddenClass = hiddenClass ? hiddenClass : 'toggle-section-hidden';			for(i in toHide_tbl) {				$(toHide_tbl[i]).addClass(hiddenClass);			}			for (i in toShow_tbl) {				$(toShow_tbl[i]).removeClass(hiddenClass);			}		}); });	// checkboxes to show-hide rows in a table (or whatever)	$('.checkbox-togglers').each(function { $(this).find('input').each(function {			this.addEventListener('change', function(e) { var $this = $(this); var classToToggle = $this.attr('data-toggle-class'); var hiddenClass = $this.attr('data-toggler-hiddenclass'); hiddenClass = hiddenClass ? hiddenClass : 'toggle-section-hidden'; $(classToToggle).toggleClass(hiddenClass); });		});	}); });