Все мы знаем, какой пиздец сейчас происходит с Украиной и одной известной вам страной-победительницей-фашизма. Если вы хотите почитать об этом, помочь актуализировать информацию или высказать свое мнение — можете сделать это в статье Война в Украине и в обсуждении.
MediaWiki:Common.js — различия между версиями
Материал из Urbanculture
Анонимус (lintify) |
|||
Строка 7: | Строка 7: | ||
var _is_editpage = wgAction == 'edit' || wgAction == 'submit'; | var _is_editpage = wgAction == 'edit' || wgAction == 'submit'; | ||
var _is_editable = (function isEditable() { | var _is_editable = (function isEditable() { | ||
− | var restrict = (typeof wgRestrictionEdit !== 'undefined'?wgRestrictionEdit:[]); | + | var restrict = (typeof wgRestrictionEdit !== 'undefined'?wgRestrictionEdit:[]), g; |
− | if (restrict.length < 1) return true; | + | if (restrict.length < 1) {return true;} |
− | if (!wgUserGroups) return false; | + | if (!wgUserGroups) {return false;} |
− | for( | + | for( g=0; g<wgUserGroups.length; g++) {if ($.inArray(wgUserGroups[g], restrict)!=-1) {return true;}} |
return false; | return false; | ||
− | } | + | }()); |
− | var _is_autoconfirmed = wgUserGroups && ($.inArray('autoconfirmed', wgUserGroups) != -1) | + | var _is_autoconfirmed = wgUserGroups && ($.inArray('autoconfirmed', wgUserGroups) != -1), |
− | + | f5s=('localStorage' in window) && window.localStorage!==null ? window.localStorage : false, | |
+ | Queue | ||
+ | ; | ||
/** /Misc common defines ****/ | /** /Misc common defines ****/ | ||
Строка 35: | Строка 37: | ||
/* Authors: [[User:Anotubus]], [[User:Obvious]] */ | /* Authors: [[User:Anotubus]], [[User:Obvious]] */ | ||
Queue.addOnce('UC.edittools', 'tabbedEditTools', ( | Queue.addOnce('UC.edittools', 'tabbedEditTools', ( | ||
− | !wgCanonicalSpecialPageName && | + | (!wgCanonicalSpecialPageName && |
( | ( | ||
location.href.match(/&action=(?:edit|submit)/) !== null || | location.href.match(/&action=(?:edit|submit)/) !== null || | ||
wgAction == 'edit' || | wgAction == 'edit' || | ||
wgAction == 'submit' | wgAction == 'submit' | ||
− | ) || | + | )) || |
wgPageName.match(/mediawiki:(?:edittools|topedittools)/i) !== null || | wgPageName.match(/mediawiki:(?:edittools|topedittools)/i) !== null || | ||
wgCanonicalNamespace.match(/talk$/i) !== null | wgCanonicalNamespace.match(/talk$/i) !== null | ||
) ); | ) ); | ||
Queue.addOnce('UC.edittools', 'fileInsert', ( | Queue.addOnce('UC.edittools', 'fileInsert', ( | ||
− | !wgCanonicalSpecialPageName && | + | (!wgCanonicalSpecialPageName && |
( | ( | ||
location.href.match(/&action=(?:edit|submit)/) !== null || | location.href.match(/&action=(?:edit|submit)/) !== null || | ||
wgAction == 'edit' || | wgAction == 'edit' || | ||
wgAction == 'submit' | wgAction == 'submit' | ||
− | ) || | + | )) || |
wgPageName.match(/mediawiki:(?:edittools|topedittools)/i) !== null || | wgPageName.match(/mediawiki:(?:edittools|topedittools)/i) !== null || | ||
wgCanonicalNamespace.match(/talk$/i) !== null | wgCanonicalNamespace.match(/talk$/i) !== null | ||
Строка 85: | Строка 87: | ||
$(window).click(function(e) { | $(window).click(function(e) { | ||
if (!($(e.target).hasClass('areference') || $(e.target).parents().andSelf().hasClass('tooltip'))) { | if (!($(e.target).hasClass('areference') || $(e.target).parents().andSelf().hasClass('tooltip'))) { | ||
− | $('.tooltip').hide(250); $('.curreference').removeClass('curreference') | + | $('.tooltip').hide(250); $('.curreference').removeClass('curreference'); |
} | } | ||
− | }) | + | }); |
}, !wgCanonicalSpecialPageName).addEachFragment(function(scope) { | }, !wgCanonicalSpecialPageName).addEachFragment(function(scope) { | ||
− | var refs = $('ol.references', scope) | + | var refs = $('ol.references', scope); |
− | if (!refs.size()) return; | + | if (!refs.size()) { return; } |
− | refs.before($('<a href="#">[показать примечания]</a>').click(function(e) { e.preventDefault(); refs.toggle() } )).hide() | + | refs.before($('<a href="#">[показать примечания]</a>').click(function(e) { e.preventDefault(); refs.toggle(); } )).hide(); |
$('.reference a', scope).click(function(e) { | $('.reference a', scope).click(function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
− | var x = $(this), iscurrent = x.hasClass('curreference'), i = $('.tooltip').hide(250) | + | var x = $(this), iscurrent = x.hasClass('curreference'), i = $('.tooltip').hide(250), |
+ | par = x.parent(), o = par.offset(), l = o.left, t = o.top+13, | ||
+ | b = $('body'), mh = b.height(), mw = b.width(), | ||
+ | c=$(x.attr('href'), refs).clone().find('a:first').remove().end().html(); | ||
$('.curreference').removeClass('curreference'); | $('.curreference').removeClass('curreference'); | ||
− | if (iscurrent) return; | + | if (iscurrent) { return; } |
− | + | x.addClass('areference').addClass('curreference'); | |
− | + | if (!i.size()) { i = $('<div/>').addClass('tooltip');} | |
− | + | ||
− | + | ||
− | x.addClass('areference').addClass('curreference') | + | |
− | if (!i.size()) i = $('<div/>').addClass('tooltip') | + | |
i.appendTo(b).queue(function() { | 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() | + | 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) | + | }).show(250); |
− | }) | + | }); |
− | }, !wgCanonicalSpecialPageName) | + | }, !wgCanonicalSpecialPageName); |
/** Linkchecker ***/ | /** Linkchecker ***/ | ||
function linkchecker(scope) { | function linkchecker(scope) { | ||
$('.linkchecker', scope).each(function(i, e) { | $('.linkchecker', scope).each(function(i, e) { | ||
− | var lc_if = $(".linkcheckerif a", this) | + | var lc_if = $(".linkcheckerif a", this), |
− | + | lc_then = $(".linkcheckerthen", this), | |
− | + | lc_else = $(".linkcheckerelse", this) | |
+ | ; | ||
if (lc_if.size() && lc_then.size()) { | if (lc_if.size() && lc_then.size()) { | ||
− | if (lc_if.hasClass('new')) lc_then.hide(); else lc_else.hide(); | + | if (lc_if.hasClass('new')) { lc_then.hide(); } else { lc_else.hide(); } |
− | lc_if.parent().hide() | + | lc_if.parent().hide(); |
− | } else $(this).hide() | + | } else { $(this).hide(); } |
− | }) | + | }); |
− | } | + | } |
Queue.addEachFragment(linkchecker, !wgCanonicalSpecialPageName); | Queue.addEachFragment(linkchecker, !wgCanonicalSpecialPageName); | ||
Строка 130: | Строка 132: | ||
$("#ca-history").after('<li><a href="'+location.href.replace(/^(.+\?).*&?(diff=(?:\d+|prev|next|curr)).*?(&oldid=\d+)?.*$/,"$1$2$3")+'" title="Короткая ссылка на дифф">url</a></li>'); | $("#ca-history").after('<li><a href="'+location.href.replace(/^(.+\?).*&?(diff=(?:\d+|prev|next|curr)).*?(&oldid=\d+)?.*$/,"$1$2$3")+'" title="Короткая ссылка на дифф">url</a></li>'); | ||
} | } | ||
− | } | + | } |
− | Queue.addOnce(shortdiffurl, !wgCanonicalSpecialPageName && location.href.indexOf("diff=") != -1) | + | Queue.addOnce(shortdiffurl, !wgCanonicalSpecialPageName && location.href.indexOf("diff=") != -1); |
Строка 138: | Строка 140: | ||
$('.mw-redirect').addClass('neededpagerdrcts'); | $('.mw-redirect').addClass('neededpagerdrcts'); | ||
$('ul').addClass('neededpagelist'); | $('ul').addClass('neededpagelist'); | ||
− | }, !wgCanonicalSpecialPageName && wgPageName == 'Urbanculture:R') | + | }, !wgCanonicalSpecialPageName && wgPageName == 'Urbanculture:R'); |
/** Wikificator ************************************* */ | /** Wikificator ************************************* */ | ||
Строка 147: | Строка 149: | ||
} | } | ||
− | Queue.addOnce( 'UC.wikificator', wikification, !wgCanonicalSpecialPageName && wgAction == "edit" || wgAction == "submit" || wgPageName == "Special:Upload"); | + | Queue.addOnce( 'UC.wikificator', wikification, (!wgCanonicalSpecialPageName && wgAction == "edit") || wgAction == "submit" || wgPageName == "Special:Upload"); |
Строка 167: | Строка 169: | ||
Queue.addOnce(function() { | Queue.addOnce(function() { | ||
$('#bodySearch').submit(function(e) { | $('#bodySearch').submit(function(e) { | ||
− | var wrap = $(this).children(".bodySearchWrap") | + | var wrap = $(this).children(".bodySearchWrap"); |
if(/^\s*$/.test(wrap.children('#bodySearchInput').val())) { | if(/^\s*$/.test(wrap.children('#bodySearchInput').val())) { | ||
if(wrap.children('.pagenameneeded').size() == 0) { | if(wrap.children('.pagenameneeded').size() == 0) { | ||
Строка 202: | Строка 204: | ||
/*** Resize textarea ***/ | /*** Resize textarea ***/ | ||
− | Queue.addOnce('UC.autosizetextarea','autoSizeTextArea') | + | Queue.addOnce('UC.autosizetextarea','autoSizeTextArea'); |
Строка 237: | Строка 239: | ||
$("#create-page-lay .createboxInput").focusout(function () { | $("#create-page-lay .createboxInput").focusout(function () { | ||
if ($(this).val() == "") { | if ($(this).val() == "") { | ||
− | $('#create-page-lay').hide() | + | $('#create-page-lay').hide(); |
− | $('#write-article a').fadeIn() | + | $('#write-article a').fadeIn(); |
} | } | ||
}); | }); | ||
Строка 264: | Строка 266: | ||
var portlet = $(this); | var portlet = $(this); | ||
$('#portlet-bg').fadeIn('slow'); | $('#portlet-bg').fadeIn('slow'); | ||
− | portlet.parent().addClass('visible') | + | portlet.parent().addClass('visible'); |
}); | }); | ||
$('#close-portlet').click(function() { | $('#close-portlet').click(function() { | ||
$(this).parent().fadeOut('slow'); | $(this).parent().fadeOut('slow'); | ||
− | $('.portlet').removeClass('visible') | + | $('.portlet').removeClass('visible'); |
}); | }); | ||
} | } |
Версия 13:37, 23 октября 2012
/** Misc common defines ****/ /* Неоднократно нужные проверки: */ /*** _is_editpage - я на странице редактирования? */ /*** _is_editable - у меня есть права на правку текущей страницы? */ /*** _is_autoconfirmed */ var _is_editpage = wgAction == 'edit' || wgAction == 'submit'; var _is_editable = (function isEditable() { var restrict = (typeof wgRestrictionEdit !== 'undefined'?wgRestrictionEdit:[]), g; if (restrict.length < 1) {return true;} if (!wgUserGroups) {return false;} for( g=0; g<wgUserGroups.length; g++) {if ($.inArray(wgUserGroups[g], restrict)!=-1) {return true;}} return false; }()); var _is_autoconfirmed = wgUserGroups && ($.inArray('autoconfirmed', wgUserGroups) != -1), f5s=('localStorage' in window) && window.localStorage!==null ? window.localStorage : false, Queue ; /** /Misc common defines ****/ /** Processing queue ****/ /**** Queue.addOnce(function(){}, condition = true) - adds a function to run once on page load */ /**** Queue.addOnce('module.name', [function(){} | function name string string], condition = true) - loads a module and adds a function to run once on page load */ /**** Queue.addEachFragment(function(scope){}, condtion = true) - adds function to run on page load AND on each AJAX loaded fragment */ /**** Queue.addEachFragment('module.name', [function(scope){} | function name string string], condtion = true) - loads a module and adds function to run on page load AND on each AJAX loaded fragment */ /**** Function must take a single parameter - currently processed fragment */ /**** Both functions take optional second parameter - if false, function won't be run on current page */ /**** Queue.runOnce - self-descriptive, shouldn't be run directly */ /**** Queue.runEachFragment(scope) - scope can be an html element or array of elements */ mw.loader.using('UC.queue', function() { /** Edittools ****/ /* Authors: [[User:Anotubus]], [[User:Obvious]] */ Queue.addOnce('UC.edittools', 'tabbedEditTools', ( (!wgCanonicalSpecialPageName && ( location.href.match(/&action=(?:edit|submit)/) !== null || wgAction == 'edit' || wgAction == 'submit' )) || wgPageName.match(/mediawiki:(?:edittools|topedittools)/i) !== null || wgCanonicalNamespace.match(/talk$/i) !== null ) ); Queue.addOnce('UC.edittools', 'fileInsert', ( (!wgCanonicalSpecialPageName && ( location.href.match(/&action=(?:edit|submit)/) !== null || wgAction == 'edit' || wgAction == 'submit' )) || wgPageName.match(/mediawiki:(?:edittools|topedittools)/i) !== null || wgCanonicalNamespace.match(/talk$/i) !== null ) ); /** Collapsible tables ****/ // Используется в коллапсерах Queue.addEachFragment( 'UC.tablecollapsers','createTableCollapsers', !wgCanonicalSpecialPageName ); Queue.addEachFragment( 'UC.tablecollapsers','createHiderButtons', !wgCanonicalSpecialPageName ); /** NSFW Gallery Items ****/ /* Description: Hides images with |NSFW in description from galleries */ /* Authors: [[User:Anotubus]], [[User:Obvious]] */ Queue.addEachFragment('UC.gallerymodify','processNSFWGalleryItems', !wgCanonicalSpecialPageName); /** Dynamic gallery ****/ Queue.addEachFragment('UC.gallerymodify','dynamicGallery', !wgCanonicalSpecialPageName); /** Ajaxed *****/ Queue.addEachFragment('UC.ajaxed', 'ajaxed', !wgCanonicalSpecialPageName); /** Morph LM Edition **************************************/ Queue.addEachFragment('UC.morphobjects','createMorphObjects', !wgCanonicalSpecialPageName); /** Ref tooltips****************************************** * * Description: Replace references with JQuery-based tooltips * Made by: Tachikoma */ Queue.addOnce(function() { $(window).click(function(e) { if (!($(e.target).hasClass('areference') || $(e.target).parents().andSelf().hasClass('tooltip'))) { $('.tooltip').hide(250); $('.curreference').removeClass('curreference'); } }); }, !wgCanonicalSpecialPageName).addEachFragment(function(scope) { var refs = $('ol.references', scope); if (!refs.size()) { return; } refs.before($('<a href="#">[показать примечания]</a>').click(function(e) { e.preventDefault(); refs.toggle(); } )).hide(); $('.reference a', scope).click(function(e) { e.preventDefault(); var x = $(this), iscurrent = x.hasClass('curreference'), i = $('.tooltip').hide(250), par = x.parent(), o = par.offset(), l = o.left, t = o.top+13, b = $('body'), mh = b.height(), mw = b.width(), c=$(x.attr('href'), refs).clone().find('a:first').remove().end().html(); $('.curreference').removeClass('curreference'); if (iscurrent) { return; } 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); }); }, !wgCanonicalSpecialPageName); /** Linkchecker ***/ function linkchecker(scope) { $('.linkchecker', scope).each(function(i, e) { var lc_if = $(".linkcheckerif a", this), lc_then = $(".linkcheckerthen", this), lc_else = $(".linkcheckerelse", this) ; if (lc_if.size() && lc_then.size()) { if (lc_if.hasClass('new')) { lc_then.hide(); } else { lc_else.hide(); } lc_if.parent().hide(); } else { $(this).hide(); } }); } Queue.addEachFragment(linkchecker, !wgCanonicalSpecialPageName); /** ShortDiffURL ****/ function shortdiffurl() { if ($("#ca-history").size() > 0 ){ $("#ca-history").after('<li><a href="'+location.href.replace(/^(.+\?).*&?(diff=(?:\d+|prev|next|curr)).*?(&oldid=\d+)?.*$/,"$1$2$3")+'" title="Короткая ссылка на дифф">url</a></li>'); } } Queue.addOnce(shortdiffurl, !wgCanonicalSpecialPageName && location.href.indexOf("diff=") != -1); /** Needed page **/ Queue.addOnce(function() { $('.mw-redirect').addClass('neededpagerdrcts'); $('ul').addClass('neededpagelist'); }, !wgCanonicalSpecialPageName && wgPageName == 'Urbanculture:R'); /** Wikificator ************************************* */ function wikification() { $('<button id="Wikifybutton" onclick="Wikify();" type="button">Викифицировать</button>').insertBefore($('#wpSave')); if(wgNamespaceNumber==-1 || wgNamespaceNumber==108) {$('#Wikifybutton').attr('disabled','disabled');} $('#editpage-copywarn').insertAfter('.editOptions'); } Queue.addOnce( 'UC.wikificator', wikification, (!wgCanonicalSpecialPageName && wgAction == "edit") || wgAction == "submit" || wgPageName == "Special:Upload"); /** Image Categorizer ************************************* */ /** Author: Anotubus */ /* if ( (wgCanonicalNamespace == 'File' || wgNamespaceNumber == 6) && _is_autoconfirmed && _is_editable ) importScriptURI("/skins/common/imgcat.js");*/ /** Section menus ****************************************** */ /* Authors: [[User:Tachikoma]], [[User:T_kns]], [[User:Мопец Ципельман]] */ Queue.addOnce('UC.sectionmenus','addSectionMenus', !wgCanonicalSpecialPageName && skin=='impetus'); /** collapsibledivs *****/ Queue.addOnce('UC.collapsiblesidebar','collapsibleSideBar', f5s && skin=='impetus'); /* empty pagename ****/ Queue.addOnce(function() { $('#bodySearch').submit(function(e) { var wrap = $(this).children(".bodySearchWrap"); if(/^\s*$/.test(wrap.children('#bodySearchInput').val())) { if(wrap.children('.pagenameneeded').size() == 0) { wrap.append($('<p class="pagenameneeded">Введите имя статьи</p>').delay(1500).fadeOut('slow',function() {$(this).remove();})); } return false; } }); }, !wgCanonicalSpecialPageName && wgPageName == "Urbanculture:Новая_статья"); /* b-yauser ****/ Queue.addEachFragment(function(sc) { $('.b-yauser a', sc).each(function(i) { $(this).html($(this).html().replace(/^([^<])/,'<b>$1</b>')); }); }); /* prettyPhoto ****/ Queue.addOnce( 'UC.prettyphotify', 'prettyPhotifyOptions', f5s && wgCanonicalSpecialPageName == 'Preferences' ); Queue.addEachFragment( 'UC.prettyphotify', 'prettyPhotify', f5s && localStorage.getItem('gallery_slideshow') != 'false' ); /* By ****/ Queue.addOnce(function() { $('body').addClass('ns-talk'); }, !wgCanonicalSpecialPageName && wgPageName == "Urbanculture:Вниманию_участников"); /* Spoilers ****/ Queue.addEachFragment(function(scope) { $('.spoiler',scope).click(function() { $(this).toggleClass('spoilered'); }); }, !wgCanonicalSpecialPageName ); /* new gallerytemplate ****/ //Queue.addEachFragment('UC.newgallerytemplate', 'newGalleryTemplate', !wgCanonicalSpecialPageName); /*** Resize textarea ***/ Queue.addOnce('UC.autosizetextarea','autoSizeTextArea'); }); /** /Processing queue ****/ /*** Scroll menu ***/ var scrollmenu = false; $(document).ready(function () { var windowWidth = $(window).width(); $(document).scroll(function () { if ((scrollmenu == false) && ($(window).scrollTop() > 112) && ($(window).height() > 700) && ($('#content').outerHeight() > 750) && (skin=='impetus')) { $(".editbox").css('position', 'fixed'); $(".editbox").css('top', '0'); scrollmenu = true; } else if ((scrollmenu == true) && ($(window).scrollTop() < 113)) { $(".editbox").css('position', 'absolute'); $(".editbox").css('top', ''); scrollmenu = false; } }); }); /*** /Scroll menu ***/ /*** Title page ***/ $('#write-article a').click(function () { $(this).hide(); $('#create-page-lay').fadeIn(); $('#create-page-lay .createboxInput').focus(); $("#create-page-lay .createboxInput").focusout(function () { if ($(this).val() == "") { $('#create-page-lay').hide(); $('#write-article a').fadeIn(); } }); return false; }); /*** Blog page ***/ $('div.news.old').first().before("<div id='oldnews'></div>"); $('div.news.old').appendTo($('#oldnews')); $('#oldnews').after("<div id='showarchive'><a id='show-link' href='#' class='showarchive'><span>Показать архив</span></a></div>"); $('#show-link').toggle(function () { $('#oldnews').fadeIn(); $(this).html('<span>Скрыть архив</span>') .stop(); }, function () { $('#oldnews').hide(); $(this).html('<span>Показать архив</span>') .stop(); }); /*** Mobile menu ***/ if (skin=='mobile') { $('.portlet h5').click(function() { var portlet = $(this); $('#portlet-bg').fadeIn('slow'); portlet.parent().addClass('visible'); }); $('#close-portlet').click(function() { $(this).parent().fadeOut('slow'); $('.portlet').removeClass('visible'); }); }