MediaWiki:Common.js: verschil tussen versies

Uit Wiki Grepolis NL
Naar navigatie springen
(Nieuwe pagina aangemaakt met '→‎Any JavaScript here will be loaded for all users on every page load.: /* //////////////////////////////////////////////////////////////// // =-=-=- HELPER FUNCTI...')
 
Geen bewerkingssamenvatting
 
(13 tussenliggende versies door 4 gebruikers niet weergegeven)
Regel 1: Regel 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
// Old Global.js.
// Rewrite of announcement display.
$ (function () {
// Changes the announcement to the next announcement in the list.
function changeAnnouncement () {
$ (announcementList [currentAnnouncement]).fadeOut ("normal", function () {
++currentAnnouncement;
if (currentAnnouncement >= announcementList.length)
currentAnnouncement = 0;
$ (announcementList [currentAnnouncement]).fadeIn ();
});
}


/*
var announcementList = $ (".announcement");
////////////////////////////////////////////////////////////////
var currentAnnouncement = 0;
// =-=-=- HELPER FUNCTIONS -=-=-=-
var announcementVisibilityTime = 10000; // ms
function addlilink(tabs, url, name, id, title, key){
 
    var na = document.createElement('a');
announcementList.hide ();
    na.href = url;
if (announcementList.length > 1) {
    na.appendChild(document.createTextNode(name));
$ (announcementList [0]).fadeIn ();
    var li = document.createElement('li');
setInterval (changeAnnouncement, announcementVisibilityTime);
    if(id) li.id = id;
} else if (announcementList.length > 0)
    li.appendChild(na);
announcementList.fadeIn ();
    tabs.appendChild(li);
 
    if(id)
 
    {
// Piwik is undefined -> comment it out.
        if(key && title)
/*
        {
try {
            ta[id] = [key, title];
var piwikTracker = Piwik.getTracker (pkBaseURL + "piwik.php", 2);
        }
piwikTracker.trackPageView ();
        else if(key)
piwikTracker.enableLinkTracking ();
        {
} catch (err) {}
            ta[id] = [key, ''];
*/
        }
});
        else if(title)
 
        {
// ?
            ta[id] = ['', title];
var importScript_ = importScript;
        }
 
    }
 
    // re-render the title and accesskeys from existing code in wikibits.js
// Makes the sidebar foldable (by Menidan)
    akeytt();
var sidebar_settings = JSON.parse (localStorage.getItem ("sidebar_settings")) || {};
    return li;
 
function save_sidebar () {
localStorage.setItem ("sidebar_settings", JSON.stringify (sidebar_settings));
}
}


function addToolboxLink(url, name, id, title){
function set_sidebar (id, folded) {
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
if (document.getElementById (id).parentElement.id != "column-one")
    addlilink(tb, url, name, id, title);
return;
if (folded)
sidebar_settings [id] = true;
else
delete sidebar_settings [id];
save_sidebar ();
}
}


function addTab(url, name, id, title, key) {
var fold = "https://wiki.de.grepolis.com/images/7/7e/Einklappen.png";
    return addPortletLink('p-cactions', url, name, id, title, key);
var unfold = "https://wiki.de.grepolis.com/images/0/06/Ausklappen.png";
function sidebar_click (node) {
var content = $ (node.parentElement.lastElementChild);
if (content.css ("display") == "none") {
content.css ("display", "block");
node.firstElementChild.alt = "[-]";
node.firstElementChild.src = fold;
set_sidebar (node.parentElement.id, false);
} else {
content.css ("display", "none");
node.firstElementChild.alt = "[+]";
node.firstElementChild.src = unfold;
set_sidebar (node.parentElement.id, true);
}
return false;
}
}


