Ero sivun ”Järjestelmäviesti:Common.js” versioiden välillä

Seikkailuoppaasta
Rivi 43: Rivi 43:
 
$('#bodyContentOuter').css('margin-top', '-1.5em');
 
$('#bodyContentOuter').css('margin-top', '-1.5em');
 
}
 
}
 +
 +
const $itemOverlay = $('<div/>')
 +
.css({
 +
'position': 'fixed',
 +
'z-index': '1000',
 +
'padding': '1em',
 +
'font-family': 'monospace',
 +
'color': '#ffffff',
 +
'background-color': '#2a114f',
 +
'border': '3px solid rgba(255, 255, 255, 0.2)',
 +
'box-shadow': '-2px -2px 0 black, 2px -2px 0 black, -2px 2px 0 black, 2px 2px 0 black',
 +
'top': '0',
 +
'left': '0'
 +
});
 +
 +
$('body').append($itemOverlay);
 
 
 
// crafting grids
 
// crafting grids

Versio 14. kesäkuuta 2022 kello 11.11

function createItemDisplay(itemData) {
	
	if (!itemData || itemData.trim() == '') {
		return $('<div class="x-item"/>');
	}
	
	itemData = itemData.trim();
	
	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');
	}
	
	const $itemOverlay = $('<div/>')
		.css({
			'position': 'fixed',
			'z-index': '1000',
			'padding': '1em',
			'font-family': 'monospace',
			'color': '#ffffff',
			'background-color': '#2a114f',
			'border': '3px solid rgba(255, 255, 255, 0.2)',
			'box-shadow': '-2px -2px 0 black, 2px -2px 0 black, -2px 2px 0 black, 2px 2px 0 black',
			'top': '0',
			'left': '0'
		});
	
	$('body').append($itemOverlay);
	
	// 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);
		
	});
	
});