Difference between revisions of "MediaWiki:Common.js"

From Unrailed! Wiki
Jump to navigation Jump to search
(jQuery UI Dragging Test)
Line 25: Line 25:
 
$(this).css("background-image", 'url(' + ')');
 
$(this).css("background-image", 'url(' + ')');
 
});
 
});
 +
});
  
`mw.loader.load('jquery.ui').then(function(){  
+
`mw.loader.load('jquery.ui').then(function(){  
jQuery.fn.swap = function(b){
+
jQuery.fn.swap = function(b){
b = jQuery(b)[0];  
+
b = jQuery(b)[0];  
var a = this[0];  
+
var a = this[0];  
var t = a.parentNode.insertBefore(document.createTextNode(''), a);  
+
var t = a.parentNode.insertBefore(document.createTextNode(''), a);  
b.parentNode.insertBefore(a, b);  
+
b.parentNode.insertBefore(a, b);  
t.parentNode.insertBefore(b, t);  
+
t.parentNode.insertBefore(b, t);  
t.parentNode.removeChild(t);  
+
t.parentNode.removeChild(t);  
return this;  
+
return this;  
};
+
};
  
$( ".wagon-slot" ).draggable({helper: "clone"});
+
$( ".wagon-slot" ).draggable({helper: "clone"});
$( ".wagon-slot" ).droppable({
+
$( ".wagon-slot" ).droppable({
accept: ".wagon-slot",
+
accept: ".wagon-slot",
activeClass: "ui-state-hover",
+
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
+
hoverClass: "ui-state-active",
drop: function(event, ui){
+
drop: function(event, ui){
var draggable = ui.draggable, droppable = $(this),
+
var draggable = ui.draggable, droppable = $(this),
dragPos = draggable.position(), dropPos = droppable.position();
+
dragPos = draggable.position(), dropPos = droppable.position();
draggable.swap(droppable);
+
draggable.swap(droppable);
}
+
}
});
+
});
})`
+
})`
});
 

Revision as of 16:45, 5 August 2021

/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function(){
	var wagonConfiguratorList;
	var wagonSelection;

	var wagonImages = {"wagonNone" : "", "wagonBrake" : "https://unrailed-wiki.com/images/thumb/8/83/BrakeWagon_3.png/128px-BrakeWagon_3.png", "wagonBuckinator" : "https://unrailed-wiki.com/images/thumb/0/01/BuckinatorWagon_3.png/128px-BuckinatorWagon_3.png", "wagonCollector" : "https://unrailed-wiki.com/images/thumb/0/0a/CollectorWagon_3.png/128px-CollectorWagon_3.png", "wagonCompass" : "https://unrailed-wiki.com/images/thumb/8/88/CompassWagon_1.png/128px-CompassWagon_1.png", "wagonCrafter" : "https://unrailed-wiki.com/images/thumb/f/f8/CraftingWagon_3.png/128px-CraftingWagon_3.png", "wagonDynamite" : "https://unrailed-wiki.com/images/thumb/8/89/DynamiteWagon_3.png/128px-DynamiteWagon_3.png", "wagonGhost" : "https://unrailed-wiki.com/images/thumb/1/1f/GhostWagon_1.png/128px-GhostWagon_1.png", "wagonLight" : "https://unrailed-wiki.com/images/thumb/7/7a/LightWagon_2.png/128px-LightWagon_2.png", "wagonMilk" : "https://unrailed-wiki.com/images/thumb/5/59/MilkWagon_3.png/128px-MilkWagon_3.png", "wagonMiner" : "https://unrailed-wiki.com/images/thumb/a/ab/MinerWagon_3.png/128px-MinerWagon_3.png", "wagonSlots" : "https://unrailed-wiki.com/images/thumb/1/13/SlotMachineWagon_3.png/128px-SlotMachineWagon_3.png", "wagonStorage" : "https://unrailed-wiki.com/images/thumb/1/1f/StorageWagon_3.png/128px-StorageWagon_3.png", "wagonSupercharger" : "https://unrailed-wiki.com/images/thumb/7/70/SuperchargerWagon_3.png/128px-SuperchargerWagon_3.png", "wagonTank" : "https://unrailed-wiki.com/images/thumb/f/f1/TankWagon_3.png/128px-TankWagon_3.png", "wagonTransformer" : "https://unrailed-wiki.com/images/thumb/4/4b/TransformerWagon_3.png/128px-TransformerWagon_3.png"};

	$('#wagon-configurator-list li').click(function(){
		$(this).addClass('selected');
		$(this).siblings().removeClass('selected');
	});

	$('#wagon-configurator-slots li.wagon-slot').click(function(){
		if ($('#wagon-configurator-list li.wagonNone').hasClass('selected')){
			$(this).removeClass('wagon-tank wagon-storage wagon-crafter');
		}
		wagonConfiguratorList = $('#wagon-configurator-list li.selected')[0].classList[0];
		window['wagonConfiguratorList'] = wagonConfiguratorList;
		$(this).css("background-image", 'url(' + wagonImages[wagonConfiguratorList] + ')');
	});

	$('#wagon-configurator-slots li.wagon-slot').bind('contextmenu', function(e){
		e.preventDefault();
		$(this).css("background-image", 'url(' + ')');
	});
});

`mw.loader.load('jquery.ui').then(function(){ 
	jQuery.fn.swap = function(b){
		b = jQuery(b)[0]; 
		var a = this[0]; 
		var t = a.parentNode.insertBefore(document.createTextNode(''), a); 
		b.parentNode.insertBefore(a, b); 
		t.parentNode.insertBefore(b, t); 
		t.parentNode.removeChild(t); 
		return this; 
	};

	$( ".wagon-slot" ).draggable({helper: "clone"});
	$( ".wagon-slot" ).droppable({
		accept: ".wagon-slot",
		activeClass: "ui-state-hover",
		hoverClass: "ui-state-active",
		drop: function(event, ui){
			var draggable = ui.draggable, droppable = $(this),
				dragPos = draggable.position(), dropPos = droppable.position();
			draggable.swap(droppable);
		}
	});
})`