مدیاویکی:Common.js: تفاوت میان نسخه‌ها

بدون خلاصۀ ویرایش
خنثی‌سازی نسخهٔ 55143 از Engineer (بحث)
برچسب: خنثی‌سازی
 
(۲۷ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد)
خط ۱: خط ۱:
/* اضافه کردن تیتر برای یادداشت ها */
$( function() {
    if($('#reflist-notes .reflist').text().length>10) {
        $('#reflist-notes').before('<h2>یادداشت‌ها</h2>');
    }
});
/* تنظیمات پاپ آپ ها
mw.loader.using( [ 'ext.popups' ], function() { // wait for popups to be loaded
// Time to wait in ms before showing a popup on hover. Default is 500.
mw.popups.render.POPUP_DELAY = 500;
// Time to wait in ms before closing a popup on de-hover. Default is 300.
mw.popups.render.POPUP_CLOSE_DELAY = 300;
// Time to wait in ms before starting the API queries on hover, must be <= POPUP_DELAY. Default is 50.
// Don't change this unless you know what you're doing.
mw.popups.render.API_DELAY = 50;
});
var offset = $(':target').offset();
var scrollto = offset.top - 100; // minus fixed header height
$('html, body').animate({scrollTop:scrollto}, 0);
*/
/* global mw, $ */
/* global mw, $ */
// Editing-related javascripts
// Editing-related javascripts
خط ۳۶: خط ۶۲:
/**
/**
  * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
  * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
  * @revision 2017-05-16
  * @revision 2020-04-04
  */
  */
mw.loader.using( ['mediawiki.util', 'mediawiki.notify'], function () {
mw.loader.using( ['mediawiki.util'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
extraJS = mw.util.getParamValue( 'withJS' );


if ( extraCSS ) {
if ( extraCSS ) {
// DONT REMOVE THIS IF (unless you are OK with CSRF attacks)
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
خط ۵۲: خط ۷۸:


if ( extraJS ) {
if ( extraJS ) {
// DONT REMOVE THIS IF (unless you are OK with XSS & CSRF attacks)
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
خط ۷۰: خط ۹۶:
});
});


/** Collapsible tables *********************************************************
/**
* Collapsible tables; reimplemented with mw-collapsible
* Styling is also in place to avoid FOUC
  *
  *
  * Description: Allows tables to be collapsed, showing only the header. See
  * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
*              [[Wikipedia:NavFrame]].
  * @version 3.0.0 (2018-05-20)
  *  Maintainers: [[User:R. Koot]]
  * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
* @author [[User:R. Koot]]
* @author [[User:Krinkle]]
* @author [[User:TheDJ]]
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
*
* @param {jQuery} $content
  */
  */
var autoCollapse = 2;
function makeCollapsibleMwCollapsible( $content ) {
var collapseCaption = "نهفتن";
var $tables = $content
var expandCaption = "نمایش";
.find( 'table.collapsible:not(.mw-collapsible)' )
.addClass( 'mw-collapsible' );


function collapseTable(tableIndex) {
$.each( $tables, function ( index, table ) {
  var Button = document.getElementById("collapseButton" + tableIndex);
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
  var Table = document.getElementById("collapsibleTable" + tableIndex);
if ( $( table ).hasClass( 'collapsed' ) ) {
$( table ).addClass( 'mw-collapsed' );
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
}
} );
if ( $tables.length > 0 ) {
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
$tables.makeCollapsible();
} );
}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );


  if (!Table || !Button) {
/**
    return false;
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
  }
*
* Maintainers: TheDJ
*/
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
$toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function ( index, element ) {
$element = $( element );
if ( $element.hasClass( 'collapsible' ) ) {
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
}
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
$element.data( 'mw-collapsible' ).collapse();
} else if ( $element.hasClass( 'innercollapse' ) ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
$element.data( 'mw-collapsible' ).collapse();
}
}
// because of colored backgrounds, style the link in the text color
// to ensure accessible contrast
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color
if ( $toggle.parent()[ 0 ].style.color ) {
$toggle.find( 'a' ).css( 'color', 'inherit' );
}
}
} );
}


  var Rows = Table.rows;
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );


  if (Button.firstChild.data == collapseCaption) {
/**
    for (var i = 1; i < Rows.length; i++) {
* Dynamic Navigation Bars (experimental)
      Rows[i].style.display = "none";
*
    }
* Description: See [[Wikipedia:NavFrame]].
    Button.firstChild.data = expandCaption;
* Maintainers: UNMAINTAINED
  } else {
*/
    for (var i = 1; i < Rows.length; i++) {
      Rows[i].style.display = Rows[0].style.display;
    }
    Button.firstChild.data = collapseCaption;
  }
}


