MediaWiki:Common.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
M (+głosowanie, na razie wyłączone -- włączę, jak się style odświeżą) |
M (Ocenianie już działa <fanfary>) |
||
Linia 310: | Linia 310: | ||
ratings.onlyusers = false; // czy tylko zalogowani mogą głosować |
ratings.onlyusers = false; // czy tylko zalogowani mogą głosować |
||
ratings.disabled = |
ratings.disabled = false; // czy głosowanie jest wyłączone |
||
ratings.text = null; |
ratings.text = null; |
||
ratings.setup = function() { |
ratings.setup = function() { |
Wersja z 19:20, 2 wrz 2010
/*
[http://nonsensopedia.wikia.com/index.php?title=MediaWiki:Common.js&action=purge purge], [http://nonsensopedia.wikia.com/index.php?title=-&action=raw&smaxage=0&gen=js purge2]
<pre>
*/
/* * Poniższy fragment pochodzi ze strony: http://pl.wikipedia.org/wiki/MediaWiki:Common.js
* Lista autorów: http://pl.wikipedia.org/w/index.php?title=MediaWiki:Common.js&action=history
* Licencja: http://www.gnu.org/copyleft/fdl.html */
function returnObjById( id )
{
var returnVar=null;
if (document.getElementById)
returnVar = document.getElementById(id);
else if (document.all)
returnVar = document.all[id];
else if (document.layers)
returnVar = document.layers[id];
return returnVar;
}
/**
* Skrypt dla Szablon:Galeria
* Źródło: http://pl.wikipedia.org/wiki/MediaWiki:Common.js
* Autorzy: http://pl.wikipedia.org/w/index.php?title=MediaWiki:Common.js&action=history
* Licencja: http://www.gnu.org/copyleft/fdl.html
*/
function toggleImage(group, remindex, shwindex) {
returnObjById("ImageGroupsGr"+group+"Im"+remindex).style.display="none";
returnObjById("ImageGroupsGr"+group+"Im"+shwindex).style.display="inline";
}
function ImageGroup(){
if (document.URL.match(/printable/g)) return;
var divs=document.getElementsByTagName("div");
var i = 0, j = 0;
var units, search;
var currentimage;
var UnitNode;
for (i = 0; i < divs.length ; i++) {
if (divs[i].className != "ImageGroup") continue;
UnitNode=undefined;
search=divs[i].getElementsByTagName("div");
for (j = 0; j < search.length ; j++) {
if (search[j].className != "ImageGroupUnits") continue;
UnitNode=search[j];
break;
}
if (UnitNode==undefined) continue;
units=Array();
for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
var temp = UnitNode.childNodes[j];
if (temp.className=="center") units.push(temp);
}
for (j = 0 ; j < units.length ; j++) {
currentimage=units[j];
currentimage.id="ImageGroupsGr"+i+"Im"+j;
var imghead = document.createElement("div");
var leftlink = document.createElement("a");
var rightlink = document.createElement("a");
if (j != 0) {
leftlink.href = "javascript:toggleImage("+i+","+j+","+(j-1)+");";
}
leftlink.innerHTML="◀";
if (j != units.length - 1) {
rightlink.href = "javascript:toggleImage("+i+","+j+","+(j+1)+");";
}
rightlink.innerHTML="▶";
var comment = document.createElement("tt");
comment.innerHTML = "("+ (j+1) + "/" + units.length + ")";
with(imghead) {
style.fontSize="110%";
style.fontweight="bold";
appendChild(leftlink);
appendChild(comment);
appendChild(rightlink);
}
currentimage.insertBefore(imghead,currentimage.childNodes[0]);
if (j != 0) currentimage.style.display="none";
}
}
}
addOnloadHook(ImageGroup);
/* Zmiana tytulu strony, autor: [[user:Vae]], Public Domain */
/* Użycie: {{nibytytul|Przykladowy tytul}} */
/* {{nibytytul|Przykladowy tytul|sub=Podtytul}} */
function uChangeTitle(){
var staryTytul=null;
staryTytul=returnObjById("firstHeading"); /* monobook */
if(!staryTytul) /* monaco */
{
var h1=document.body.getElementsByTagName("h1");
for(i in h1)
{
if(h1[i].className=="firstHeading")
{
staryTytul=h1[i];
}
}
}
var nowyTytul=null;
nowyTytul=returnObjById("uTytulStrony");
if(nowyTytul && staryTytul){
// sprawdzamy, czy zawiera cudzyslowy (np. strona edycji)
// jesli tak, podmieniamy tylko zawartosc cudzyslowow
if(staryTytul.innerHTML.match(/^.*?„.*?”.*?$/))
staryTytul.innerHTML=staryTytul.innerHTML.replace(/^(.*?)„.*?”(.*?)$/,"$1"+"„"+nowyTytul.innerHTML+"”"+"$2");
else if(staryTytul.innerHTML.match(/<span>/i))
staryTytul.innerHTML=staryTytul.innerHTML.replace(/^(.*?)<span>/,returnObjById("uTytulStrony").innerHTML+"<span>");
else
staryTytul.innerHTML=returnObjById("uTytulStrony").innerHTML;
staryTytul.style.backgroundColor=nowyTytul.style.backgroundColor;
staryTytul.style.color=nowyTytul.style.color;
// sprawdzamy, czy podtytul tez jest do zamiany
var ssub = returnObjById("uPodtytulStrony");
var sub = returnObjById("siteSub");
if(ssub && ssub.innerHTML && sub)
{
sub.innerHTML=ssub.innerHTML;
}
}
if(returnObjById("uLogoStrony"))
{
var a=(skin=="monobook")?returnObjById("p-logo").getElementsByTagName('a')[0]:returnObjById("wiki_logo");
a.style.backgroundImage="url("+returnObjById("uLogoStrony").getElementsByTagName('img')[0].src+")";
}
return;
}
addOnloadHook(function(){uChangeTitle();});
/* koniec */
// ============================================================
// BEGIN Dynamic Navigation Bars (experimantal)
// pochodzi z http://en.wikipedia.org/wiki/MediaWiki:Monobook.js
// autorzy: http://en.wikipedia.org/w/index.php?title=MediaWiki:Monobook.js&action=history
// licencja: GFDL
// set up the words in your language
var NavigationBarHide = '[ Ukryj ]';
var NavigationBarShow = '[ Pokaż ]';
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
var NavigationBarShowDefault = 1;
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if (NavChild.className == 'NavPic') {
NavChild.style.display = 'none';
}
if (NavChild.className == 'NavContent') {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if (NavChild.className == 'NavPic') {
NavChild.style.display = 'block';
}
if (NavChild.className == 'NavContent') {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
for(
var i=0;
NavFrame = document.getElementsByTagName("div")[i];
i++
) {
// if found a navigation bar
if (NavFrame.className == "NavFrame") {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var NavToggleText = document.createTextNode(NavigationBarHide);
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for(
var j=0;
j < NavFrame.childNodes.length;
j++
) {
if (NavFrame.childNodes[j].className == "NavHead") {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
// if more Navigation Bars found than Default: hide all
if (NavigationBarShowDefault < indexNavigationBar && !wgTitle.match(/Najbardziej poszablonowana/)) {
for(
var i=1;
i<=indexNavigationBar;
i++
) {
toggleNavigationBar(i);
}
}
}
addOnloadHook(function(){createNavigationBarToggleButton();});
// END Dynamic Navigation Bars
// ============================================================
importScript('MediaWiki:Facebook.js'); // pasek podziel się tym
/////////// /////////
// Skrypt dodający do licznika edycji (Specjalna:Editcount) rubrykę "edycje kreatywne" //
// Autor: [[user:Vae]], licencja: Public Domain //
/////////// /////////
function format_th2(num)
{
if(num>=1000)
{
return ""+Math.floor(num/1000)+" "+(num%1000);
}
return ""+num;
}
function format_comma2(num)
{
return (""+(Math.round(num*100)/100.0)).replace(/\./,",");
}
function kreatywne2()
{
if(!wgPageName) return;
if(wgPageName!='Specjalna:Editcount')
return;
var przestrzenie=[/główna/,/^NonNews/,/^Cytaty/,/^Słownik/,/^Nonźródła/,/^Poradnik/,/^Gra/];
var f= document.getElementById("editcount").getElementsByTagName('table')[1].getElementsByTagName('tr');
var ekreatywne=0,procent=0.0;
for(i in f)
{
if(!f[i].innerHTML) break;
var nazwa=f[i].getElementsByTagName('td');
if(nazwa.length) nazwa=nazwa[0].innerHTML;
else continue;
for(j in przestrzenie)
{
if(nazwa.match(przestrzenie[j]))
{
ekreatywne+=parseInt(f[i].getElementsByTagName('td')[1].innerHTML.replace(/[\D]/g,''));
procent+=parseFloat(f[i].getElementsByTagName('td')[2].innerHTML.replace(/,/g,'.').replace(/[^0-9.]/g,''));
}
}
}
var ttab=document.getElementById("editcount").getElementsByTagName('table')[1];
ttab.innerHTML+='<tr><td class="ecrowcenter"><b>Edycje kreatywne</b></td><td class="ecrowright"><b>'+format_th2(ekreatywne)+'</b></td><td class="ecrowright"><b>'+format_comma2(procent)+'%</b></td><td colspan="3"></td></tr>';
}
addOnloadHook(kreatywne2);
/** Voting *******************************
* Autor: Spang z Uncyclopedii ( http://uncyclopedia.wikia.com/wiki/User:Spang )
* Przystosował: Vae
* Voting system
* Add "ratings.disabled = true" without the quotes to your JS to disable
*/
ratings = {};
ratings.onlyusers = false; // czy tylko zalogowani mogą głosować
ratings.disabled = false; // czy głosowanie jest wyłączone
ratings.text = null;
ratings.setup = function() {
switch(wgCanonicalNamespace)
{
// Poniżej znajduje się lista przestrzeni, w których można głosować.
// Śmiało proponuj zmiany.
case "": // przestrzeń główna (artykuły)
case "NonNews":
case "Cytaty":
case "Nonźródła":
case "Słownik":
case "Poradnik":
case "Gra":
case "Plik":
case "Grafika": // na wszelki wypadek
case "File":
case "Wideo":
case "Video":
break;
default:
return;
}
if(ratings.disabled == true ) {
return;
}
if( wgTitle == "Strona główna" )
{
return;
}
ratings.p = document.createElement( 'div' );
var co_to,kl;
switch(wgCanonicalNamespace)
{
case "":
co_to = "artykuł"; // formy w bierniku
kl = 'y'; // końcówki przymiotnika w mianowniku
break;
case "NonNews":
co_to = "wiadomość";
kl = 'a';
break;
case "Nonźródła":
co_to = "źródło";
kl = 'e';
break;
case "Poradnik":
co_to = "poradnik";
kl = 'y';
break;
case "Plik":
case "Grafika":
case "File":
co_to = "bohomaz"
kl = 'y';
break;
case "Wideo":
case "Video":
co_to = "film"
kl = 'y';
break;
default:
co_to = "stronę"
kl = 'a';
break;
}
var a = document.getElementById( 'p-spo.C5.82eczno.C5.9B.C4.87' );
if( !a ) {
return;
}
ratings.p.innerHTML = '<h5>oceń '+co_to+'</h5><div id="ratingBody" class="pBody"><div><ul id="ratingStars" onmouseout="ratings.paint(0);"><li id="vote-1" class="voteStar" onmouseover="ratings.paint(1)" onclick="ratings.vote(1);"> 1</li><li id="vote-2" class="voteStar" onmouseover="ratings.paint(2)" onclick="ratings.vote(2);"> 2</li><li id="vote-3" class="voteStar" onmouseover="ratings.paint(3)" onclick="ratings.vote(3);"> 3</li><li id="vote-4" class="voteStar" onmouseover="ratings.paint(4)" onclick="ratings.vote(4);"> 4</li><li id="vote-5" class="voteStar" onmouseover="ratings.paint(5)" onclick="ratings.vote(5);"> 5 </li></ul></div><span id="ratingMsg">Oceń '+co_to+'</span></div>';
ratings.p.className = 'portlet';
ratings.p.id = 'p-rating';
document.getElementById( 'column-one' ).insertBefore( ratings.p, a );
ratings.text = [ 'Oceń '+co_to, 'Wyjątkowo słab'+kl, 'Nic ciekawego', 'Warto przeczytać', 'Bardzo dobr'+kl, 'Rewelacyjn'+kl ];
ratings.get = YAHOO.util.Connect.asyncRequest( 'GET', '/api.php?format=json&action=query&list=wkvoteart&wkctime=5&wkpage=' + wgArticleId, ratings.getCallback, null );
};
ratings.getCallback = {
success : function( o ) {
var j = YAHOO.tools.JSONParse( o.responseText );
try {
with( j.query.wkvoteart[wgArticleId] ) {
if( typeof votesavg != undefined && votesavg ) {
ratings.avgVote = ( 5 >= votesavg >= 1 ? Math.round( votesavg * 10 ) / 10 : 5 );
ratings.text[0] = ( 'średnia ocena: ' + ratings.avgVote );
}
ratings.hasVoted = false;
ratings.paint( 0 );
}
} catch( e ) {
}
},
failure : function( o ) {
ratings.out( 'Nie udało mi się połączyć z serwerem. Widocznie admin potknął się o wtyczkę. :(' );
}
};
ratings.vote = function( a ) {
var b = ( ratings.hasVoted == true ? 'update' : 'insert' );
if ( ratings.hasVoted ) {
ratings.get = YAHOO.util.Connect.asyncRequest( 'GET', '/api.php?format=json&action=delete&list=wkvoteart&wkpage=' + wgArticleId, ratings.vote( a ), null );
}
ratings.get = YAHOO.util.Connect.asyncRequest( 'GET', '/api.php?format=json&action=' + b + '&list=wkvoteart&wkuservote=1&wkctime=5&wkpage=' + wgArticleId + '&wkvote=' + a, ratings.voteCallback, null );
ratings.myVote = a;
ratings.paint( a, 'zapisywanie głosu...' );
ratings.votingInProgress = true
};
ratings.voteCallback = {
success : function( o ) {
var j = YAHOO.tools.JSONParse( o.responseText );
if( j.item.wkvoteart[3] != undefined && ratings.retried != true ) {
ratings.retried = true;
ratings.out( 'błąd... spróbujemy jeszcze raz' );
ratings.get = YAHOO.util.Connect.asyncRequest( 'GET', '/api.php?format=json&action=delete&list=wkvoteart&wkpage=' + wgArticleId, ratings.retry, null );
return;
};
try {
with( j.item.wkvoteart[0] == undefined ? j.item.wkvoteart : j.item.wkvoteart[0] ) {
ratings.hasVoted = true;
ratings.myVote = vote;
ratings.avgVote = Math.round( avgvote * 10 ) / 10.0;
if( ratings.avgVote > 5 ) {
ratings.avgVote = 5;
}
}
} catch( e ) {
ratings.out( 'Błąd: ' + e );
ratings.votingInProgress = false;
return;
}
ratings.votingInProgress = false;
ratings.out( 'Dziękujemy za głos. :)' );
ratings.text[0] = ( 'Średnia ocena: ' + ratings.avgVote );
ratings.timeout = setTimeout( 'ratings.paint(0)', 1800 );
},
failure : function( o ) {
ratings.votingInProgress = false;
ratings.out( 'Nie mogę się połączyć z serwerem. :(' );
}
};
ratings.retry = {
success : function( o ) {
ratings.get = YAHOO.util.Connect.asyncRequest( 'GET', '/api.php?format=json&action=insert&list=wkvoteart&wkuservote=1&wkctime=5&wkpage=' + wgArticleId + '&wkvote=' + ratings.myVote, ratings.voteCallback, null );
},
failure : function( o ) {
ratings.out( 'Bardzo poważny błąd.' );
}
};
ratings.out = function( m ) {
document.getElementById( 'ratingMsg' ).innerHTML = m;
};
ratings.paint = function( n, m ) {
if( ratings.votingInProgress == true ) {
return;
}
YAHOO.util.Dom.setStyle( ['vote-1', 'vote-2', 'vote-3', 'vote-4', 'vote-5'], 'backgroundPosition', '0 0' );
for( var l = 1; l <= n; l++ ) {
YAHOO.util.Dom.setStyle( 'vote-' + l, 'backgroundPosition', '0 -34px' );
}
if( n === 0 && ( ratings.myVote != false || ratings.avgVote != undefined ) ) {
var a = ratings.hasVoted == true ? '0 -34px' : '0 -17px';
var b = ratings.hasVoted != false ? ratings.myVote : ratings.avgVote;
for( var l = 1; l <= b; l++ ) {
YAHOO.util.Dom.setStyle( 'vote-' + l, 'backgroundPosition', a );
}
if( l - ratings.avgVote < 1 && l <= 5 && ratings.hasVoted != true ) {
var p = ratings.avgVote - ( l - 1 );
var q = 0;
switch( true ) {
case 0 < p && p <= .2 : q = '-51px';
break;
case.2 < p && p <= .4 : q = '-68px';
break;
case.4 < p && p <= .6 : q = '-85px';
break;
case.6 < p && p <= .8 : q = '-102px';
break;
case.8 < p && p < 1 : q = '-119px';
break;
default :
};
document.getElementById( 'vote-' + l ).style.backgroundPosition = '0px ' + q;
}
};
if( m == undefined ) {
ratings.out( ratings.text[n] );
} else {
ratings.out( m );
}
};
YAHOO.util.Event.onContentReady( 'column-one', ratings.setup );
/* </pre> */