User:Benwing2/common.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

This JavaScript is executed for Benwing2 on every page load.


importScript("User:Ioaxxere/minitoc.js");

// Various fixes for the trees generated by [[Module:family tree]].
$(function () {
	// Show the top toggle.
	$('.ft-toptoggle').css('display', '');
	
	var customtogglePrefix = 'ft';
	
	// Initialize the text of the toggles.
	$('.ftree').get().forEach(function (tree) {
		var isCollapsed = tree.classList.contains('mw-collapsed');
		var toggles = $(tree).find('.ft-toggle');
		if (toggles[0]) {
			var customToggleClass = Array.prototype.filter.call(toggles[0].classList, function (className) {
				return className.indexOf('mw-customtoggle-' + customtogglePrefix) === 0;
			})[0];
			if (customToggleClass) {
				var toggledElement = $('#' + customToggleClass.replace('mw-customtoggle', 'mw-customcollapsible'));
				if (toggledElement) {
					toggles.html(toggledElement.data(isCollapsed ? 'expandtext' : 'collapsetext'));
				}
			}
		}
	});
	
	// Change the text in the custom toggles generated by [[Module:family tree]]
	// when they are clicked.
	$('.mw-collapsible').on('beforeExpand.mw-collapsible beforeCollapse.mw-collapsible',
    function (event) {
        if (this.id.indexOf('mw-customcollapsible-' + customtogglePrefix) === 0) {
            var toggle = $('.' + this.id.replace('mw-customcollapsible', 'mw-customtoggle'));
            if (event.type === 'beforeExpand') {
                toggle.html(this.dataset.collapsetext);
            } else { // beforeCollapse
                toggle.html(this.dataset.expandtext);
            }
            event.stopPropagation();
        }
    });
});