function createCollapseButtons() {
var collapseCaption = 'بسته';
  var tableIndex = 0;
var expandCaption = 'باز';
  var NavigationBoxes = {};
  var Tables = document.getElementsByTagName("table");
  var i;


  function handleButtonLink(index, e) {
// Set up the words in your language
    window.collapseTable(index);
var navigationBarHide = '[' + collapseCaption + ']';
    e.preventDefault();
var navigationBarShow = '[' + expandCaption + ']';
  }


  for (i = 0; i < Tables.length; i++) {
/**
    if ($(Tables[i]).hasClass("collapsible")) {
* Shows and hides content and picture (if available) of navigation bars.
*
* @param {number} indexNavigationBar The index of navigation bar to be toggled
* @param {jQuery.Event} event Event object
* @return {boolean}
*/
function toggleNavigationBar( indexNavigationBar, event ) {
var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var navChild;


      /* only add button and increment count if there is a header row to work with */
if ( !navFrame || !navToggle ) {
      var HeaderRow = Tables[i].getElementsByTagName("tr")[0];
return false;
      if (!HeaderRow) continue;
}
      var Header = HeaderRow.getElementsByTagName("th")[0];
      if (!Header) continue;


      NavigationBoxes[tableIndex] = Tables[i];
// If shown now
      Tables[i].setAttribute("id", "collapsibleTable" + tableIndex);
if ( navToggle.firstChild.data === navigationBarHide ) {
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavContent' ) ) {
navChild.style.display = 'none';
}
}
navToggle.firstChild.data = navigationBarShow;


      var Button = document.createElement("span");
// If hidden now
      var ButtonLink = document.createElement("a");
} else if ( navToggle.firstChild.data === navigationBarShow ) {
      var ButtonText = document.createTextNode(collapseCaption);
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavContent' ) ) {
navChild.style.display = 'block';
}
}
navToggle.firstChild.data = navigationBarHide;
}


      Button.className = "collapseButton"; /* Styles are declared in Common.css */
event.preventDefault();
}


      ButtonLink.style.color = Header.style.color;
