MediaWiki:Common.js

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

//********************************************************\\ //***Admin Background Colors for Forums and Message Walls***\\ //************************************************************\\

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Areades"]').length; }).next.css({    background: "rgba(129, 190, 247, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="SamwiseFilmore"]').length; }).next.css({    background: "rgba(208, 112, 48, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Thorin11"]').length; }).next.css({    background: "rgba(167, 178, 0, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="LOTRMod"]').length; }).next.css({    background: "rgba(206, 180, 78, 0.85) url('http://img4.wikia.nocookie.net/__cb20141225003527/lotrminecraftmod/images/thumb/4/4e/Modcreator.png/250px-Modcreator.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Handles-081"]').length; }).next.css({    background: "rgba(0, 204, 255, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Glflegolas"]').length; }).next.css({    background: "rgba(56, 124, 68, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Gen._Grievous1138"]').length; }).next.css({    background: "rgba(220, 20, 60, 0.80) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Sinthoniel"]').length; }).next.css({    background: "rgba(255, 127, 0, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Beijing1000"]').length; }).next.css({    background: "rgba(136, 209, 136, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Glaerdir"]').length; }).next.css({    background: "rgba(249, 98, 165, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Thorin_Stonehelm"]').length; }).next.css({    background: "rgba(7, 21, 212, 0.75) url('http://img2.wikia.nocookie.net/__cb20140625215453/lotrminecraftmod/images/0/03/Admin1_120.png') bottom center no-repeat",    padding: '10px' });

//***********************************************************\\ //***Moderator Background Colors on Forums and Message Walls***\\ //***************************************************************\\

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Seb_TheDunlending"]').length; }).next.css({    background: "rgba(73, 199, 30, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Commandogregor1234"]').length; }).next.css({    background: "rgba(189, 51, 164, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Edacnik"]').length; }).next.css({ /*old color: rgba(255, 26, 26, 0.70)*/    background: "rgba(0, 0, 0, 0.80) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px',    color: "white" }).find(".quote").css({    background: "rgba(200, 200, 200, 0.40)" });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="EpicSpacePanda"]').length; }).next.css({    background: "rgba(14, 199, 159, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Ffets"]').length; }).next.css({    background: "rgba(196, 232, 46, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Narvin"]').length; }).next.css({    background: "rgba( 36, 160, 208, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Smaug_the_Tyrannical"]').length; }).next.css({    background: "rgba(204, 172, 0, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="Special_Elf_Friend"]').length; }).next.css({    background: "rgba(0, 206, 209, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="CaptCaptain"]').length; }).next.css({    background: "rgba(0, 204, 255, 0.70) url('http://img2.wikia.nocookie.net/__cb20141205133613/lotrminecraftmod/images/d/d1/Mod.png') bottom center no-repeat",    padding: '10px' });

//*********************************************************************\\ //***Temporary Moderator Background Colors on Forums and Message Walls***\\ //*************************************************************************\\

$('.speech-bubble-avatar') .filter(function {    return $(this).has('a[href$="TomtheBom"],a[href$="Rocket_Engineer"],a[href$="Recneps"],a[href$="Dinopizzagamer"],a[href$="GimliBurper"],a[href$="High_Prince_Imrahil"]').length; }).next.css({    background: "rgba(205, 192, 176, 0.66) url('http://vignette2.wikia.nocookie.net/lotrminecraftmod/images/b/b2/Temp_mod_tag_3.png/revision/latest?cb=20150605193955') bottom center no-repeat",    padding: '10px' });

// OTHER CODE //

/* Username replace feature * Inserts viewing user's name into * Put text inside the spans to be viewed by logged out users * Originally by Splarka, then by Spang, * This (jQuery) version by wikia:User:Joeyaa, written to be backwards compatible */ if (wgUserName != 'null') { $('.insertusername').html(wgUserName); }

//********************************************\\ //** Worldmap (Template:MiddleEarthMap) [WIP] **\\ //************************************************\\

/* function GetPixel(x, y) { var p = canvas.context.getImageData(x, y, 1, 1).data; var hex = "#" + ("000000" + rgbToHex(p[0], p[1], p[2])).slice(-6); return hex; }

function rgbToHex(r, g, b) { if (r > 255 || g > 255 || b > 255) throw "Invalid color component"; return ((r << 16) | (g << 8) | b).toString(16); }

var map = document.getElementById("worldmap"); // Run the following code only if there is a valid map on the page if (map) { /*   //This code does not work due to security restrictions when getting images from another server var img = document.createElement("img"); img.src = 'http://vignette1.wikia.nocookie.net/lotrminecraftmod/images/7/70/MiddleEarth.png/revision/latest?cb=20150605200727'; img.style.visibility = "hidden"; //   document.body.appendChild(img);

var canvas = document.createElement("canvas"); canvas.id = "canvas"; canvas.style.border = "2px solid red"; canvas.width = img.width; canvas.height = img.height; canvas.style.visibility = "hidden"; canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height); document.body.appendChild(canvas);

alert("debug:" + GetPixel(10, 10)); alert("sucess"); // The current background-position; usually negative map.offX = -500; map.offY = -500; // The position where the dragging was started map.dragX = 0; map.dragY = 0; // The position to which the background will be moved map.newX = 0; map.newY = 0; // The current zoom level. Higher zoom level means bigger map map.zoom = 1.0; // Called when the mouse cursor is pressed down inside the map var dragStart = function(e) { e.preventDefault; map.dragX = e.clientX; map.dragY = e.clientY; document.addEventListener("mouseup", dragEnd); document.addEventListener("mousemove", update); return false; }   // Called when the cursor is released anywhere on the screen. // This event is only triggered after a call of dragStart. It stops the listeners for this event and the update event. var dragEnd = function(e) { e.preventDefault; // If the mouse has not moved, it's no drag but a simple click action if (map.dragX == e.clientX && map.dragY == e.clientY) { /* Link to biome page */ document.removeEventListener("mousemove", update); document.removeEventListener("mouseup", dragEnd); return false; }       map.offX = map.newX; map.offY = map.newY; document.removeEventListener("mousemove", update); document.removeEventListener("mouseup", dragEnd); return false; }   // Called whenever the mouse moves while it is dragging the map var update = function(e) { map.newX = map.offX + e.clientX - map.dragX; map.newY = map.offY + e.clientY - map.dragY; var newpos = map.newX.toString + "px " + map.newY.toString + "px"; map.style.backgroundPosition = newpos; }   // Called whenever the mousewheel is scrolled while the cursor is inside the map var zoom = function(e) { e.preventDefault; // Delta always is a multiple of 3 var delta = e.deltaY / 3; // Set the zoom speed delta *= map.zoom / 15; map.zoom -= delta; // Apply zoom limits if (map.zoom < map.width / 3200) { map.zoom = map.width / 3200; return false; }       if (map.zoom < map.height / 4000) { map.zoom = map.height / 4000; return false; }       // Min zoom level is 300% if (map.zoom > 3.0) { map.zoom = 3.0; return false; }       var sizeX = 3200 * map.zoom; var sizeY = 4000 * map.zoom; var newsize = sizeX.toString + "px " + sizeY.toString + "px"; map.style.backgroundSize = newsize; map.offX *= delta * 15; map.offY *= delat * 15; var newpos = map.offX.toString + "px " + map.offY.toString + "px"; map.style.backgroundPosition = newpos; return false; }   // Start the initial event listeners map.addEventListener("mousedown", dragStart); map.addEventListener("wheel", zoom); }