function addLink(where, url, name, id, title, key, after){
var sidebar_links = $ ("#column-one .generated-sidebar.portlet h5").slice (1).replaceWith (function () {
    var na = document.createElement('a');
if (! sidebar_settings [this.parentElement.id])
    na.href = url;
return $ ('<a href="#" style="text-align:center"><img src="' + fold + '" style="float:left" alt="[-]" /><h5>' + this.innerHTML + '</h5></a>').click (function () {
    na.appendChild(document.createTextNode(name));
return sidebar_click (this);
    var li = document.createElement('li');
});
    if(id) li.id = id;
 
    li.appendChild(na);
$ (this.nextElementSibling).css ("display", "none");
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
return $ ('<a href="#" style="text-align:center"><img src="' + unfold + '" style="float:left" alt="[+]" /><h5>' + this.innerHTML + '</h5></a>').click (function () {
    if(after) {
return sidebar_click (this);
tabs.insertBefore(li,document.getElementById(after));
});
    } else {
});
tabs.appendChild(li);
 
    }
 
    if(id) {
// Halloween 2013 (by Menidan)
if(key && title) { ta[id] = [key, title]; }
if (location.pathname == "/wiki/Halloween_2013_im_Wiki" && ! localStorage.getItem ("halloween-2013")) {
else if(key) { ta[id] = [key, '']; }
localStorage.setItem ("halloween-2013", "delete this entry to show the window again");
else if(title) { ta[id] = ['', title];}
var overlay = $ ('<div></div>').appendTo (document.body);
    }
overlay.css ({
    // re-render the title and accesskeys from existing code in wikibits.js
"background-color": "black",
    akeytt();
"background-position": "center",
    return li;
"background-size": "contain",
}
"background-repeat": "no-repeat",
"background-attachment": "fixed",
"backgound-image": "url(/images/e/ea/Test.gif)",
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0,
"z-index": 10
});
overlay [0].style.backgroundImage = "url(/images/e/ea/Test.gif)";
$ (document.body).css ("overflow", "hidden");
 
var close_button = $ ('<a href="#"><img src="/images/7/75/Grepolis_Wiki_307.png" /></a>').appendTo (overlay).css ({
position: "absolute",
top: "10px",
right: "10px"
}).click (function () {
$ (document.body).css ("overflow", "");
overlay.remove ();
$ (audio).remove ();
});
 
var audio = $ ('<audio preload="preload" autostart="autostart"><source src="http://www.horror-grusel.de/horror0407/sounds/hexe.wav" /></audio>').appendTo (overlay) [0];
audio.addEventListener ("load", function () {
alert ("loaded");
audio.play ();
});
audio.addEventListener ("ended", function () {
setTimeout (function () {
audio.currentTime = 0;
audio.play ();
}, 1); // die 1 durch beliebige Anzahl an Millisekunden zwischen dem einzelnen Abspielen des Geräusches ersetzen
});
audio.load ();
audio.play ();
}  
 


function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '#';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}


function addnavbox_link(URL,Name,ID)
// Simple Culture Point Calculator (by Menidan)
{
(function () {
var portlet = document.getElementById('p-navigation');
function is_right_page () {
var links = portlet.getElementsByTagName('ul')[0];
if (location.pathname == "/wiki/Kulturpunkte")
links.innerHTML += '<li id="' + ID + '"><a href="' + URL + '">' + Name + '</a></li>';
return true;
}
if (location.pathname != "/index.php")
/////////////////////////////////////////////
return false;
*/
var query = location.search.substring (1).split ("&").map (function (s) { return s.split ("="); });
document.write("<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js' type='text/javascript'></script>");
if (! query.find (function (s) { return s [0] == "title" && s [1] == "Kulturpunkte"; }))
return false;
return ! query.find (function (s) { return s [0] == "action" && s [1] != "view"; });
}
if (! is_right_page ())
return;


document.write("<script src='/index.php?title=Global.js&action=raw&smaxage=0&ctype=text/javascript' type='text/javascript'></script>");
var table = $ ("table.wikitable");
var tr = $ ("<tr>").insertAfter (table.find ("tr:first"));
function level_from_points (points) { return Math.floor (3 / 2 + Math.sqrt (1 / 4 + 2 / 3 * points)); }
function points_from_level (level) { return Math.floor (3 / 2 * (level - 1) * (level - 2)); }
var level  = $ ('<input type="text" value="5" />').bind ("propertychange keyup input paste", function () {
points.val (points_from_level (level.val ()));
}).appendTo ($ ("<th>").appendTo (tr));
var points = $ ('<input type="text" value="18" />').bind ("propertychange keyup input paste", function () {
level.val (level_from_points (points.val ()));
}).appendTo ($ ("<th>").appendTo (tr));
}) ();

Huidige versie van 20 jun 2020 om 07:07

/* Any JavaScript here will be loaded for all users on every page load. */
// Old Global.js.
// Rewrite of announcement display.
$ (function () {
	// Changes the announcement to the next announcement in the list.
	function changeAnnouncement () {
		$ (announcementList [currentAnnouncement]).fadeOut ("normal", function () {
			++currentAnnouncement;
			if (currentAnnouncement >= announcementList.length)
				currentAnnouncement = 0;
			$ (announcementList [currentAnnouncement]).fadeIn ();
		});
	}

	var announcementList = $ (".announcement");
	var currentAnnouncement = 0;
	var announcementVisibilityTime = 10000; // ms

	announcementList.hide ();
	if (announcementList.length > 1) {
		$ (announcementList [0]).fadeIn ();
		setInterval (changeAnnouncement, announcementVisibilityTime);
	} else if (announcementList.length > 0)
		announcementList.fadeIn ();


	// Piwik is undefined -> comment it out.
	/*
	try {
		var piwikTracker = Piwik.getTracker (pkBaseURL + "piwik.php", 2);
		piwikTracker.trackPageView ();
		piwikTracker.enableLinkTracking ();
	} catch (err) {}
	*/
});

// ?
var importScript_ = importScript;


// Makes the sidebar foldable (by Menidan)
var sidebar_settings = JSON.parse (localStorage.getItem ("sidebar_settings")) || {};

