MediaWiki:Common.js: Difference between revisions
From Valheim Wiki
No edit summary |
No edit summary Tag: Reverted |
||
| Line 31: | Line 31: | ||
}); | }); | ||
}); | }); | ||
// Retrieve references to current table TR elements | |||
let collection = Array.from(this.querySelectorAll('.crafts.crafts-upgrades tr')) | |||
.sort(function(x, y) { | |||
let posX = +x.dataset.order | |||
,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); | |||
}); | |||
}); | }); | ||
Revision as of 22:58, 1 January 2022
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
$('.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('---------------');
});
});
// Retrieve references to current table TR elements
let collection = Array.from(this.querySelectorAll('.crafts.crafts-upgrades tr'))
.sort(function(x, y) {
let posX = +x.dataset.order
,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);
});
});