User:Erutuon/scripts/changeCaseOrder.js

//

/* jshint eqeqeq: true */ /* globals mw, $ */

'use strict';

$(function {	// Each object contains a canonical name, code, and an array of	// row headers.	// The array will be used to sort the table rows. List row headers in the order	// that you want them to display.	// If a row does not have its header listed in the array, it will appear	// before all the headers in the array.	// For Ancient Greek noun declension tables, this means that the "Case / #"	// row will appear directly above the "Nominative" row.	// Headers are converted to lowercase before this list is used.	var languages = [		{			name: "Ancient Greek",			code: "grc",			headers: [ "nominative", "vocative", "accusative", "genitive", "dative", "notes:", "derived forms" ]		},		{			name: "Latin",			code: "la",			headers: [ "nominative", "vocative", "accusative", "genitive", "dative", "ablative" ],		},		{			name: "German",			code: "de",			headers: [ "nominative", "accusative", "dative", "genitive", "ablative", "vocative" ], },	];	function rearrange(language) { var languageName = language.name, languageCode = language.code, rowOrder = language.headers; var declensionTables = $(".inflection-table-" + languageCode + " tbody"); // Get text of first header in row. var getCompareValue = function (row) { var headerText = $(row).children("th").first.text.trim.toLowerCase; return rowOrder.indexOf(headerText); };		declensionTables.each(function {			$(this).replaceWith(function { return $(this) .children .sort(function (a, b) {						return getCompareValue(a) - getCompareValue(b);					}); });		});	}	languages.forEach(rearrange); });

//