MediaWiki:Common.js/instantCollapsible.js

/** * instantCollapsible.js * * Description: Removes fade animations for expand/collapse on mw-collapsible tables * @author cqm * @version 1.0 * @notes  Experimental, largely untested and not ready for site wide deployment */


 * (function ($) {

'use strict';

function noFade {

// use th to avoid affecting enhanced rc       var expand = 'Expand', collapse = 'Collapse', $toggle = $('th > .mw-collapsible-toggle'), $this, $tr, $tbody, $table, expand, collapse, i;

// prevent normal mw-collapsible behaviour $toggle.unbind('click');

$toggle.click(function (e) {

// stop scrolling to the top of the page e.preventDefault;

$this = $(this); // move one level at a time to prevent selecting nested parent tables $tbody = $($(this).parent.parent.parent); $table = $($tbody.parent); $tr = $($tbody.children);

// check for defined expand/collapse text // normally these are defined by MediaWiki:Collapsible-expand and MediaWiki:Collapsible-collapse respectively // however, this is currently bugged on wikia (2013-07-23) which forces the default 'Expand' and 'Collapse' expand = $table.attr('data-expandtext') || 'Expand'; collapse = $table.attr('data-collapsetext') || 'Collapse';

// check if collapsed already if ($table.hasClass('mw-collapsed')) {

$table.removeClass('mw-collapsed');

$this.children.text(expand);

$this.addClass('mw-collapsible-toggle-expanded') .removeClass('mw-collapsible-toggle-collapsed');

// ignore first row as it's the header for (i = 1; i < $tr.length; i += 1) { $($tr[i]).css({                       'display': 'table-row'                    }); }

} else {

$table.addClass('mw-collapsed');

// this is only added by default if already collapsed if (!$table.hasClass('mw-made-collapsible')) { $table.addClass('mw-made-collapsible'); }

$this.children.text(collapse); $this.addClass('mw-collapsible-toggle-collapsed').removeClass('mw-collapsible-toggle-expanded');

// ignore first row as it's the header for (i = 1; i < $tr.length; i += 1) { $($tr[i]).css({                       'display': 'none'                    }); }           }

});

}

$(function {

noFade;

});

}(this.jQuery));

/* */