Ouvrir le menu principal

Modifications

MediaWiki:Common.js

4 716 octets supprimés, 19 février 2014 à 20:01
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
 
/******************************************************************/
// Test if an element has a certain class
// Description: Uses regular expressions and caching for better performance.
// Source: http://dragonage.wikia.com/wiki/MediaWiki:Common.js
/******************************************************************/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
 
/******************************************************************/
// Sliders using jquery by Tierrie
// Source: http://dragonage.wikia.com/wiki/MediaWiki:Common.js
// Author: http://dragonage.wikia.com/wiki/User:Tierrie
/******************************************************************/
mw.loader.load("jquery.ui.tabs");
 
$(function() {
var $tabs = $("#portal_slider").tabs({ fx: {opacity:'toggle', duration:100} } );
$("[class^=portal_sliderlink]").click(function() { // bind click event to link
$tabs.tabs('select', this.className.replace("portal_sliderlink_", ""));
return false;
});
$('#portal_next').click(function() {
$tabs.tabs('select', ($tabs.tabs('option', 'selected') == ($tabs.tabs('length'))-1) ? 0 : $tabs.tabs('option', 'selected') + 1 ); // switch to next tab
return false;
});
$('#portal_prev').click(function() { // bind click event to link
$tabs.tabs('select', ($tabs.tabs('option', 'selected') == 0) ? ($tabs.tabs('length')-1) : $tabs.tabs('option', 'selected') - 1 ); // switch to previous tab
return false;
});
});
 
/****************************************************************/
// Spoilers by Tierrie
// Source: http://dragonage.wikia.com/wiki/MediaWiki:Common.js
// Author: http://dragonage.wikia.com/wiki/User:Tierrie
/****************************************************************/
var showSpoiler = new Array();
 
function showSpoilers(splrType) {
var Divs= document.getElementsByTagName("div");
for (i=0;i<Divs.length;i++) {
// allows the child to be something besides a div (a table for example)
if (hasClass(Divs[i], 'splr') && hasClass(Divs[i].childNodes[0], 'splr_'+splrType)) {
var warning = Divs[i].childNodes[0].childNodes[1];
warning.className = warning.className.replace('show_warning','hide_warning');
var spoiler = Divs[i].childNodes[1];
spoiler.className = spoiler.className.replace('hide_spoiler','show_spoiler');
}
}
document.cookie='showspoiler_'+splrType+'=1; path=/';
}
 
function hideSpoilers(splrType) {
var Divs= document.getElementsByTagName("div");
for (i=0;i<Divs.length;i++) {
// allows the child to be something besides a div (a table for example)
if (hasClass(Divs[i], 'splr') && hasClass(Divs[i].childNodes[0], 'splr_'+splrType)) {
var warning = Divs[i].childNodes[0].childNodes[1];
warning.className = warning.className.replace('hide_warning','show_warning');
var spoiler = Divs[i].childNodes[1];
spoiler.className = spoiler.className.replace('show_spoiler','hide_spoiler');
}
}
document.cookie='showspoiler_'+splrType+'=0; path=/';
}
 
function toggleSpoilers(ev) {
var splrType=this.className.split('_')[1];
showSpoiler[splrType] = showSpoiler[splrType]?0:1;
if(showSpoiler[splrType])
showSpoilers(splrType);
else
hideSpoilers(splrType);
//ev.target.focus(); /* focus back on the element because large spoilers tend to move the page around */
}
 
function initSpoilers() {
var Divs= document.getElementsByTagName("div");
for (i=0;i<Divs.length;i++) {
if (hasClass(Divs[i], 'splr')) {
Divs[i].childNodes[0].onclick = toggleSpoilers;
var warning = Divs[i].childNodes[0].childNodes[1];
warning.className = warning.className.replace('hide_warning','show_warning');
var spoiler = Divs[i].childNodes[1];
spoiler.className = spoiler.className.replace('show_spoiler','hide_spoiler');
}
}
var cookies = document.cookie.split("; ");
for (var i=0; i < cookies.length; i++) {
// a name/value pair (a crumb) is separated by an equal sign
if(cookies[i].indexOf('showspoiler')!=-1) {
var crumbs = cookies[i].split("=");
var splrType = crumbs[0].split('_')[1]; /* cookie="showspoiler_terawjol=1", crumbs[0] = "showspoiler_terawjol", splrType="terawjol" */
var splrValue = parseInt(crumbs[1]);
showSpoiler[splrType]=splrValue;
if(splrValue)
showSpoilers(splrType);
else
hideSpoilers(splrType);
}
}
}
 
var spoilers = true;
function loadSpoilers() {
if(spoilers) initSpoilers();
}
addOnloadHook(loadSpoilers);