MediaWiki:Common.js — различия между версиями
Материал из CelestePedia
SoulTrain (обсуждение | вклад) |
SoulTrain (обсуждение | вклад) |
||
Строка 1: | Строка 1: | ||
+ | //import scripts | ||
+ | importScript('MediaWiki:Editpage.js'); | ||
+ | importScript('MediaWiki:Collapsebuttons.js'); | ||
+ | importScript('User:X-romix/SciRefs.js'); | ||
+ | importScript('MediaWiki:Refstandard.js'); | ||
+ | |||
+ | addLoadEvent = addOnloadHook | ||
+ | importScript_ = importScript | ||
+ | |||
+ | |||
+ | // for backwards compatibility | ||
+ | var addLoadEvent = addOnloadHook; | ||
+ | var import_script = importScript; | ||
+ | var import_style = importStylesheet; | ||
+ | var importScript_ = importScript; | ||
+ | |||
+ | // | ||
+ | |||
+ | function addLoadEvent(func) | ||
+ | { | ||
+ | if (window.addEventListener) | ||
+ | window.addEventListener("load", func, false); | ||
+ | else if (window.attachEvent) | ||
+ | window.attachEvent("onload", func); | ||
+ | } | ||
+ | |||
+ | //Edit zero section | ||
+ | if (wgAction == 'view' && wgNamespaceNumber >=0) | ||
+ | addOnloadHook(function(){ | ||
+ | var h2s = document.getElementsByTagName('H2'); | ||
+ | var h2 = h2s[0]; | ||
+ | if (!h2) return; | ||
+ | if (h2.parentNode.id == 'toctitle') h2 = h2s[1]; | ||
+ | if (!h2) return; | ||
+ | var span = h2.firstChild; | ||
+ | if (!span || span.className != 'editsection') return; | ||
+ | var zero = span.cloneNode(true); | ||
+ | if (document.getElementById('featured-star')) zero.style.marginRight = '25px' | ||
+ | var parent = document.getElementsByTagName('H1')[0]; | ||
+ | parent.insertBefore(zero, parent.firstChild); | ||
+ | var a = zero.getElementsByTagName('A')[0]; | ||
+ | a.title = a.title.replace(/:.*$/,': 0'); | ||
+ | a.setAttribute('href', a.href.replace(/§ion=1/,'§ion=0')); | ||
+ | }) | ||
+ | |||
+ | // hasClass() | ||
+ | var hasClass = (function () { | ||
+ | var reCache = {}; | ||
+ | return function (element, className) { | ||
+ | return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); | ||
+ | }; | ||
+ | })(); | ||
+ | |||
+ | |||
+ | function sysopProtectPage(){ | ||
+ | var inp = document.getElementById('mwProtect-level-edit') | ||
+ | if (inp) addHandler(inp, 'change', noMoveAutoconfirmedProtection) | ||
+ | function noMoveAutoconfirmedProtection(){ | ||
+ | var inp = document.getElementById('mwProtectUnchained') | ||
+ | if (!inp || inp.checked) return | ||
+ | inp = document.getElementById('mwProtect-level-move') | ||
+ | if (inp && inp.selectedIndex==1) inp.selectedIndex = 0 | ||
+ | inp = document.getElementById('mwProtect-level-delete') | ||
+ | if (inp && inp.selectedIndex==1) inp.selectedIndex = 0 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | addOnloadHook(sysopProtectPage); | ||
+ | |||
+ | function newSectionLink(){ | ||
+ | var plus = document.getElementById('ca-addsection') | ||
+ | if (!plus) return | ||
+ | var custom = document.getElementById('add-custom-section') | ||
+ | if (!custom) return | ||
+ | plus.firstChild.setAttribute('href', custom.getElementsByTagName('a')[0].href) | ||
+ | } | ||
+ | |||
// подключение загрузчика карт "Google maps" | // подключение загрузчика карт "Google maps" | ||
var gm2wiki_language = "RU"; // RU/EN value correct only | var gm2wiki_language = "RU"; // RU/EN value correct only | ||
Строка 12: | Строка 89: | ||
importScriptURI('http://'+proj+'/w/index.php?action=raw&ctype=text/javascript&title='+encodeURIComponent(page.replace(/ /g,'_'))) | importScriptURI('http://'+proj+'/w/index.php?action=raw&ctype=text/javascript&title='+encodeURIComponent(page.replace(/ /g,'_'))) | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } |
Версия 19:02, 30 ноября 2010
//import scripts
importScript('MediaWiki:Editpage.js');
importScript('MediaWiki:Collapsebuttons.js');
importScript('User:X-romix/SciRefs.js');
importScript('MediaWiki:Refstandard.js');
addLoadEvent = addOnloadHook
importScript_ = importScript
// for backwards compatibility
var addLoadEvent = addOnloadHook;
var import_script = importScript;
var import_style = importStylesheet;
var importScript_ = importScript;
//
function addLoadEvent(func)
{
if (window.addEventListener)
window.addEventListener("load", func, false);
else if (window.attachEvent)
window.attachEvent("onload", func);
}
//Edit zero section
if (wgAction == 'view' && wgNamespaceNumber >=0)
addOnloadHook(function(){
var h2s = document.getElementsByTagName('H2');
var h2 = h2s[0];
if (!h2) return;
if (h2.parentNode.id == 'toctitle') h2 = h2s[1];
if (!h2) return;
var span = h2.firstChild;
if (!span || span.className != 'editsection') return;
var zero = span.cloneNode(true);
if (document.getElementById('featured-star')) zero.style.marginRight = '25px'
var parent = document.getElementsByTagName('H1')[0];
parent.insertBefore(zero, parent.firstChild);
var a = zero.getElementsByTagName('A')[0];
a.title = a.title.replace(/:.*$/,': 0');
a.setAttribute('href', a.href.replace(/§ion=1/,'§ion=0'));
})
// hasClass()
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
function sysopProtectPage(){
var inp = document.getElementById('mwProtect-level-edit')
if (inp) addHandler(inp, 'change', noMoveAutoconfirmedProtection)
function noMoveAutoconfirmedProtection(){
var inp = document.getElementById('mwProtectUnchained')
if (!inp || inp.checked) return
inp = document.getElementById('mwProtect-level-move')
if (inp && inp.selectedIndex==1) inp.selectedIndex = 0
inp = document.getElementById('mwProtect-level-delete')
if (inp && inp.selectedIndex==1) inp.selectedIndex = 0
}
}
addOnloadHook(sysopProtectPage);
function newSectionLink(){
var plus = document.getElementById('ca-addsection')
if (!plus) return
var custom = document.getElementById('add-custom-section')
if (!custom) return
plus.firstChild.setAttribute('href', custom.getElementsByTagName('a')[0].href)
}
// подключение загрузчика карт "Google maps"
var gm2wiki_language = "RU"; // RU/EN value correct only
document.write('<script type="text/javascript" src="http://ru.gm2.wikia.com/index.php?title=MediaWiki:GmapsLoader.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//See http://ru.wikipedia.org/wiki/project:code
importScript_ = importScript
importScript = function (page, proj){
if (!proj) importScript_(page)
else {
if (proj.indexOf('.')==-1) proj += '.wikipedia.org'
importScriptURI('http://'+proj+'/w/index.php?action=raw&ctype=text/javascript&title='+encodeURIComponent(page.replace(/ /g,'_')))
}
}