MediaWiki:Common.js — различия между версиями
Материал из ANT-Inform documentation
Hubbitus (обсуждение | вклад) (GA code should work) |
Hubbitus (обсуждение | вклад) (Copy of http://wiki.ru.grepolis.com/wiki/MediaWiki:Common.js to allow work Шаблон:спойлер) |
||
Строка 15: | Строка 15: | ||
*/ | */ | ||
+ | /* Statistics */ | ||
var _gaq = _gaq || []; | var _gaq = _gaq || []; | ||
_gaq.push(['_setAccount', 'UA-38366739-1']); | _gaq.push(['_setAccount', 'UA-38366739-1']); | ||
Строка 24: | Строка 25: | ||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | ||
})(); | })(); | ||
+ | |||
+ | /* | ||
+ | Copy of http://wiki.ru.grepolis.com/wiki/MediaWiki:Common.js to allow work Шаблон:спойлер | ||
+ | */ | ||
+ | if(wgAction == 'view' || wgAction == 'submit') { | ||
+ | importScript('MediaWiki:Collapsebuttons.js'); | ||
+ | } | ||
+ | if(wgAction == 'edit' || wgAction == 'submit') { | ||
+ | importScript('MediaWiki:Editpage.js'); | ||
+ | } | ||
+ | |||
+ | 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,'_'))) | ||
+ | } | ||
+ | } | ||
+ | importMW = function (name) { importScript('MediaWiki:'+name+'.js') } | ||
+ | |||
+ | function LinkFA(){ | ||
+ | var pLang = document.getElementById('p-lang') | ||
+ | if (!pLang) return | ||
+ | var list = { | ||
+ | 'fa':'Эта статья является избранной', | ||
+ | 'fl':'Этот список или портал является избранным', | ||
+ | 'ga':'Эта статья является хорошей'} | ||
+ | var iw = pLang.getElementsByTagName('li') | ||
+ | for (var i=0; i<iw.length; i++) | ||
+ | for (var s in list) | ||
+ | if (document.getElementById(iw[i].className+'-'+s)){ | ||
+ | iw[i].className += ' ' + s.toUpperCase() | ||
+ | iw[i].title = list[s] + ' в другом языковом разделе' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | // iwiki sorting | ||
+ | if (!wgUserName | ||
+ | || (wgUserName | ||
+ | && (((typeof wgLangPrefs == 'undefined') ? false : true) | ||
+ | || ((typeof wgAddLangHints == 'undefined') ? false : wgAddLangHints) | ||
+ | || ((typeof wgUseUserLanguage == 'undefined') ? false : wgUseUserLanguage)))) | ||
+ | importMW('Interwiki-links'); | ||
+ | |||
+ | var withJS = document.URL.match(/[&?]withjs=((mediawiki:)?([^&#]+))/i) | ||
+ | if (withJS) importScript_('MediaWiki:'+withJS[3]) | ||
+ | |||
+ | if (!window.wgUserName) appendCSS('#mw-fr-revisiontag {display:none}') | ||
+ | |||
+ | function addWikifButton() { | ||
+ | var toolbar = document.getElementById('toolbar') | ||
+ | if (!toolbar) return | ||
+ | var i = document.createElement('img') | ||
+ | i.src = 'http://upload.wikimedia.org/wikisource/ru/d/d1/Button-wikifikator.png' | ||
+ | i.alt = i.title = 'викификатор' | ||
+ | i.onclick = Wikify | ||
+ | i.style.cursor = 'pointer' | ||
+ | toolbar.appendChild(i) | ||
+ | } | ||
+ | if (document.URL.indexOf('action=edit') > 0 || document.URL.indexOf('action=submit') > 0) { | ||
+ | document.write('<script type="text/javascript" src="http://ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript"><\/script>') | ||
+ | addOnloadHook(addWikifButton) | ||
+ | } | ||
+ | |||
+ | //////////////////////////////////////////////////////////////// | ||
+ | // =-=-=- HELPER FUNCTIONS -=-=-=- | ||
+ | function addlilink(tabs, url, name, id, title, key){ | ||
+ | var na = document.createElement('a'); | ||
+ | na.href = url; | ||
+ | na.appendChild(document.createTextNode(name)); | ||
+ | var li = document.createElement('li'); | ||
+ | if(id) li.id = id; | ||
+ | li.appendChild(na); | ||
+ | tabs.appendChild(li); | ||
+ | if(id) | ||
+ | { | ||
+ | if(key && title) | ||
+ | { | ||
+ | ta[id] = [key, title]; | ||
+ | } | ||
+ | else if(key) | ||
+ | { | ||
+ | ta[id] = [key, '']; | ||
+ | } | ||
+ | else if(title) | ||
+ | { | ||
+ | ta[id] = ['', title]; | ||
+ | } | ||
+ | } | ||
+ | // re-render the title and accesskeys from existing code in wikibits.js | ||
+ | akeytt(); | ||
+ | return li; | ||
+ | } | ||
+ | |||
+ | function addToolboxLink(url, name, id, title){ | ||
+ | var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; | ||
+ | addlilink(tb, url, name, id, title); | ||
+ | } | ||
+ | |||
+ | function addTab(url, name, id, title, key) { | ||
+ | return addPortletLink('p-cactions', url, name, id, title, key); | ||
+ | } | ||
+ | |||
+ | function addLink(where, url, name, id, title, key, after){ | ||
+ | var na = document.createElement('a'); | ||
+ | na.href = url; | ||
+ | na.appendChild(document.createTextNode(name)); | ||
+ | var li = document.createElement('li'); | ||
+ | if(id) li.id = id; | ||
+ | li.appendChild(na); | ||
+ | var tabs = document.getElementById(where).getElementsByTagName('ul')[0]; | ||
+ | if(after) { | ||
+ | tabs.insertBefore(li,document.getElementById(after)); | ||
+ | } else { | ||
+ | tabs.appendChild(li); | ||
+ | } | ||
+ | if(id) { | ||
+ | if(key && title) { ta[id] = [key, title]; } | ||
+ | else if(key) { ta[id] = [key, '']; } | ||
+ | else if(title) { ta[id] = ['', title];} | ||
+ | } | ||
+ | // re-render the title and accesskeys from existing code in wikibits.js | ||
+ | akeytt(); | ||
+ | return li; | ||
+ | } | ||
+ | |||
+ | function addlimenu(tabs, name, id) | ||
+ | { | ||
+ | var na = document.createElement('a'); | ||
+ | na.href = '#'; | ||
+ | var mn = document.createElement('ul'); | ||
+ | na.appendChild(document.createTextNode(name)); | ||
+ | var li = document.createElement('li'); | ||
+ | li.id = id; | ||
+ | li.className = 'tabmenu'; | ||
+ | li.appendChild(na); | ||
+ | li.appendChild(mn); | ||
+ | tabs.appendChild(li); | ||
+ | return li; | ||
+ | } | ||
+ | |||
+ | function addnavbox_link(URL,Name,ID) | ||
+ | { | ||
+ | var portlet = document.getElementById('p-navigation'); | ||
+ | var links = portlet.getElementsByTagName('ul')[0]; | ||
+ | links.innerHTML += '<li id="' + ID + '"><a href="' + URL + '">' + Name + '</a></li>'; | ||
+ | } | ||
+ | document.write("<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js' type='text/javascript'></script>"); | ||
+ | |||
+ | document.write("<script src='/index.php?title=Global.js&action=raw&smaxage=0&ctype=text/javascript' type='text/javascript'></script>"); | ||
+ | |||
+ | var Engine = (function(){ | ||
+ | return { | ||
+ | init: function(){ | ||
+ | console.log('hello world'); | ||
+ | } | ||
+ | } | ||
+ | })(); | ||
+ | |||
+ | //Попытка реализовать гибкую навигацию | ||
+ | $(function() { | ||
+ | $('.jnav').each(function(i,e) { | ||
+ | $(this).data('i', i+1).click(function() { | ||
+ | var $this = $(this), | ||
+ | $jnavb = $('#jnavb-' + $this.data('i')); | ||
+ | if( $this.hasClass('jnav-inactive') ) { | ||
+ | $('.jnav-active').removeClass('jnav-active').addClass('jnav-inactive'); | ||
+ | $('.jnavb').slideUp(250); | ||
+ | $this.removeClass('jnav-inactive').addClass('jnav-active'); | ||
+ | $jnavb.slideDown(300); | ||
+ | } else { | ||
+ | $this.removeClass('jnav-active').addClass('jnav-inactive'); | ||
+ | $jnavb.slideUp(300); | ||
+ | } | ||
+ | return false; | ||
+ | }); | ||
+ | }); | ||
+ | |||
+ | if($('.jnavpm').width() > 0) | ||
+ | { | ||
+ | $('.jnavpm').each(function(i,e) { | ||
+ | $(this).data('i', i+1).click(function() { | ||
+ | var $this = $(this), $jnavb = $('#jnavb-' + $this.data('i')); | ||
+ | if( $this.hasClass('jnavpm-inactive') ) { | ||
+ | $('.jnavpm-active').removeClass('jnavpm-active').addClass('jnavpm-inactive'); | ||
+ | $('.jnavb').slideUp(250); | ||
+ | $this.removeClass('jnavpm-inactive').addClass('jnavpm-active'); | ||
+ | $jnavb.slideDown(300); | ||
+ | } else { | ||
+ | $this.removeClass('jnavpm-active').addClass('jnavpm-inactive'); | ||
+ | $jnavb.slideUp(300); | ||
+ | } | ||
+ | return false; | ||
+ | }); | ||
+ | }); | ||
+ | } | ||
+ | }); |
Версия 12:14, 23 декабря 2014
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */ /* http://en.wikipedia.org/wiki/User:Js/ajaxPreview importScript('User:Js/ajaxPreview.js'); // [[user:js/ajaxPreview]] */ /* http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/External_editor addOnloadHook(function() { var editTab = document.getElementById("ca-edit"); if (!editTab) return; var editURL = editTab.getElementsByTagName("a")[0].href; addPortletLink("p-cactions", editURL + "&externaledit=true", "EE", "ca-exted", "External editor", ""); }); */ /* Statistics */ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-38366739-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); /* Copy of http://wiki.ru.grepolis.com/wiki/MediaWiki:Common.js to allow work Шаблон:спойлер */ if(wgAction == 'view' || wgAction == 'submit') { importScript('MediaWiki:Collapsebuttons.js'); } if(wgAction == 'edit' || wgAction == 'submit') { importScript('MediaWiki:Editpage.js'); } 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,'_'))) } } importMW = function (name) { importScript('MediaWiki:'+name+'.js') } function LinkFA(){ var pLang = document.getElementById('p-lang') if (!pLang) return var list = { 'fa':'Эта статья является избранной', 'fl':'Этот список или портал является избранным', 'ga':'Эта статья является хорошей'} var iw = pLang.getElementsByTagName('li') for (var i=0; i<iw.length; i++) for (var s in list) if (document.getElementById(iw[i].className+'-'+s)){ iw[i].className += ' ' + s.toUpperCase() iw[i].title = list[s] + ' в другом языковом разделе' } } // iwiki sorting if (!wgUserName || (wgUserName && (((typeof wgLangPrefs == 'undefined') ? false : true) || ((typeof wgAddLangHints == 'undefined') ? false : wgAddLangHints) || ((typeof wgUseUserLanguage == 'undefined') ? false : wgUseUserLanguage)))) importMW('Interwiki-links'); var withJS = document.URL.match(/[&?]withjs=((mediawiki:)?([^&#]+))/i) if (withJS) importScript_('MediaWiki:'+withJS[3]) if (!window.wgUserName) appendCSS('#mw-fr-revisiontag {display:none}') function addWikifButton() { var toolbar = document.getElementById('toolbar') if (!toolbar) return var i = document.createElement('img') i.src = 'http://upload.wikimedia.org/wikisource/ru/d/d1/Button-wikifikator.png' i.alt = i.title = 'викификатор' i.onclick = Wikify i.style.cursor = 'pointer' toolbar.appendChild(i) } if (document.URL.indexOf('action=edit') > 0 || document.URL.indexOf('action=submit') > 0) { document.write('<script type="text/javascript" src="http://ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript"><\/script>') addOnloadHook(addWikifButton) } //////////////////////////////////////////////////////////////// // =-=-=- HELPER FUNCTIONS -=-=-=- function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title]; } } // re-render the title and accesskeys from existing code in wikibits.js akeytt(); return li; } function addToolboxLink(url, name, id, title){ var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; addlilink(tb, url, name, id, title); } function addTab(url, name, id, title, key) { return addPortletLink('p-cactions', url, name, id, title, key); } function addLink(where, url, name, id, title, key, after){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); var tabs = document.getElementById(where).getElementsByTagName('ul')[0]; if(after) { tabs.insertBefore(li,document.getElementById(after)); } else { tabs.appendChild(li); } if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title];} } // re-render the title and accesskeys from existing code in wikibits.js akeytt(); return li; } function addlimenu(tabs, name, id) { var na = document.createElement('a'); na.href = '#'; var mn = document.createElement('ul'); na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.id = id; li.className = 'tabmenu'; li.appendChild(na); li.appendChild(mn); tabs.appendChild(li); return li; } function addnavbox_link(URL,Name,ID) { var portlet = document.getElementById('p-navigation'); var links = portlet.getElementsByTagName('ul')[0]; links.innerHTML += '<li id="' + ID + '"><a href="' + URL + '">' + Name + '</a></li>'; } document.write("<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js' type='text/javascript'></script>"); document.write("<script src='/index.php?title=Global.js&action=raw&smaxage=0&ctype=text/javascript' type='text/javascript'></script>"); var Engine = (function(){ return { init: function(){ console.log('hello world'); } } })(); //Попытка реализовать гибкую навигацию $(function() { $('.jnav').each(function(i,e) { $(this).data('i', i+1).click(function() { var $this = $(this), $jnavb = $('#jnavb-' + $this.data('i')); if( $this.hasClass('jnav-inactive') ) { $('.jnav-active').removeClass('jnav-active').addClass('jnav-inactive'); $('.jnavb').slideUp(250); $this.removeClass('jnav-inactive').addClass('jnav-active'); $jnavb.slideDown(300); } else { $this.removeClass('jnav-active').addClass('jnav-inactive'); $jnavb.slideUp(300); } return false; }); }); if($('.jnavpm').width() > 0) { $('.jnavpm').each(function(i,e) { $(this).data('i', i+1).click(function() { var $this = $(this), $jnavb = $('#jnavb-' + $this.data('i')); if( $this.hasClass('jnavpm-inactive') ) { $('.jnavpm-active').removeClass('jnavpm-active').addClass('jnavpm-inactive'); $('.jnavb').slideUp(250); $this.removeClass('jnavpm-inactive').addClass('jnavpm-active'); $jnavb.slideDown(300); } else { $this.removeClass('jnavpm-active').addClass('jnavpm-inactive'); $jnavb.slideUp(300); } return false; }); }); } });