MediaWiki:Common.js
Зовнішній вигляд
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5.
//<source lang="javascript">
/**
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
* loaded for all users on every wiki page. If possible create a gadget that is
* enabled by default instead of adding it here (since gadgets are fully
* optimized ResourceLoader modules with possibility to add dependencies etc.)
*
* Since Common.js isn't a gadget, there is no place to declare its
* dependencies, so we have to lazy load them with mw.loader.using on demand and
* then execute the rest in the callback. In most cases these dependencies will
* be loaded (or loading) already and the callback will not be delayed. In case a
* dependency hasn't arrived yet it'll make sure those are loaded before this.
*/
/* global mw, $, importStylesheet, importScript */
/* jshint curly:false eqnull:true, strict:false, browser:true, */
mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'jquery.client'] ).done( function () {
/* Begin of mw.loader.using callback */
/**
* Scripts imported from en.wikisource.org and old wikisource.org
*/
mw.loader.load('//uk.wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript');
mw.loader.load('//uk.wikisource.org/w/index.php?title=MediaWiki:ManageBookCover.js&action=raw&ctype=text/javascript');
mw.loader.load('//uk.wikisource.org/w/index.php?title=MediaWiki:IndexForm.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');
//
mw.loader.load('//uk.wikisource.org/w/index.php?title=MediaWiki:HidePageTitleNamespace.js&action=raw&ctype=text/javascript');
// Вичитування прози і поезії
//importScript('MediaWiki:Prose.js');
//importScript('MediaWiki:Poem.js');
// Messages are configurable here
if(!self.ws_messages) self.ws_messages = { };
window.ws_msg = function (name) {
var m = self.ws_messages[name];
if(m) return m; else return name;
};
self.ws_messages = {
'▲':'▲',
'corr_list':"List of corrections performed on this page" ,
'corr_link':"Corrections" ,
'corr_one':"One typo </a> has been corrected." ,
'corr_many':" typos</a> have been corrected." ,
'corr_close':"Close." ,
'iwtrans':'Цей текст береться з',
'iwtrans2':'Цей текст береться з інших розділів Вікіджерел.'
};
self.proofreadpage_add_container = true;
// Mouse wheel zoom should work now for most browsers.
// If it does not work for you, set this to true in your javascript.
self.proofreadpage_disable_wheelzoom = false;
/**
* Allow descriptive labels next to sidebar language links using {{interwiki-info}}
* by [[user:ThomasV]]
*/
function interwikiExtra() {
// iterate over all <span>-elements
for(var i=0; a=document.getElementsByTagName('span')[i]; i++) {
// if found a linkInfo span
if(a.className == 'interwiki-info') {
// iterate over all <li>-elements
var count=0;
for(var j=0; b=document.getElementsByTagName('li')[j]; j++) {
if(b.className == 'interwiki-' + a.id) {
b.innerHTML = b.innerHTML + ' ' + mw.html.escape(a.title);
if(a.title == '(vo)') {
b.title = 'Original Version';
}
}
else if(b.className == 'interwiki-' + a.id.substr(0, a.id.length-1)) {
count++;
if(a.id.charAt(a.id.length-1) == count) {
b.innerHTML = b.innerHTML + ' ' + mw.html.escape(a.title);
}
}
}
}
}
}
$(interwikiExtra);
$(function() {
var spans, span, i, len;
spans = document.getElementById('n-Ad-fontes').getElementsByTagName('span');
for (i = 0, len = spans.length; i < len; i++) {
span = spans[i];
span.style.fontStyle = "italic";
}
});
$(function() {
var spans, span, i, len;
spans = document.getElementById('n-225-річчя-Оноре-де-Бальзака').getElementsByTagName('span');
for (i = 0, len = spans.length; i < len; i++) {
span = spans[i];
span.innerHTML = "225-річчя<br/>Оноре де Бальзака";
// span.style.fontWeight = "bold";
}
});
/**
* Quality indicators on "article" tab
* by [[user:ThomasV]]
*/
// Return src for icon given percentage
function icon_src(t){
var src='//upload.wikimedia.org/wikipedia/commons/';
switch(t){
case '0%': src+='8/8f/00'; break;
case '25%': src+='5/5b/25'; break;
case '50%': src+='3/3a/50'; break;
case '75%': src+='c/cd/75'; break;
case '100%': src+='6/64/100'; break;
}
return src + '%25.png';
}
// add indicator
function pageQuality() {
var a = document.getElementById('ca-nstab-main');
if(!a) return;
var pr_index = document.getElementById('pr_index');
if(pr_index) return;
var q = document.getElementById('textquality');
var new_img;
if(q) {
new_img = document.createElement('img');
new_img.setAttribute('src', icon_src(q.className));
a.firstChild.appendChild(new_img);
}
for(var i=0; spanElem = document.getElementsByTagName('span')[i]; i++) {
if (spanElem.className == 'pagequality') {
new_img = document.createElement('img');
new_img.setAttribute('src', icon_src(spanElem.title));
if(mw.config.get('wgCanonicalNamespace') == 'Page') {
a.firstChild.appendChild(new_img);
}
else {
s1 = spanElem.parentNode.previousSibling;
opttext = s1.firstChild.firstChild;
img = opttext.firstChild.nextSibling.nextSibling.nextSibling;
next = img.nextSibling;
opttext.removeChild(img);
opttext.insertBefore(new_img,next);
}
}
}
}
$(pageQuality);
// Add link to the extension [[user:sanbeg]]
function pr_add_quality_buttons_link(){
if(typeof proofreadPageMessageStatus == 'undefined') return;
if( self.proofreadpage_no_quality_buttons ) return;
var ig = document.getElementById("wpWatchthis");
if( !ig ) return;
var f = document.createElement("span");
f.innerHTML = ' (<a href="/wiki/Help:Page Status">help</a>)';
ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling.nextSibling);
}
$(pr_add_quality_buttons_link);
/**
* Add arrows on sidebar to compare current page to interlanguage link'd page
* by [[user:Pathoschild]], based on older script by unknown
*/
$(function() {
var lang = $('#p-lang');
if (lang.length > 0) {
// get list of links
var biboxes = lang.find('li');
// iterate over links
biboxes.each(function(index, bibox) {
// get link
var bilink = $(bibox).find('a')[0];
if (!bilink) {
return true;
}
// create new URL
var m = $(bilink).attr('href').match(/\/\/([^\.]+)\.wikisource/);
if (!m) {
return true;
}
var bilang = m[1];
var bilanglink = mw.util.getUrl( mw.config.get('wgPageName') ) + '?match=' + bilang;
// create link
var bianchor = $('<a></a>')
.attr('href',bilanglink)
.attr('title','Порівняти цю сторінку з версією мовою ' + bilang +'.')
.text(' ⇔');
// add link
$(bibox).append(bianchor);
});
}
});
/**
* Allows extra script to run in Special:Watchlist — addition of announcements
* script allows users to dismiss Mediawiki:watchlist-announcements, as per sitenotice
* user:billinghurst 20100522, as hacked from WP script
*/
if ( mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist' ) {
importScript('MediaWiki:Common.js/watchlist.js');
}
// Стилі для makeCollapsible
importStylesheet('MediaWiki:JQuery-makeCollapsible.css');
/**
* Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[:en:Wikipedia:NavFrame]].
* Maintainers: [[:en:User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "сховати";
var expandCaption = "показати";
window.collapseTable = function ( tableIndex ) {
var Button = document.getElementById( 'collapseButton' + tableIndex );
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
var i;
if ( Button.firstChild.data === collapseCaption ) {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
}
Button.firstChild.data = expandCaption;
} else {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
};
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = {};
var Tables = document.getElementsByTagName( 'table' );
var i;
function handleButtonLink( index, e ) {
window.collapseTable( index );
e.preventDefault();
}
for ( i = 0; i < Tables.length; i++ ) {
if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
if ( !HeaderRow ) continue;
var Header = HeaderRow.getElementsByTagName( 'th' )[0];
if ( !Header ) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
var Button = document.createElement( 'span' );
var ButtonLink = document.createElement( 'a' );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = 'collapseButton'; /* Styles are declared in Common.css */
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
ButtonLink.setAttribute( 'href', '#' );
$( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( '[' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
Header.insertBefore( Button, Header.firstChild );
tableIndex++;
}
}
for ( i = 0; i < tableIndex; i++ ) {
if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
window.collapseTable( i );
}
else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
var element = NavigationBoxes[i];
while ((element = element.parentNode)) {
if ( $( element ).hasClass( 'outercollapse' ) ) {
window.collapseTable ( i );
break;
}
}
}
}
}
$( createCollapseButtons );
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[:en:Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
/**
* Shows and hides content and picture (if available) of navigation bars
* Parameters:
* indexNavigationBar: the index of navigation bar to be toggled
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var NavChild;
if ( !NavFrame || !NavToggle ) {
return false;
}
/* if shown now */
if ( NavToggle.firstChild.data === NavigationBarHide ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
/* if hidden now */
} else if ( NavToggle.firstChild.data === NavigationBarShow ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
event.preventDefault();
};
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
var indexNavigationBar = 0;
var NavFrame;
var NavChild;
/* iterate over all < div >-elements */
var divs = document.getElementsByTagName( 'div' );
for ( var i = 0; (NavFrame = divs[i]); i++ ) {
/* if found a navigation bar */
if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
indexNavigationBar++;
var NavToggle = document.createElement( 'a' );
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
NavToggle.setAttribute( 'href', '#' );
$( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
/**
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
if ( NavChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
if ( isCollapsed ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
NavToggle.appendChild( NavToggleText );
/* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild( NavToggle );
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
}
}
$( createNavigationBarToggleButton );
/**
* Description: Uses regular expressions and caching for better performance to determine if an element has a class.
* original authors (stolen from wikipedia): w:User:Mike Dillon, w:User:R. Koot, w:User:SG
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/*
* port from [[:he:mediawiki:common.js]] for [[mediawiki:edittools]] -Steve
*/
/* פונקציה שמשמשת לאיפשור ניקוד ב[[מדיה ויקי:edittools]] */
function nikud(){
if (document.getElementById('edit-templates')!=null){
for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
if(a.className == "nikud") {
a.onclick=function(){insertTags('', this.title, '');return false;};
}
}
}
}
$(nikud);
/**
* withJS
*
* Allow to load custom scripts from the MediaWiki namespace without
* editing [[Special:Mypage/common.js]]
*
* Maintainer: [[User:Platonides]], [[User:Lupo]]
*/
var extraJS = mw.util.getParamValue('withJS');
// Leave here for backwards compatibility
(function (extraJS) {
if (!extraJS) {
return;
}
if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
// Disallow some characters in file name
importScript(extraJS);
} else {
// Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
$(function () {
mw.notify(extraJS + ' javascript not allowed to be loaded.', 'error');
});
}
})(extraJS);
/**
* Icons on the top right of the article.
*
* @source https://www.mediawiki.org/wiki/Snippets/Top_icons
* @author Krinkle
* @version 6
*/
mw.hook( 'wikipage.content' ).add( function ( $content ) {
$content.find( '.Top_icon_raw' )
.removeClass( 'Top_icon_raw' )
.addClass( 'Top_icon_dynamic' )
.prependTo( '#firstHeading' );
} );
/*Script to allow language links to Multilingual Wikisource (http://wikisource.org) */
importScript('MediaWiki:Multilingual-link.js');
/*
* Зміни на панелі інструментів редактора WikiEditor/Toolbar customization
*/
$(function () {
if ($('#editform').length) {
$('#wpTextbox1').on( 'wikiEditor-toolbar-doneInitialSections', function() {
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced', group: 'insert',
tools:{
/* Наголос */
id_a:{
type: 'button',
action: {type:'encapsulate', options:{pre: "́", post: ""}},
label: 'Наголос',
labelMsg: 'a',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Acute_accent.svg/16px-Acute_accent.svg.png'
},
/* circumflex */
id_c:{
type: 'button',
action: {type:'encapsulate', options:{pre: String.fromCharCode(770), post: ""}},
label: 'Циркумфлекс',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/cc/Circumflex_accent.svg/16px-Circumflex_accent.svg.png'
},
/* Гравіс */
id_g:{
type: 'button',
action: {type:'encapsulate', options:{pre: String.fromCharCode(768), post: ""}},
label: 'Гравіс',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/4/43/Grave_accent.svg/16px-Grave_accent.svg.png'
},
/* Довге тире */
id_d:{
type: 'button',
action: {type:'encapsulate', options:{pre: '—', post: ""}},
label: 'Довге тире',
icon: '//upload.wikimedia.org/wikipedia/commons/4/4e/Dash_icon.svg'
},
/* Три крапки */
id_3p:{
type: 'button',
action: {type:'encapsulate', options:{pre: '…', post: ""}},
label: 'Три крапки',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Simple_icon_ellipsis.svg/28px-Simple_icon_ellipsis.svg.png'
}
}
});
/* Remove button for <big> */
$('#wpTextbox1').wikiEditor('removeFromToolbar', {
'section': 'advanced',
'group': 'size',
'tool': 'big'
});
/* Remove button for <small> */
$('#wpTextbox1').wikiEditor('removeFromToolbar', {
'section': 'advanced',
'group': 'size',
'tool': 'small'
});
});
}
});
/**
* Force Footer &/or end matter out of Dynamic Layouts
* Namespace coverage: Main (ns-0), Translation (ns-114)
*/
jQuery( document ).ready( function ( $ ) {
var nsFooters = [ 0/*, 114*/ ];
if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), nsFooters ) !== -1 ) {
$( 'table.acContainer' ).insertAfter( $( 'div.printfooter' ) );
$( 'div.licenseContainer' ).not( 'div.licenseContainer div.licenseContainer' ).insertBefore( $( 'div#catlinks' ) );
}
} );
/**
* Force Header &/or section heading matter out of Dynamic Layouts
* Namespace coverage: Main (ns-0), Translation (ns-114)
*/
jQuery( document ).ready( function ( $ ) {
var nsHeaders = [ 0/*, 114*/ ];
if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), nsHeaders ) !== -1 ) {
$( 'div#headerContainer' ).prependTo( $( 'div#mw-content-text' ) );
$( 'div#heederContainer' ).prependTo( $( 'div#mw-content-text' ) );
$( 'div#headertemplate' ).prependTo( $( 'div#mw-content-text' ) );
$( 'div#heedertemplate' ).prependTo( $( 'div#mw-content-text' ) );
}
} );
/**
* PageNumbers Dynamic Layouts helper
*
* removes sidebar Display Options menu from all ns except Main (ns-0) and Translation (ns-114)
*
*/
jQuery( document ).ready( function ( $ ) {
var nsDynamicLayouts = [ -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103, 104, 105, 106, 107, 115, 828, 829 ];
if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), nsDynamicLayouts ) !== -1 ) {
$( 'div' ).remove( '#p-do' );
}
} );
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */
/* НЕ ДОДАВАЙТЕ КОД ПІСЛЯ ЦЬОГО РЯДКА */