/**
      ButtonLink.setAttribute("id", "collapseButton" + tableIndex);
* Adds show/hide-button to navigation bars.
      ButtonLink.setAttribute("href", "#");
*
      $(ButtonLink).on("click", $.proxy(handleButtonLink, ButtonLink, tableIndex));
* @param {jQuery} $content
      ButtonLink.appendChild(ButtonText);
*/
function createNavigationBarToggleButton( $content ) {
var j, navChild, navToggle, navToggleText, isCollapsed,
indexNavigationBar = 0;
// Iterate over all < div >-elements
var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
$divs.each( function ( i, navFrame ) {
indexNavigationBar++;
navToggle = document.createElement( 'a' );
navToggle.className = 'NavToggle';
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
navToggle.setAttribute( 'href', '#' );
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );


      Button.appendChild(document.createTextNode("["));
isCollapsed = $( navFrame ).hasClass( 'collapsed' );
      Button.appendChild(ButtonLink);
/**
      Button.appendChild(document.createTextNode("]"));
* 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';
}
}
}
navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
navToggle.appendChild( navToggleText );


      Header.insertBefore(Button, Header.firstChild);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
      tableIndex++;
for ( 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 );
  for (i = 0; i < tableIndex; i++) {
}
    if ($(NavigationBoxes[i]).hasClass("collapsed") || (tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass("autocollapse"))) {
}
      window.collapseTable(i);
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
    } else if ($(NavigationBoxes[i]).hasClass("innercollapse")) {
} );
      var element = NavigationBoxes[i];
      while ((element = element.parentNode)) {
        if ($(element).hasClass("outercollapse")) {
          window.collapseTable(i);
          break;
        }
      }
    }
  }
}
}


$(createCollapseButtons);
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );


/** Dynamic Navigation Bars (experimental) *************************************
/** Dynamic Navigation Bars (experimental) *************************************
خط ۱۸۸: خط ۲۹۸:
   /* if shown now */
   /* if shown now */
   if (NavToggle.firstChild.data === NavigationBarHide) {
   if (NavToggle.firstChild.data === NavigationBarHide) {
     for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) {
     for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
       if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic")) {
       if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic")) {
         NavChild.style.display = "none";
         NavChild.style.display = "none";
خط ۲۶۴: خط ۳۷۴:
}
}


$(createNavigationBarToggleButton);
// $(createNavigationBarToggleButton);


/** Main Page layout fixes *********************************************************
/** Main Page layout fixes *********************************************************
خط ۲۷۲: خط ۳۸۲:
  */
  */
mw.loader.using(["mediawiki.util"], function() {
mw.loader.using(["mediawiki.util"], function() {
/**
  * Extract a URL parameter from the current URL
  * @deprecated: Use mw.util.getParamValue with proper escaping
  */
  mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
   if (["صفحهٔ_اصلی", "بحث:صفحه_اصلی"].indexOf(mw.config.get("wgPageName")) !== -1) {
   if (["صفحهٔ_اصلی", "بحث:صفحه_اصلی"].indexOf(mw.config.get("wgPageName")) !== -1) {
     $(function() {
     $(function() {
خط ۳۵۶: خط ۴۷۱:
} );
} );


/* google analytics */
// Hide the FileExporter portlet link if the file is not free content
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
$(function() {
   (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
   if ($('#ca-fileExporter').length == 1 & $(mw.config.get('wgCategories')).filter(['محتویات غیر آزاد', 'تصویرهای با منبع نامعلوم', 'تصویرهای با پدیدآور نامشخص', 'پرونده‌های بدون مجوز قابل خواندن برای ماشین']).length > 0) {
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  $('#ca-fileExporter').find('a').css('color', 'grey').attr('title', 'غیرفعال برای محتوای غیر آزاد');
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  }
 
  ga('create', 'UA-105346324-1', 'auto');
  ga('send', 'pageview');
 
/* end of google analytics */
 
/* اضافه کردن تیتر برای یادداشت ها */
$( function() {
    if($('#reflist-notes .reflist').text().length>10) {
        $('#reflist-notes').before('<h2>یادداشت‌ها</h2>');
    }
 
 
});
});


/* تنظیمات پاپ آپ ها */
function updateUserScriptWarning( msg, newMsg ) {
mw.loader.using( [ 'ext.popups' ], function() { // wait for popups to be loaded
return function () {
 
var userScript = '/wiki/Special:MyPage/' + mw.config.get('skin') + '.js';
// Time to wait in ms before showing a popup on hover. Default is 500.
var commonScript = '/wiki/Special:MyPage/common.js';
mw.popups.render.POPUP_DELAY = 500;
mw.notify(
 
$('<div>').html(
// Time to wait in ms before closing a popup on de-hover. Default is 300.
// please translate to Farsi
mw.popups.render.POPUP_CLOSE_DELAY = 300;
'One of the scripts you are running is broken and using a deprecated function <strong>' + msg + '</strong>. Please check your <a href="' + userScript + '">skin scripts</a> and <a href="' + commonScript + '">common scripts</a>, to update the reference to' + newMsg + 'to restore your script.'
 
),
// Time to wait in ms before starting the API queries on hover, must be <= POPUP_DELAY. Default is 50.
{ type: 'error' }
// Don't change this unless you know what you're doing.
);  
mw.popups.render.API_DELAY = 50;
};
 
}
});