/* Viikon kilpailu script
* Maintainer: ]
* Alkuperäinen skripti: http://no.wikipedia.orghttps://wiki386.com/fi/MediaWiki:Ukens_konkurranse.js
* Scriptin toimintaa voi testata sivulla: ]
*
* if (/^Wikipedia:Ukens_konkurranse\/Ukens_konkurranse/.test(mw.config.get('wgPageName'))) {
* mw.loader.load(mw.config.get('wgServer') + mw.config.get('wgScript') + '?title= MediaWiki:Ukens_konkurranse.js&action=raw&ctype=text/javascript&maxage=21600&smaxage=86400');
* }
*/
/*jslint browser: true */
/*global mediaWiki, jQuery */
(function ($, mw) {
"use strict";
mw.loader.using(, function () {
// Increase tipsy max-width
mw.util.addCSS('.tipsy-inner { max-width: 65em; font-size:smaller; }');
$('.uk-ap').each(function () {
var me = this,
timer = null,
visible = false;
function leave() {
timer = setTimeout(function () {
$(me).tipsy('hide');
visible = false;
}, 200);
}
function enter() {
if (visible) {
clearTimeout(timer);
} else {
$(me).tipsy('show');
$('.tipsy').hover(enter, leave);
visible = true;
}
}
$(this).tipsy({
title: function () {
return $(me).next('.uk-ap-title').html();
},
html: true,
trigger: 'manual',
gravity: 'w'
});
$(this).hover(enter, leave);
});
$('.uk-ap-title').hide();
});
mw.loader.using(, function () {
mw.messages.set('ukens-konkurranse-login', 'Kirjaudu sisään ilmoittautuaksesi osallistujaksi');
mw.messages.set('ukens-konkurranse-join', 'Ilmoittaudu osallistujaksi');
mw.messages.set('ukens-konkurranse-joined', 'Olet ilmoittautunut!');
mw.messages.set('ukens-konkurranse-closed', 'Tämä kilpailu on loppunut.<br />Kiitos kaikille osallistujille!');
mw.messages.set('ukens-konkurranse-summary', 'Ilmoittautumassa...');
var paameldt = false,
h2 = $('#Osallistujat').parent(),
sectionId = -1,
userName = mw.user.getName(),
api = new mw.Api(),
endtime = parseInt($('.UK-end-ts').text(), 10),
now = new Date() / 1000;
function visPaameldt() {
h2.after('<div style="float:right; border:3px solid #008800; padding:15px 30px 15px 20px; margin:0 0 0.5em 0.5em; border-radius:10px; font-weight:bold; background: #BFFF00;"><div style="background: url(http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Dialog-apply.svg/16px-Dialog-apply.svg.png) left no-repeat; padding-left:20px;">' + mw.messages.get('ukens-konkurranse-joined') + '</div></div>');
}
if (h2.length === 1) {
sectionId = h2.prevAll('h2').length + 1;
if (now > endtime) {
h2.after('<div style="float:right; border:3px solid #DD5555; padding:15px 30px 15px 20px; margin:0 0 0.5em 0.5em; border-radius:10px; font-weight:bold; background: #F8F8F8;"><div style="background: url(http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Emblem-diamond.svg/16px-Emblem-diamond.svg.png) left no-repeat; padding-left:20px;">' + mw.messages.get('ukens-konkurranse-closed') + '</div></div>');
return;
}
if (userName === null) {
h2.after('<div style="float:right; border:3px solid #008800; padding:15px 30px 15px 20px; margin:0 0 0.5em 0.5em; border-radius:10px; font-weight:bold; background: #BFFF00;">' + mw.messages.get('ukens-konkurranse-login') + '</div>');
return;
}
// Onko joku ilmoittaunut?
if (h2.nextUntil('h2', 'ul').length !== 0) {
h2.nextUntil('h2', 'ul').find('a').each(function () {
if ($(this).attr('title').split(':') === userName) {
paameldt = true;
}
});
}
if (paameldt) {
visPaameldt();
} else {
h2.after('<div id="joindiv" style="float:right;"><span id="uk-status"></span><button id="joinbtn">' + mw.messages.get('ukens-konkurranse-join') + '</button></div>');
$(function () {
$('#joinbtn').button({ icons: { primary: 'ui-icon-plus-thick' } }).addClass('ui-button-orange');
$('#joinbtn').click(function () {
$('#joinbtn').button('option', 'disabled', true);
$('#uk-status').injectSpinner('uk-status-spinner');
api.post(
{
'action': 'edit',
'title': mw.config.get('wgPageName'),
'section': sectionId,
'appendtext': '\n* ]',
'token': mw.user.tokens.get('csrfToken'),
'summary': mw.messages.get('ukens-konkurranse-summary')
},
{
'ok': function () {
var ul = h2.nextUntil('h2', 'ul'),
li = '<li><a href="https://wiki386.com/fi/User:' + userName + '" title= ==="User:' + userName + ' 0 pistettä"===>' + userName + '</a></li>\n';
$.removeSpinner('uk-status-spinner');
paameldt = true;
$('#joindiv').remove();
if (ul.length === 0) {
h2.nextAll('h2').first().before('\n<ul>\n' + li + '</ul>');
} else {
ul.append(li);
}
visPaameldt();
},
'err': function (code) {
$.removeSpinner('uk-status-spinner');
$('#uk-status').append('Det oppstod en feil:' + code);
}
}
);
});
});
}
}
});
}(jQuery, mediaWiki));