Ero sivun ”Järjestelmäviesti:Common.js” versioiden välillä
Seikkailuoppaasta
| Rivi 4: | Rivi 4: | ||
return $('<div class="x-item"/>'); | return $('<div class="x-item"/>'); | ||
} | } | ||
| + | |||
| + | console.log('"' + itemData + '"'); | ||
const $it = $('<div class="x-item"/>'); | const $it = $('<div class="x-item"/>'); | ||
Versio 14. kesäkuuta 2022 kello 09.49
function createItemDisplay(itemData) {
if (!itemData || itemData.trim() == '') {
return $('<div class="x-item"/>');
}
console.log('"' + itemData + '"');
const $it = $('<div class="x-item"/>');
const dataParts = itemData.split(',');
if (dataParts[0].indexOf('item:') == 0) {
if (dataParts[0].indexOf('.png') == -1) dataParts[0] += '.png';
$it.css('background-image', 'url("https://cubisti.xeno.fi/' + dataParts[0].substring(5) + '")');
} else if (dataParts[0].indexOf('http') == 0) {
$it.css('background-image', 'url("' + dataParts[0] + '")');
}
if (dataParts.length > 1) {
$it.attr('data-item-title', dataParts[1]);
}
if (dataParts.length > 2) {
$it.append($('<span/>').text(''+dataParts[2]));
}
return $it;
}
$(function(){
// hide the stupid navigation options under the title
$('#mw-page-header-links').hide();
$('#p-views li').each(function(){
if (!$(this).is('#ca-more')) {
$('#p-cactions ul').prepend($(this));
}
});
// title-less pages
if ($('[data-x-hide-title]').length > 0) {
$('#firstHeading').hide();
$('#bodyContentOuter').css('margin-top', '-1.5em');
}
// crafting grids
$('.x-crafting').each(function(){
const craftItems = ($(this).attr('data-crafting-data') || '').split(';');
const resultItem = craftItems[craftItems.length-1];
const $grid = $('<div class="x-crafting-grid"/>');
const $result = $('<div class="x-crafting-result"/>');
$result.append(createItemDisplay(resultItem));
$.each(craftItems.slice(0, -1), function(key, it){
it = it.trim();
$grid.append(createItemDisplay(it));
});
$(this).append($grid);
$(this).append($('<div class="x-crafting-arrow"/>'));
$(this).append($result);
});
});