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

KKWikistä
 
(27 välissä olevaa versiota samalta käyttäjältä ei näytetä)
Rivi 1: Rivi 1:
 
/* Tämän sivun JavaScript-koodi liitetään jokaiseen sivulataukseen */
 
/* Tämän sivun JavaScript-koodi liitetään jokaiseen sivulataukseen */
 +
 +
var _kk_seed = 1;
 +
function kk_random() {
 +
    var x = Math.sin(_kk_seed++) * 10000;
 +
    return x - Math.floor(x);
 +
}
 +
 +
function kk_random_word(){
 +
var o = '';
 +
var l = 2 + kk_random()*15;
 +
for (var i = 0; i < l; i++) {
 +
o += 'n';
 +
}
 +
return o;
 +
}
  
  
 
$(document).ready(function(){
 
$(document).ready(function(){
 +
 +
var _u = window.location.href;
 +
_kk_seed = _u.length;
 +
for (var i = 0; i < _u.length; i++) {
 +
_kk_seed += _u.charCodeAt(i);
 +
}
 
 
 
// replace feathericons
 
// replace feathericons
Rivi 20: Rivi 41:
 
$('#toc li:not(.toclevel-1)').hide();
 
$('#toc li:not(.toclevel-1)').hide();
 
$('.x-toc-main-only').show();
 
$('.x-toc-main-only').show();
 +
}
 +
 +
if ($('[data-hide-title]').length > 0) {
 +
$('[data-hide-title]').hide();
 +
$('#firstHeading').hide();
 +
}
 +
 +
if ($('[data-redirect]').length > 0) {
 +
console.log('Redirect to ' + $($('[data-redirect]')[0]).attr('data-redirect'));
 +
window.location.href = $('[data-redirect]').attr('data-redirect');
 
}
 
}
 
 
Rivi 25: Rivi 56:
 
if ($('.x-item').length > 0) {
 
if ($('.x-item').length > 0) {
 
 
var itemImage = $(this).attr('data-item');
+
$('.x-item').each(function(){
+
if (itemImage != '') {
+
var itemImage = $(this).attr('data-item');
            if (itemImage.indexOf('http') == 0) {
+
                $(this).css('background-image', 'url("' + itemImage + '")');
+
if (itemImage && itemImage != '') {
            } else {
+
            if (itemImage.indexOf('http') == 0) {
                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + itemImage + '.png")');
+
                $(this).css('background-image', 'url("' + itemImage + '")');
            }
+
            } else {
        } else {
+
                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + itemImage + '.png")');
            $(this).css('cursor', 'default');
+
            }
        }
+
        }
 +
 +
});
 
 
 +
}
 +
 +
// classified/redacted
 +
if ($('.kk-redacted').length > 0) {
 +
$('.kk-redacted').each(function(){
 +
 +
var outText = '';
 +
var chapterCount = 1 + Math.floor(kk_random()*4);
 +
 +
for (var c = 0; c < chapterCount; c++) {
 +
var wordCount = 5 + Math.floor(kk_random()*25);
 +
outText += '<p>';
 +
for (var w = 0; w < wordCount; w++) {
 +
outText += '<span style="margin: 0.1em; background-color: black; color: black; display: inline-block; transform: rotate('+(1.5-kk_random()*3)+'deg);">' + kk_random_word() + '</span> ';
 +
}
 +
outText += '</p>';
 +
}
 +
 +
$(this).append(outText);
 +
 +
});
 +
}
 +
 +
// drink stars
 +
if ($('[data-drink-stars]').length > 0) {
 +
$('[data-drink-stars]').each(function(){
 +
var starCount = parseInt($(this).attr('data-drink-stars'));
 +
var starsOut = [];
 +
for (var i = 0; i < starCount; i++) starsOut.push('<span class="x-drink-star">★</span>');
 +
$(this).html(starsOut.join(''));
 +
});
 
}
 
}
 
 
Rivi 55: Rivi 119:
 
                  
 
                  
 
                 var itemImage = $(this).attr('data-item');
 
                 var itemImage = $(this).attr('data-item');
 +
                var itemHover = $(this).attr('data-hover');
 +
               
 +
                if (itemHover.split(':').length > 1) {
 +
                var pts = itemHover.split(':');
 +
                itemHover = pts[0];
 +
                $(this).append($('<span class="x-amount"></span>').text(pts[1]));
 +
                $(this).attr('data-hover', itemHover);
 +
                }
 
                  
 
                  
 
                 if (itemImage != '') {
 
                 if (itemImage != '') {
                    if (itemImage.indexOf('item:') == 0) {
+
                if (itemImage.split(';').length == 0) {
                        $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + itemImage.replace('item:', '') + '.png")');
+
                if (itemImage.indexOf('item:') == 0) {
                    } else {
+
                        $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/'
                        $(this).css('background-image', 'url("' + itemImage + '")');
+
                        + itemImage.replace('item:', '') + '.png")');
                    }
+
                    } else {
 +
                        $(this).css('background-image', 'url("' + itemImage + '")');
 +
                    }
 +
                } else {
 +
               
 +
                var itemImages = itemImage.split(';');
 +
$(this).attr('data-animate-images', itemImages.join(';'));
 +
$(this).attr('data-animate-pointer', '0');
 +
 +
var currentImage = itemImages[0];
 +
 +
if (currentImage.indexOf('item:') == 0) {
 +
                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + currentImage.substr(5) + '.png")');
 +
            } else {
 +
                $(this).css('background-image', 'url("' + currentImage + '")');
 +
            }
 +
           
 +
                }
 
                 } else {
 
                 } else {
 
                     $(this).css('cursor', 'default');
 
                     $(this).css('cursor', 'default');
Rivi 96: Rivi 185:
 
              
 
              
 
             $('.x-crafting-item').on('click', function(e){
 
             $('.x-crafting-item').on('click', function(e){
                 window.location.href = 'https://kk.xenomc.fi/wiki/index.php/' + encodeURIComponent($(this).attr('data-hover'));
+
                 window.location.href = 'https://kk.xeno.fi/wiki/index.php/' + encodeURIComponent($(this).attr('data-hover'));
 
             });
 
             });
 
              
 
              
Rivi 112: Rivi 201:
 
             $(window).resize(rs);
 
             $(window).resize(rs);
 
              
 
              
 +
           
 +
            if ($('[data-animate-images]').length > 0) {
 +
            var __updateAnimations = function(){
 +
            $('[data-animate-images]').each(function(){
 +
           
 +
            var _i = parseInt($(this).attr('data-animate-pointer'));
 +
            var _imgs = $(this).attr('data-animate-images').split(';');
 +
           
 +
            var currentImage = _imgs[_i];
 +
            if (currentImage.indexOf('item:') == 0) {
 +
                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + currentImage.substr(5) + '.png")');
 +
            } else {
 +
                $(this).css('background-image', 'url("' + currentImage + '")');
 +
            }
 +
           
 +
            _i++;
 +
            if (_i >= _imgs.length) _i = 0;
 +
            $(this).attr('data-animate-pointer', ''+_i);
 +
           
 +
            });
 +
            };
 +
            setInterval(__updateAnimations, 2500);
 +
            __updateAnimations();
 +
            }
 +
           
 +
        }
 +
       
 +
       
 +
       
 +
        if ($('[data-kk-audio]').length > 0) {
 +
        $('[data-kk-audio]').each(function(){
 +
        $(this).replaceWith(
 +
        $('<audio></audio>')
 +
        .attr('src', $(this).attr('data-kk-audio'))
 +
        .attr('controls', 'true')
 +
    );
 +
        });
 
         }
 
         }
 
          
 
          
 
     });
 
     });