function save_sidebar () {
	localStorage.setItem ("sidebar_settings", JSON.stringify (sidebar_settings));
}

function set_sidebar (id, folded) {
	if (document.getElementById (id).parentElement.id != "column-one")
		return;
	if (folded)
		sidebar_settings [id] = true;
	else
		delete sidebar_settings [id];
	save_sidebar ();
}

var fold = "https://wiki.de.grepolis.com/images/7/7e/Einklappen.png";
var unfold = "https://wiki.de.grepolis.com/images/0/06/Ausklappen.png";
function sidebar_click (node) {
	var content = $ (node.parentElement.lastElementChild);
	if (content.css ("display") == "none") {
		content.css ("display", "block");
		node.firstElementChild.alt = "[-]";
		node.firstElementChild.src = fold;
		set_sidebar (node.parentElement.id, false);
	} else {
		content.css ("display", "none");
		node.firstElementChild.alt = "[+]";
		node.firstElementChild.src = unfold;
		set_sidebar (node.parentElement.id, true);
	}
	return false;
}

var sidebar_links = $ ("#column-one .generated-sidebar.portlet h5").slice (1).replaceWith (function () {
	if (! sidebar_settings [this.parentElement.id])
		return $ ('<a href="#" style="text-align:center"><img src="' + fold + '" style="float:left" alt="[-]" /><h5>' + this.innerHTML + '</h5></a>').click (function () {
			return sidebar_click (this);
		});

	$ (this.nextElementSibling).css ("display", "none");
	return $ ('<a href="#" style="text-align:center"><img src="' + unfold + '" style="float:left" alt="[+]" /><h5>' + this.innerHTML + '</h5></a>').click (function () {
		return sidebar_click (this);
	});
});


// Halloween 2013 (by Menidan)
if (location.pathname == "/wiki/Halloween_2013_im_Wiki" && ! localStorage.getItem ("halloween-2013")) {
	localStorage.setItem ("halloween-2013", "delete this entry to show the window again");
	var overlay = $ ('<div></div>').appendTo (document.body);
	overlay.css ({
		"background-color": "black",
		"background-position": "center",
		"background-size": "contain",
		"background-repeat": "no-repeat",
		"background-attachment": "fixed",
		"backgound-image": "url(/images/e/ea/Test.gif)",
		position: "absolute",
		left: 0,
		right: 0,
		top: 0,
		bottom: 0,
		"z-index": 10
	});
	overlay [0].style.backgroundImage = "url(/images/e/ea/Test.gif)";
	$ (document.body).css ("overflow", "hidden");

	var close_button = $ ('<a href="#"><img src="/images/7/75/Grepolis_Wiki_307.png" /></a>').appendTo (overlay).css ({
		position: "absolute",
		top: "10px",
		right: "10px"
	}).click (function () {
		$ (document.body).css ("overflow", "");
		overlay.remove ();
		$ (audio).remove ();
	});

	var audio = $ ('<audio preload="preload" autostart="autostart"><source src="http://www.horror-grusel.de/horror0407/sounds/hexe.wav" /></audio>').appendTo (overlay) [0];
	audio.addEventListener ("load", function () {
		alert ("loaded");
		audio.play ();
	});
	audio.addEventListener ("ended", function () {
		setTimeout (function () {
			audio.currentTime = 0;
			audio.play ();
		}, 1); // die 1 durch beliebige Anzahl an Millisekunden zwischen dem einzelnen Abspielen des Geräusches ersetzen
	});
	audio.load ();
	audio.play ();
} 



// Simple Culture Point Calculator (by Menidan)
(function () {
	function is_right_page () {
		if (location.pathname == "/wiki/Kulturpunkte")
			return true;
		if (location.pathname != "/index.php")
			return false;
		var query = location.search.substring (1).split ("&").map (function (s) { return s.split ("="); });
		if (! query.find (function (s) { return s [0] == "title" && s [1] == "Kulturpunkte"; }))
			return false;
		return ! query.find (function (s) { return s [0] == "action" && s [1] != "view"; });
	}
	if (! is_right_page ())
		return;

	var table = $ ("table.wikitable");
	var tr = $ ("<tr>").insertAfter (table.find ("tr:first"));
	function level_from_points (points) { return Math.floor (3 / 2 + Math.sqrt (1 / 4 + 2 / 3 * points)); }
	function points_from_level (level) { return Math.floor (3 / 2 * (level - 1) * (level - 2)); }
	var level  = $ ('<input type="text" value="5" />').bind ("propertychange keyup input paste", function () {
		points.val (points_from_level (level.val ()));
	}).appendTo ($ ("<th>").appendTo (tr));
	var points = $ ('<input type="text" value="18" />').bind ("propertychange keyup input paste", function () {
		level.val (level_from_points (points.val ()));
	}).appendTo ($ ("<th>").appendTo (tr));
}) ();