Ero sivun ”Järjestelmäviesti:Common.js” versioiden välillä
Seikkailuoppaasta
| Rivi 1: | Rivi 1: | ||
| + | function createItemDisplay(itemData) { | ||
| + | |||
| + | if (itemData.trim() == '') { | ||
| + | return $('<div class="x-item"/>'); | ||
| + | } | ||
| + | |||
| + | 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]}')`); | ||
| + | } 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(){ | $(function(){ | ||
| Rivi 17: | Rivi 44: | ||
// crafting grids | // crafting grids | ||
$('.x-crafting').each(function(){ | $('.x-crafting').each(function(){ | ||
| − | const craftItems = ($(this).attr('data-crafting-data') || '').split(';'); | + | |
| + | const craftItems = ($(this).attr('data-crafting-data') || '').split(';').map(it => it.trim()); | ||
| + | const resultItem = craftItems[craftItems.length-1]; | ||
| + | |||
| + | const $grid = $('<div class="x-crafting-grid"/>'); | ||
| + | const $result = $('<div class="x-crafting-result"/>'); | ||
| + | $result.append(createItemDisplay(resultItem)); | ||
| + | |||
| + | for (const it of craftItems.slice(0, -1)) { | ||
| + | $grid.append(createItemDisplay(it)); | ||
| + | } | ||
| + | |||
| + | $(this).append($grid); | ||
| + | $(this).append($('<div class="x-crafting-arrow"/>')); | ||
| + | $(this).append($result); | ||
}); | }); | ||
}); | }); | ||
Versio 13. kesäkuuta 2022 kello 23.10
function createItemDisplay(itemData) {
if (itemData.trim() == '') {
return $('<div class="x-item"/>');
}
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]}')`);
} 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(';').map(it => it.trim());
const resultItem = craftItems[craftItems.length-1];
const $grid = $('<div class="x-crafting-grid"/>');
const $result = $('<div class="x-crafting-result"/>');
$result.append(createItemDisplay(resultItem));
for (const it of craftItems.slice(0, -1)) {
$grid.append(createItemDisplay(it));
}
$(this).append($grid);
$(this).append($('<div class="x-crafting-arrow"/>'));
$(this).append($result);
});
});