Nykyinen versio 27. marraskuuta 2021 kello 20.40

/* Tämän sivun JavaScript-koodi liitetään jokaiseen sivulataukseen */

var _kk_seed = 1;
function kk_random() {
    var x = Math.sin(_kk_seed++) * 10000;
    return x - Math.floor(x);
}

function kk_random_word(){
	var o = '';
	var l = 2 + kk_random()*15;
	for (var i = 0; i < l; i++) {
		o += 'n';
	}
	return o;
}


$(document).ready(function(){
	
	var _u = window.location.href;
	_kk_seed = _u.length;
	for (var i = 0; i < _u.length; i++) {
		_kk_seed += _u.charCodeAt(i);
	}
	
	// replace feathericons
	feather.replace();
	
	// 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));
		}
	});
	
	// if the current page asks us to hide non-top-level toc entries
	if ($('.x-toc-main-only').length > 0) {
		$('#toc li:not(.toclevel-1)').hide();
		$('.x-toc-main-only').show();
	}
	
	if ($('[data-hide-title]').length > 0) {
		$('[data-hide-title]').hide();
		$('#firstHeading').hide();
	}
	
	if ($('[data-redirect]').length > 0) {
		console.log('Redirect to ' + $($('[data-redirect]')[0]).attr('data-redirect'));
		window.location.href = $('[data-redirect]').attr('data-redirect');
	}
	
	// item displays
	if ($('.x-item').length > 0) {
		
		$('.x-item').each(function(){
			
			var itemImage = $(this).attr('data-item');
			
			if (itemImage && itemImage != '') {
	            if (itemImage.indexOf('http') == 0) {
	                $(this).css('background-image', 'url("' + itemImage + '")');
	            } else {
	                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + itemImage + '.png")');
	            }
	        }
			
		});
		
	}
	
	// classified/redacted
	if ($('.kk-redacted').length > 0) {
		$('.kk-redacted').each(function(){
			
			var outText = '';
			var chapterCount = 1 + Math.floor(kk_random()*4);
			
			for (var c = 0; c < chapterCount; c++) {
				var wordCount = 5 + Math.floor(kk_random()*25);
				outText += '<p>';
				for (var w = 0; w < wordCount; w++) {
					outText += '<span style="margin: 0.1em; background-color: black; color: black; display: inline-block; transform: rotate('+(1.5-kk_random()*3)+'deg);">' + kk_random_word() + '</span> ';
				}
				outText += '</p>';
			}
			
			$(this).append(outText);
			
		});
	}
	
	// drink stars
	if ($('[data-drink-stars]').length > 0) {
		$('[data-drink-stars]').each(function(){
			var starCount = parseInt($(this).attr('data-drink-stars'));
			var starsOut = [];
			for (var i = 0; i < starCount; i++) starsOut.push('<span class="x-drink-star">★</span>');
			$(this).html(starsOut.join(''));
		});
	}
	
});


