MediaWiki:Common.js: различия между версиями
Материал из Абсурдопедии
Перейти к навигацииПерейти к поискум (эта ссылка не внутри ol) |
(баг в jQuery: выбор по id="", который содержит кодированные символы UTF8, не работал. Однако прямой getElementById работает) |
||
Строка 122: | Строка 122: | ||
var par = x.parent(), o = par.offset(), l = o.left, t = o.top+13 | var par = x.parent(), o = par.offset(), l = o.left, t = o.top+13 | ||
var b = $('body'), mh = b.height(), mw = b.width() | var b = $('body'), mh = b.height(), mw = b.width() | ||
− | var c=$(x.attr('href')).clone().find('a:first').remove().end().html() | + | var c=$(document.getElementById(x.attr('href').substr(1))).clone().find('a:first').remove().end().html() |
x.addClass('areference').addClass('curreference') | x.addClass('areference').addClass('curreference') |
Версия от 09:23, 8 июня 2012
/* <pre> */
/* Счётчик Рамблера */
$(function(){
var ramblerCnt = $('<img/>').attr('src', "http://counter.rambler.ru/top100.scn?2206359" +
"&rn=" + Math.round(Math.random() * 2147483647) +
(document.referrer ? "&rf=" + encodeURIComponent(document.referrer) : "") +
"&pt=" + encodeURIComponent(document.title.split(" — ")[0]) +
"&en=" + (document.characterSet || document.charset || "") +
"&fv=" +
"&ja=" + (navigator.javaEnabled() ? 1 : 0) +
"&cd=" + (screen ? screen.colorDepth + "-bit" : "") +
(screen ? "&sr=" + screen.width + "x" + screen.height : "") +
(navigator && navigator.language ? "&la=" + navigator.language : "") +
"&tz=" + (new Date).getTimezoneOffset());
var ramblerDiv = $('<div/>').attr('id', 'top100Counter').append($('<a/>').attr('href', 'http://top100.rambler.ru/').append(ramblerCnt));
$('#f-copyrightico').append(ramblerDiv);
});
/* Добавляет кнопки "поделиться в ЖЖ, Twitter, ВКонтакте и т.д." в шаблон {{пишите в блоги}} */
importScriptURI("http://yandex.st/share/share.js");
$(function(){
var box = $('#share_box')[0];
if(box) box.innerHTML = '<div class="yashare-auto-init" data-yashareL10n="ru" data-yashareType="none" data-yashareQuickServices="vkontakte,lj,twitter,odnoklassniki,moimir,yaru"></div>';
});
if(['edit', 'submit'].indexOf(mw.config.get('wgAction'))>=0)
mw.loader.load('ext.gadget.edit');
/* Обеспечиваем нигилистические фокусы (см., например, статью [[Google]]) */
$(function(){
var nhl = $('#nihilism')[0];
if(nhl && !document.location.href.match("diff"))
{
var msg = nhl.innerHTML;
$('body')[0].style.backgroundColor = 'white';
$('body').html("<div id='nihilism_message'" + (nhl.style.top == "0px" ? " style='top: 0px; left: 0px;'" : "") + ">" + msg + "</div>");
$(document).dblclick(function(){ window.location = 'http://absurdopedia.net/index.php?title=' + encodeURIComponent(wgPageName) + '&action=edit'; });
}
});
/* Обеспечиваем стирание памяти для «Людёй в чёрном» */
$(function(){
if($('#erase_memory')[0]) setTimeout("$('#erase_memory').hide()", 20000);
});
/* При добавлении нового ответа в Вопрос-ответе скрыть «Название темы» (создавало == заголовок второго уровня ==) */
if(wgTitle.match('^Вопрос-ответ') && window.location.search.match('Answer_edit'))
$(function(){
var sl = $('#wpSummaryLabel');
var s = $('#wpSummary');
if(sl[0]) sl.html(sl.html().replace('Краткое описание:', ''));
if(s[0]) s[0].style.display = "none";
});
/* + ссылка «править» для нулевой секции. */
$(function(){
var h2 = $('h2').not('#toctitle h2')[0];
if(!h2) return;
var n = $(h2).find('span.editsection');
if(!n[0]) return;
var zero = n.clone();
$('#bodyContent :first').before(zero);
var a = zero.find('a')[0];
if (a.href.indexOf('§ion=T') == -1 ) a.title = a.title.replace(/:.*$/,': 0');
else a.title = 'Править секцию: 0';
a.setAttribute('href', wgScript + '?title='+encodeURIComponent(wgPageName) + '&action=edit§ion=0');
});
/* Вставка юзернейма с помощью <span class="insertusername"></span> */
$(function(){
if((typeof(disableUsernameReplace) == 'undefined' || !disableUsernameReplace) && wgUserName != null)
$('span.insertusername').html(wgUserName);
});
/* {{nologo}} */
$(function() { if(document.getElementById('nologo')) document.getElementById('p-logo').style.display = 'none'; });
/* Разворачивание и сворачивание абзацев --Edward */
$(function() {
var s = $('#colpar-switch')[0];
if(s) s.onload = function() { $('#colpar').toggle(); };
});
/* Скрыть (и отметить как скрытый в будущем при помощи куки)
блок с id="hidefun" по нажатию на [[Файл:Closewindow.png]] внутри него
*/
$(function() {
fun = $('#hidefun');
if(!fun.length) return;
if(document.cookie.match('hidefun=1') || (wgUserName == null && (wgSearchNamespaces.indexOf(wgNamespaceNumber) == -1 || wgIsArticle == false || wgTitle == "Заглавная страница")))
fun.hide();
else {
$('img[alt="Closewindow.png"]')[0].onclick = function() {
var d = new Date();
d.setMonth( d.getMonth() + 1 );
document.cookie = "hidefun=1; expires=" + d.toGMTString();
$('#hidefun').hide();
}
}
});
/** Ref tooltips******************************************
*
* Description: Replace references with JQuery-based tooltips
* Made by: Tachikoma
*/
$(function() {
if(!($('ol.references').size())) return;
$('ol.references').before($('<a ' + 'href="#" id="showrefs">[показать примечания]</a>').click(function(e){e.preventDefault(); $('#showrefs').html( ($('ol.references').toggle().css('display') == 'none') ? "[показать примечания]" : "[скрыть примечания]" )})).hide()
$('.reference a').click(function(e) {
e.preventDefault();
var x = $('a[href*="' + this.hash + '"]'), iscurrent = x.hasClass('curreference'), i = $('.tooltip').hide(250)
$('.curreference').removeClass('curreference');
if (iscurrent) return;
var par = x.parent(), o = par.offset(), l = o.left, t = o.top+13
var b = $('body'), mh = b.height(), mw = b.width()
var c=$(document.getElementById(x.attr('href').substr(1))).clone().find('a:first').remove().end().html()
x.addClass('areference').addClass('curreference')
if (!i.size()) i = $('<div/>').addClass('tooltip')
i.appendTo(b).queue(function() {
i.empty().append(c).css({ 'left': l-((l+i.width() >= mw) && i.width()), 'top': t-((t+i.height() >= mh) && (i.height()+26)) }).dequeue()
}).show(250)
})
$(window).click(function(e) {
if (!($(e.target).hasClass('areference') || $(e.target).parents().andSelf().hasClass('tooltip'))) {
$('.tooltip').hide(250); $('.curreference').removeClass('curreference')
}
})
})
/** /Ref tooltips****************************************/
/* </pre> */