MediaWiki:Common.js: Difference between revisions
From Valheim Wiki
No edit summary |
No edit summary |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
$(function () { | $(function () { | ||
$('.tabber__tab').on('click', function(e) { | |||
const id = $(this).attr('id') | |||
.replace('tab-', '') | |||
.replace('-0', '') | |||
.replace(' ', '') | |||
.replace('_', '') | |||
.replace('★', 'star') | |||
.toLowerCase(); | |||
console.log('cool', id); | |||
$('.star-hide:not(.' + id + ')').hide(); | |||
$('.star-hide.' + id).show(); | |||
}); | |||
setTimeout(function () { | |||
$('.tabber__tab[aria-selected="true"]').click(); | |||
}, 250); | |||
$('.crafts.crafts-upgrades tr').each(function (item) { | $('.crafts.crafts-upgrades tr').each(function (item) { | ||
| Line 73: | Line 93: | ||
return posA > posB ? 1 : -1; | return posA > posB ? 1 : -1; | ||
}); | }); | ||
collection.forEach(function(element) { | collection.forEach(function(element) { | ||
console.log('ordered element: ', $(element).attr('data-prop')); | console.log('ordered element: ', $(element).attr('data-prop')); | ||
Latest revision as of 22:34, 23 February 2023
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
$('.tabber__tab').on('click', function(e) {
const id = $(this).attr('id')
.replace('tab-', '')
.replace('-0', '')
.replace(' ', '')
.replace('_', '')
.replace('★', 'star')
.toLowerCase();
console.log('cool', id);
$('.star-hide:not(.' + id + ')').hide();
$('.star-hide.' + id).show();
});
setTimeout(function () {
$('.tabber__tab[aria-selected="true"]').click();
}, 250);
$('.crafts.crafts-upgrades tr').each(function (item) {
var tr = $(this);
var tdValues = tr.find('td:nth-child(n+2)');
var lastVal = 'zzz';
var lastTd = false;
tdValues.each(function (index) {
var td = $(this);
// console.log($(this).attr('data-prop'));
var currentValue = $(td).text();
// console.log('currentvalue: ', currentValue);
// console.log('lastvalue: ', lastVal);
// console.log('currentvalue === lastvalue: ', currentValue === lastVal);
if (currentValue === lastVal) {
var firstTd = $(tdValues[0]);
var currentColspan = $(firstTd).attr('colspan');
if (!currentColspan) {
currentColspan = 1;
}
$(firstTd)
.attr('colspan', currentColspan + 1)
.css({textAlign: 'center'});
$(this).hide();
}
lastTd = td;
lastVal = currentValue;
// console.log('---------------');
});
});
$('div.crafts.transpose table').each(function () {
var $this = $(this);
var newrows = [];
$this.find('tr').each(function () {
var i = 0;
$(this).find('td,th').each(function () {
i++;
if($(this).attr('rowspan')) {
$(this).attr('colspan', $(this).attr('rowspan'));
$(this).removeAttr('rowspan');
} else if ($(this).attr('colspan')) {
$(this).attr('rowspan', $(this).attr('colspan'));
$(this).removeAttr('colspan');
}
if(newrows[i] === undefined) {
newrows[i] = $('<tr></tr>');
}
newrows[i].append($(this));
});
});
$this.find('tr').remove();
$.each(newrows, function () {
$this.append(this);
});
});
try {
// Retrieve references to current table TR elements
var collection = Array.from($(this).find('.crafts.crafts-upgrades tr'));
collection.sort(function (x, y) {
if($(x).children('th').length) {
return -1;
}
var posA = parseInt($(x).attr('data-order'));
var posB = parseInt($(y).attr('data-order'));
return posA > posB ? 1 : -1;
});
collection.forEach(function(element) {
console.log('ordered element: ', $(element).attr('data-prop'));
$('.crafts.crafts-upgrades tbody').append(element);
});
// collection.sort(function (x, y) {
// console.log(x);
// console.log(y);
// let posX = +x.dataset.order;
// let posY = +y.dataset.order;
// // Behavior when items haven't the same position
// if (posX != posY) {
// return posX > posY ? 1 : -1;
// }
// return 0;
// });
// // Finally move items into the container using the computed order
// collection.forEach(element => {
// this.querySelector('.tbody').append(element);
// });
} catch(e) {
console.log(e);
}
});