User:Jberkel/semhide.js

/* globals $ */ // based on https://en.wiktionary.org/wiki/User:Ungoliant_MMDCCLXIV/synshide.js (function { 'use strict';	function setupNyms(index, dlTag) {	// https://en.wiktionary.org/wiki/Wiktionary:Semantic_relations	var relationClasses = [ 'synonym', 'antonym', 'hypernym', 'hyponym', 'meronym', 	                        'holonym', 'troponym', 'coordinate-term' ];    var relations = $(dlTag).find('dd > .nyms').map(function(index, element) { for (var i=0; i');    	var text = elements.map(function (e) { return $(e).data.relationClass.replace('-', ' ') + (($(e).find('a').length > 1) ? 's' : ''); }).join(', ');		function show {	       toggler.html(text + ' ▲');	        $(dlTag).show;            $(elements).show;    	}    	function hide {	        toggler.html(text + ' ▼');	        if ($(dlTag).children.length === elements.length) {	            $(dlTag).hide;	        } else {	        	$(elements).hide;	        }    	}	    $(dlTag).before($(' ') .addClass('HQToggle') .append(toggler) .css('margin-left', '5px'));   	toggler.click(window.VisibilityToggles.register(category, show, hide, visibleByDefault));    }    var synonyms = relations.filter(function (e) { return ['synonym', 'antonym'].includes($(e).data.relationClass); });	var other = relations.filter(function (e) { return !synonyms.includes(e); });   setupToggle(synonyms, 'synonyms', true /* show by default */);    setupToggle(other, 'semantic relations'); }

$(function {	// if (mw.config.get('wgNamespaceNumber') === 0) {	   $('dl:has(dd > .nyms)').each(setupNyms);	// } });

});