مدیاویکی:Common.js
نکته: پس از انتشار ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.
- فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلیدهای Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-R)
- گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-Shift-R)
- اینترنت اکسپلورر/ Edge: کلید Ctrl را نگهدارید و روی دکمهٔ Refresh کلیک کنید، یا کلیدهای Ctrl-F5 را با هم فشار دهید
- اپرا: Ctrl-F5 را بفشارید.
/**
* Scripts imported from wikisource.org
*/
//Correcting rtl direction in index edit pages for Proofreadpage extention
if (mw.config.get('wgNamespaceNumber') == 106) {
if (mw.config.get('wgAction') == "edit") {
$(function () { setTimeout(function () { $("textarea[name=Pages], textarea[name=Remarks]").attr('dir', 'ltr'); }, 1000); });
}
}
// Messages are configurable here
self.ws_messages = {
'optlist':'تنظیمات نمایش',
'hide_page_numbers':'پنهان کردن شماره برگ',
'show_page_numbers':'نمایش دادن شماره برگ',
'layout':'نمایش',
'author':'نویسنده',
'translator':'مترجم',
'editor':'ویراستار',
'publisher':'ناشر',
'place':'مکان',
'volume':'جلد',
'school':'مدرسه',
'book':'کتاب',
'collection':'گردآوری',
'journal':'ژورنال و مجله',
'phdthesis':'پایاننامه',
'dictionary':'فرهنگلغت',
'progress':'روند',
'progress_T':'انجام شد',
'progress_V':'نمونهخوانی شد',
'progress_C':'باید نمونهخوانی شود',
'progress_MS':'در انتظار همتایابی و جداسازی',
'progress_OCR':'نیازمند لایه متنی اوسیآر',
'progress_L':'پرونده مبدأ مشکل دارد (بدون برگاست، برگ در دسترس نیست، موارد دیگر)',
'▲':'بازگشت به بالای صفحه',
'corr_list':"فهرست نمونهخوانیهای انجام شده بر روی این برگ" ,
'corr_link':"تصحیح" ,
'corr_one':"یک اشتباه چاپی </a> تصحیح شد" ,
'corr_many':" اشتباههای چاپی</a> تصحیح شدند" ,
'corr_close':"بسته" ,
'iwtrans':'مبدا متن',
'iwtrans2':'مبدا متن از ویکینبشتههای دیگر'
};
self.ws_layouts = {
'نمایش یک':{
'#text-wrap':"",
'#text-container':"" ,
'#text':"",
'.sidenote-right':"float:right;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
'.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
'.editsection':"display:none",
'#headertemplate':""},
'نمایش دو':{
'#text-wrap':"position:relative;margin-left:3em;margin-right:3em;",
'#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" ,
'#text':"text-align:justify;",
'.sidenote-right':"position:absolute; left:37em;width:16em;text-indent:0em;text-align:left;",
'.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;",
'.editsection':"display:none",
'#headertemplate':""},
'نمایش سه':{
'#text-wrap':"margin-left:3em",
'#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" ,
'#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto; position:relative;",
'.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
'.sidenote-left':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
'.editsection':"display:none",
'#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;"}
};
self.proofreadpage_add_container = true;
var old_wgserver = '//wikisource.org';
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
/*mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:OCR.js&action=raw&ctype=text/javascript');*/
mw.loader.load('//fa.wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript');
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:Modernisation.js&action=raw&ctype=text/javascript');
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:Corrections.js&action=raw&ctype=text/javascript');
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:DisplayFooter.js&action=raw&ctype=text/javascript');
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:IndexForm.js&action=raw&ctype=text/javascript');
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:Dictionary.js&action=raw&ctype=text/javascript');
mw.loader.load(old_wgserver + '/w/index.php?title=MediaWiki:RegexpButton.js&action=raw&ctype=text/javascript');
mw.loader.load(mw.config.get('wgServer') + '/w/index.php?title=MediaWiki:MediaWiki.panel.js&action=raw&ctype=text/javascript' );
// 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;
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* قرار دادن فرمولهای ریاضی در سمت چپ مناسب برای ویکیهای راست به چپ
*/
$(function(){
$("img.tex, span.texhtml").each(function(){
if($(this).parent().text().trim() == $(this).text() && $(this).parent().is("p,dd"))
$(this).parent().css({direction: "ltr", padding: "1em 0"});
});
});
/**
* جهت صفحات کدهای منبع پایتون، سیاساس، جاوااسکریپت، سی، سی++ در هنگام ویرایش
*/
if(/\.(js|css|py|cpp|c)$/.test(mw.config.get('wgPageName')))
mw.util.addCSS(".diff-addedline, .diff-deletedline, .diff-context { direction: ltr; }" +
".diff-addedline > div, .diff-deletedline > div, .diff-context > div { white-space: pre; }" +
"#wpTextbox1 { direction: ltr; }" );
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia:NavFrame]].
* Maintainers: [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "نهفتن";
var expandCaption = "نمایش";
function collapseTable( tableIndex )
{
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var 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" );
for ( var 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', createClickHandler( tableIndex ) );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.firstChild );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( $( NavigationBoxes[i] ).hasClass( "collapsed" ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( $( NavigationBoxes[i] ).hasClass( "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( $( element ).hasClass( "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
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 + ']';
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var 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 (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ($(NavChild).hasClass('NavContent') || $(NavChild).hasClass('NavPic')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// 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', 'javascript:toggleNavigationBar(' + 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 (var 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 (var 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 );
/**
* Test if an element has a certain class.
*
* @deprecated Use jQuery instead.
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/**
* 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);
/**
* Icons on the top right of the article.
* See also CSS
*
* @source: http://www.mediawiki.org/wiki/Snippets/Top_icons
* @rev: 2
*/
jQuery( document ).ready( function( $ ) {
$( '.Top_icon_raw' )
.removeClass( 'Top_icon_raw' )
.addClass( 'Top_icon_dynamic' )
.prependTo( '#firstHeading' );
} );
/**
* 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 + ' ' + 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 + ' ' + a.title;
}
}
}
}
}
}
$(interwikiExtra);
//adding combo box to edittools.js
var load_edittools = true;
// extra drop down menu on editing for adding special characters
importScript( 'MediaWiki:Edittools.js' );
// Editpage scripts
if( $.inArray(mw.config.get('wgAction'), ['edit' , 'submit' ]) !== -1) {
importScript( 'MediaWiki:Editpage.js' );
}
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:GoogleOCR.js&action=raw&ctype=text/javascript');