МедиаВики:Common.js
Көрүнүш
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// test
$(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
/*
== Global configuration ==
Override these default settings in your [[Special:Mypage/monobook.js]]
for Example: JSconfig.loadAutoInformationTemplate = false;
*/
var JSconfig =
{
loadAutoInformationTemplate : true,
loadEditToolsStyleCompact : true
};
/*
== Import an external JavaScript ==
*/
var isMSIE = ((navigator.appName == 'Microsoft Internet Explorer' ) > 0);
var isNoSpecial = (mw.config.get("wgCanonicalNamespace") != "Special");
var isUpload = ((mw.config.get("wgCanonicalNamespace") == "Special") && (mw.config.get('wgCanonicalSpecialPageName') == "Upload"));
var isEdit = ((document.URL.indexOf("action=edit") > 0 || document.URL.indexOf("action=submit") > 0) && !document.getElementById('ca-viewsource') > 0);
// Add scripts group
mw.loader.load( '/w/index.php?title=MediaWiki:Scripts.js&action=raw&ctype=text/javascript' );
// Add MSIE fixes
if (isMSIE) { mw.loader.load( '/w/index.php?title=MediaWiki:Iefixesplus.js&action=raw&ctype=text/javascript' ); }
// Add Main page layout fix
if (mw.config.get('wgTitle') == 'Башкы бет') {mw.loader.load( '/w/index.php?title=MediaWiki:Mainpage.js&action=raw&ctype=text/javascript' );}
//
if (isEdit && $("body").hasClass("ns-talk") || isEdit && $("body").hasClass("ns-4")) { mw.loader.load( '/w/index.php?title=MediaWiki:Emoticons.js&action=raw&ctype=text/javascript' ); }
// Add editing stuff (toolbar buttons, template pull-down menu etc) for registered users
//if (isEdit && isNoSpecial) { importScript( "MediaWiki:Editplus.js" ); }
// Add script for charsets pull-down menu
//if (isEdit) { importScript( "MediaWiki:Editpage.js" ); }
// Add script for charsets pull-down menu
//if (isUpload) { importScript( "MediaWiki:Upload.js" ); }
//Fix "Upload file" link when using the secure proxy
//This is a workaround that can be removed when bug 10843 is fixed
$(function() {
if (document.getElementById("t-upload"))
{
document.getElementById("t-upload").getElementsByTagName("a")[0].href = mw.config.get('wgArticlePath').replace("$1", "Атайын:Upload");
}
});
// uploadwizard_newusers Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]
function uploadwizard_newusers() {
if (mw.config.get('wgNamespaceNumber') == 4 && mw.config.get('wgTitle') == "Жүктөө" && mw.config.get('wgAction') == "view") {
var oldDiv = document.getElementById("autoconfirmedusers"),
newDiv = document.getElementById("newusers");
if (oldDiv && newDiv) {
if( $.inArray( 'autoconfirmed', mw.config.get('wgUserGroups') ) !== -1 ){
oldDiv.style.display = "block";
newDiv.style.display = "none";
}
oldDiv.style.display = "none";
newDiv.style.display = "block";
}
}
}
$(uploadwizard_newusers);
// WikiMiniAtlas
/*
var metaBase = "http://meta.wikimedia.org";
mw.loader.load(metaBase+"/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript")
*/
/*
== Fixes for skins if RTL enabled ==
*/
// if ( $.inArray(mw.config.get('wgUserLanguage'), ["ky-arab" , "ky-cn" ]) !== -1) {
// switch(mw.config.get('skin')) {
// // Wikistandard family
// case "standard":
// importStylesheet("MediaWiki:Standard_rtl.css");
// break;
// case "cologneblue":
// importStylesheet("MediaWiki:Cologneblue_rtl.css");
// break;
// case "nostalgia":
// importStylesheet("MediaWiki:Nostalgia_rtl.css");
// break;
// // Modern family
// case "modern":
// importStylesheet("MediaWiki:Modern_rtl.css");
// break;
// // MonoBook family
// case "simple":
// importStylesheet("MediaWiki:Simple_rtl.css");
// break;
// case "myskin":
// importStylesheet("MediaWiki:Myskin_rtl.css");
// break;
// case "chick":
// importStylesheet("MediaWiki:Chick_rtl.css");
// break;
// // case "monobook":
// default:
// importStylesheet("MediaWiki:Monobook_rtl.css");
// }
// importStylesheet("MediaWiki:Rtl.css");
// }
/*
== Switch language variants of messages ==
*/
function wgULS(cyrl,latn,arab,en) {
ky = cyrl||latn||arab;
cyrl = cyrl;
latn = latn;
arab = arab;
if (!en) { en = ""; }
switch(mw.config.get('wgUserLanguage')) {
case "ky": return ky;
case "ky-kz":
case "ky-cyrl": return cyrl;
case "ky-tr":
case "ky-latn": return latn;
case "ky-cn":
case "ky-arab": return arab;
default: return en;
}
}
/*
== Execute function on page load ==
*/
mw.log.deprecate( window, 'addLoadEvent', $, 'Use jQuery instead' );
/*
== Test if an element has a certain class ==
@deprecated: Use $(element).hasClass() instead.
*/
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
return $( element ).hasClass( className );
}, 'Use jQuery.hasClass() instead' );
/*
== lan enhanced Conversion ==
*/
$(function() {
var $lanBlocks;
switch(mw.config.get('skin')) {
case "standard":
case "cologneblue":
case "nostalgia":
$lanBlocks=$('#article').find('.lanOptional');
break;
case "modern":
$lanBlocks=$('#mw_content').find('.lanOptional');
break;
// case "simple":
// case "myskin":
// case "chick":
// case "monobook":
default:
$lanBlocks=$('#bodyContent').find('.lanOptional');
}
for(var i = 0; i < $lanBlocks.length; i++) {
if(!$($lanBlocks[i]).hasClass(mw.config.get('wgUserLanguage'))){$lanBlocks[i].style.display="none";}
}
});
/*
== Collapsible tables ==
*
* Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]].
*
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
* @author [[User:R. Koot]]
* @author [[User:Krinkle]]
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
* is supported in MediaWiki core.
*/
var autoCollapse = 2;
var collapseCaption = wgULS('жашыруу ▼','jasır ▼','▼ '+'جاسىر','hide');
var expandCaption = wgULS('көрсөтүү ►','körset ►','◀ '+'كٴورسەت','show');
function collapseTable( 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 createClickHandler( tableIndex ) {
return function ( e ) {
e.preventDefault();
collapseTable( tableIndex );
};
}
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = {};
var Tables = document.getElementsByTagName( 'table' );
var i;
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 );
// FIXME: Styles should be declared in [[MediaWiki:Common.css]]
Button.style.styleFloat = 'right';
Button.style.cssFloat = 'right';
Button.style.fontWeight = 'normal';
Button.style.textAlign = 'right';
Button.style.width = '6em';
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
ButtonLink.setAttribute( 'href', '#' );
$( ButtonLink ).on( 'click', createClickHandler( 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' ) ) ) {
collapseTable( i );
}
}
}
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
/*
== Dynamic Navigation Bars (experimental) ==
Description: See [[Wikipedia:NavFrame]].
Maintainers: UNMAINTAINED
*/
/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
//var NavigationBarHide = '{{int:hide/' + mw.config.get('wgUserLanguage') + '}}';
//var NavigationBarShow = '{{int:show/' + mw.config.get('wgUserLanguage') + '}}';
/**
* 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);
}
}
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
/*
== Transforming 'Village Pump' to Discussion pages ==
*/
function DiscussionBistro() {
if(document.title.search("Wikipedia:Жамаат_порталы") != -1)
document.body.className = "ns-1";
}
$(DiscussionBistro);
/** WikiMiniAtlas
* Description: WikiMiniAtlas is a popup click and drag world map.
* Created by: [[User:Dschwen]]
*/
mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript');
/*
disable дегендерді жасыру және бірден "Кирил" боп тұратындай қылу
*/
$( function(){
$( '#ca-varlang-0' ).find( 'a' ).first().text( 'Кирил' );
// FIXME: Removed on [[gerrit:138368]]
$( '#mw-vector-current-variant' ).text( wgULS( "Кирил","Latın","توتە") );
$( '#ca-varlang-1, #ca-varlang-4, #ca-varlang-5, #ca-varlang-6' ).hide();
} );