/*
 * RECIPE VIEWER
 */
$(document).ready(function(){
        
        var tooltipVisible = false;
        
        if ($('.x-crafting').length > 0) {
            
            $('body').append('<div class="x-crafting-tooltip" style="display: none;">Tooltip is not working.<br>Please contact Tapsa.</div>');
            $('.x-crafting-item').each(function(){
                
                var itemImage = $(this).attr('data-item');
                var itemHover = $(this).attr('data-hover');
                
                if (itemHover.split(':').length > 1) {
                	var pts = itemHover.split(':');
                	itemHover = pts[0];
                	$(this).append($('<span class="x-amount"></span>').text(pts[1]));
                	$(this).attr('data-hover', itemHover);
                }
                
                if (itemImage != '') {
                	if (itemImage.split(';').length == 0) {
                		if (itemImage.indexOf('item:') == 0) {
	                        $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/'
	                        								+ itemImage.replace('item:', '') + '.png")');
	                    } else {
	                        $(this).css('background-image', 'url("' + itemImage + '")');
	                    }
                	} else {
                		
                		var itemImages = itemImage.split(';');
						$(this).attr('data-animate-images', itemImages.join(';'));
						$(this).attr('data-animate-pointer', '0');
						
						var currentImage = itemImages[0];
						
						if (currentImage.indexOf('item:') == 0) {
			                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + currentImage.substr(5) + '.png")');
			            } else {
			                $(this).css('background-image', 'url("' + currentImage + '")');
			            }
			            
                	}
                } else {
                    $(this).css('cursor', 'default');
                }
                
            });
            
            $('body').on('mousemove', function(e){
                if (tooltipVisible) {
                    
                    $('.x-crafting-tooltip').css({
                        top: (e.clientY + 15)+'px',
                        left: (e.clientX + 15)+'px'
                    });
                    
                }
            });
            
            $('.x-crafting-item').on('mouseover', function(e){
                
                if ($(this).attr('data-item') != '' && $(this).attr('data-hover') != '') {
                    $('.x-crafting-tooltip').text($(this).attr('data-hover')).show();
                    tooltipVisible = true;
                }
                
            });
            
            $('.x-crafting-item').on('mouseout', function(e){
                
                $('.x-crafting-tooltip').hide();
                tooltipVisible = false;
                
            });
            
            $('.x-crafting-item').on('click', function(e){
                window.location.href = 'https://kk.xeno.fi/wiki/index.php/' + encodeURIComponent($(this).attr('data-hover'));
            });
            
            var rs = function(){
                $('.x-crafting').each(function(){
                    if ($(this).parent().width() < 350) {
                        var sc = $(this).parent().width()/375;
                        $(this).css('transform-origin', 'top left');
                        $(this).css('transform', 'scale('+sc+')');
                    }
                });
            }
            
            rs();
            $(window).resize(rs);
            
            
            if ($('[data-animate-images]').length > 0) {
            	var __updateAnimations = function(){
            		$('[data-animate-images]').each(function(){
            			
            			var _i = parseInt($(this).attr('data-animate-pointer'));
            			var _imgs = $(this).attr('data-animate-images').split(';');
            			
            			var currentImage = _imgs[_i];
            			if (currentImage.indexOf('item:') == 0) {
			                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + currentImage.substr(5) + '.png")');
			            } else {
			                $(this).css('background-image', 'url("' + currentImage + '")');
			            }
            			
            			_i++;
            			if (_i >= _imgs.length) _i = 0;
            			$(this).attr('data-animate-pointer', ''+_i);
            			
            		});
            	};
            	setInterval(__updateAnimations, 2500);
            	__updateAnimations();
            }
            
        }
        
        
        
        if ($('[data-kk-audio]').length > 0) {
        	$('[data-kk-audio]').each(function(){
        		$(this).replaceWith(
        			$('<audio></audio>')
        				.attr('src', $(this).attr('data-kk-audio'))
        				.attr('controls', 'true')
    			);
        	});
        }
        
    });