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

از امامت‌پدیا، دانشنامهٔ امامت و ولایت
(خنثی‌سازی ویرایش 140683 توسط Heydari (بحث))
برچسب: خنثی‌سازی
جزبدون خلاصۀ ویرایش
خط ۱: خط ۱:
/* Any JavaScript here will be loaded for all users on every page load. */
/* global mw, $ */
//<syntaxhighlight lang="javascript">
// Editing-related javascripts
if ($.client.profile().name === 'msie') {
if (mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" || mw.config.get("wgCanonicalSpecialPageName") === "Upload") {
importScript('مدیاویکی:Common.js/IEFixes.js');
  /* scripts specific to editing pages */
  importScript("مدیاویکی:Common.js/edit.js");
}
}
//Editing-related javascripts
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
    /* scripts specific to editing pages */
    importScript( 'مدیاویکی:Common.js/edit.js' );
}
/** Magic editintros ****************************************************
/** Magic editintros ****************************************************
  *
  *
خط ۱۶: خط ۱۰:
  *  Maintainers: [[User:RockMFR]]
  *  Maintainers: [[User:RockMFR]]
  */
  */
function addEditIntro( name ) {
function addEditIntro(name) {
    $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
  $(".mw-editsection, #ca-edit").find("a").each(function(i, el) {
        el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
    el.href = $(this).attr("href") + "&editintro=" + name;
    } );
  });
}
}
 
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
if (mw.config.get("wgNamespaceNumber") === 0) {
    $( function () {
  $(function() {
        if ( document.getElementById( 'disambigbox' ) ) {
    if (document.getElementById("disambigbox")) {
            addEditIntro( 'Template:Disambig_editintro' );
      addEditIntro("Template:Disambig_editintro");
        }
    }
    } );
  });
 
    $( function () {
  $(function() {
        var cats = mw.config.get('wgCategories');
    var cats = mw.config.get("wgCategories");
        if ( !cats ) {
    if (!cats) {
            return;
      return;
        }
    }
        if ( $.inArray( 'افراد زنده', cats ) !== -1 ) {
    if ($.inArray("افراد زنده", cats) !== -1) {
            addEditIntro( 'Template:BLP_editintro' );
      addEditIntro("Template:BLP_editintro");
        }
    }
    } );
  });
}
}


/**
/**
  * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
  * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
  * @rev 5
  * @revision 2017-05-16
  */
  */
// CSS
mw.loader.using( ['mediawiki.util', 'mediawiki.notify'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' );
var extraCSS = mw.util.getParamValue( 'withCSS' ),
if ( extraCSS ) {
extraJS = mw.util.getParamValue( 'withJS' );
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
 
importStylesheet( extraCSS );
if ( extraCSS ) {
} else {
// DONT REMOVE THIS IF (unless you are OK with CSRF attacks)
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
}
}


// JS
if ( extraJS ) {
var extraJS = mw.util.getParamValue( 'withJS' );
// DONT REMOVE THIS IF (unless you are OK with XSS & CSRF attacks)
if ( extraJS ) {
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
importScript( extraJS );
} else {
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
}
}
});


/**
/**
  * Opening preload.js to add interactive training keys
  * Opening preload.js to add interactive training keys
  */
  */
if (mw.util.getParamValue( 'preload' )) {
mw.loader.using(["mediawiki.util"], function() {
importScript("MediaWiki:Preloaded.js");
  if (mw.util.getParamValue("preload")) {
};
    importScript("MediaWiki:Preloaded.js");
  }
});


/** Collapsible tables *********************************************************
/** Collapsible tables *********************************************************
خط ۸۰: خط ۷۹:
var collapseCaption = "نهفتن";
var collapseCaption = "نهفتن";
var expandCaption = "نمایش";
var expandCaption = "نمایش";
var expandCaption_more = "ادامه مطلب";


function collapseTable( tableIndex )
function collapseTable(tableIndex) {
{
  var Button = document.getElementById("collapseButton" + tableIndex);
    var Button = document.getElementById( "collapseButton" + tableIndex );
  var Table = document.getElementById("collapsibleTable" + tableIndex);
    var Table = document.getElementById( "collapsibleTable" + tableIndex );


    if ( !Table || !Button ) {
  if (!Table || !Button) {
        return false;
    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;
     var Rows = Table.rows;
  } else {
/**
     for (var i = 1; i < Rows.length; i++) {
  * AMDEADMAN Edit for readmore collapse added if
      Rows[i].style.display = Rows[0].style.display;
  */
    if ($("#collapsibleTable" + tableIndex).hasClass('readmore') & Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption_more;
    } else 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;
     }
     }
    Button.firstChild.data = collapseCaption;
  }
}
}


function createCollapseButtons() {
function createCollapseButtons() {
    var tableIndex = 0;
  var tableIndex = 0;
    var NavigationBoxes = {};
  var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
  var Tables = document.getElementsByTagName("table");
    var i;
  var i;


    function handleButtonLink( index, e ) {
  function handleButtonLink(index, e) {
        window.collapseTable( index );
    window.collapseTable(index);
        e.preventDefault();
    e.preventDefault();
     }
  }
 
  for (i = 0; i < Tables.length; i++) {
     if ($(Tables[i]).hasClass("collapsible")) {


    for ( i = 0; i < Tables.length; i++ ) {
      /* only add button and increment count if there is a header row to work with */
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
      var HeaderRow = Tables[i].getElementsByTagName("tr")[0];
      if (!HeaderRow) continue;
      var Header = HeaderRow.getElementsByTagName("th")[0];
      if (!Header) continue;


            /* only add button and increment count if there is a header row to work with */
      NavigationBoxes[tableIndex] = Tables[i];
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
      Tables[i].setAttribute("id", "collapsibleTable" + tableIndex);
            if ( !HeaderRow ) continue;
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            if ( !Header ) continue;


            NavigationBoxes[ tableIndex ] = Tables[i];
      var Button = document.createElement("span");
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
      var ButtonLink = document.createElement("a");
      var ButtonText = document.createTextNode(collapseCaption);


            var Button     = document.createElement( 'span' );
      Button.className = "collapseButton"; /* Styles are declared in Common.css */
            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);


            ButtonLink.style.color = Header.style.color;
      Button.appendChild(document.createTextNode("["));
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
      Button.appendChild(ButtonLink);
            ButtonLink.setAttribute( 'href', '#' );
      Button.appendChild(document.createTextNode("]"));
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );


            Button.appendChild( document.createTextNode( '[' ) );
      Header.insertBefore(Button, Header.firstChild);
            Button.appendChild( ButtonLink );
      tableIndex++;
            Button.appendChild( document.createTextNode( ']' ) );
/**
  * AMDEADMAN Edit for readmore collapse
  */
            if($( Tables[i] ).hasClass( 'readmore' )){
                $(Header).html($(Header).text()).append(Button);
            } else {
                Header.insertBefore( Button, Header.firstChild );
            }
            tableIndex++;
        }
     }
     }
  }


    for ( i = 0; i < tableIndex; i++ ) {
  for (i = 0; i < tableIndex; i++) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
    if ($(NavigationBoxes[i]).hasClass("collapsed") || (tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass("autocollapse"))) {
            window.collapseTable( i );
      window.collapseTable(i);
        }  
    } else if ($(NavigationBoxes[i]).hasClass("innercollapse")) {
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
      var element = NavigationBoxes[i];
            var element = NavigationBoxes[i];
      while ((element = element.parentNode)) {
            while ((element = element.parentNode)) {
        if ($(element).hasClass("outercollapse")) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
          window.collapseTable(i);
                    window.collapseTable ( i );
          break;
                    break;
                }
            }
         }
         }
      }
     }
     }
  }
}
}


خط ۱۸۶: خط ۱۶۹:
  *  Maintainers: UNMAINTAINED
  *  Maintainers: UNMAINTAINED
  */
  */
 
// set up the words in your language
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarHide = "[" + collapseCaption + "]";
var NavigationBarShow = '[' + expandCaption + ']';
var NavigationBarShow = "[" + expandCaption + "]";
 
// shows and hides content and picture (if available) of navigation bars
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// Parameters:
//    indexNavigationBar: the index of navigation bar to be toggled
//    indexNavigationBar: the index of navigation bar to be toggled
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
window.toggleNavigationBar = function(indexNavigationBar, event) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
  var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
  var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
    var NavChild;
  var NavChild;
 
    if ( !NavFrame || !NavToggle ) {
  if (!NavFrame || !NavToggle) {
        return false;
    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";
      }
     }
     }
    /* 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;
     NavToggle.firstChild.data = NavigationBarShow;
 
     /* if hidden now */
     /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
  } else if (NavToggle.firstChild.data === NavigationBarShow) {
        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 = 'block';
        NavChild.style.display = "block";
            }
      }
        }
        NavToggle.firstChild.data = NavigationBarHide;
     }
     }
    NavToggle.firstChild.data = NavigationBarHide;
    event.preventDefault();
  }
 
  event.preventDefault();
};
};
 
/* adds show/hide-button to navigation bars */
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
function createNavigationBarToggleButton() {
    var indexNavigationBar = 0;
  var indexNavigationBar = 0;
    var NavFrame;
  var NavFrame;
    var NavChild;
  var NavChild;
    /* iterate over all < div >-elements */
  /* iterate over all < div >-elements */
    var divs = document.getElementsByTagName( 'div' );
  var divs = document.getElementsByTagName("div");
    for ( var i = 0; (NavFrame = divs[i]); i++ ) {
  for (var i = 0;
        /* if found a navigation bar */
    (NavFrame = divs[i]); i++) {
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
    /* if found a navigation bar */
    if ($(NavFrame).hasClass("NavFrame")) {
            indexNavigationBar++;
 
            var NavToggle = document.createElement( 'a' );
      indexNavigationBar++;
            NavToggle.className = 'NavToggle';
      var NavToggle = document.createElement("a");
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
      NavToggle.className = "NavToggle";
            NavToggle.setAttribute( 'href', '#' );
      NavToggle.setAttribute("id", "NavToggle" + indexNavigationBar);
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
      NavToggle.setAttribute("href", "#");
      $(NavToggle).on("click", $.proxy(window.toggleNavigationBar, window, indexNavigationBar));
            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
 
            /**
      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"
      * Check if any children are already hidden.  This loop is here for backwards compatibility:
            * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
      * the old way of making NavFrames start out collapsed was to manually add style="display:none"
            * the content visible without JavaScript support), the new recommended way is to add the class
      * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
            * "collapsed" to the NavFrame itself, just like with collapsible tables.
      * 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' ) ) {
      for (NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                    if ( NavChild.style.display === 'none' ) {
        if ($(NavChild).hasClass("NavPic") || $(NavChild).hasClass("NavContent")) {
                        isCollapsed = true;
          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 );
         }
         }
      }
      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);
$(createNavigationBarToggleButton);


/** Main Page layout fixes *********************************************************
/** Main Page layout fixes *********************************************************
خط ۲۸۸: خط ۲۷۱:
  *  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
  *  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
  */
  */
if (['صفحهٔ_اصلی', 'بحث:صفحه_اصلی'].indexOf(mw.config.get('wgPageName')) !== -1) {
mw.loader.using(["mediawiki.util"], function() {
  $(function () {
  if (["صفحهٔ_اصلی", "بحث:صفحه_اصلی"].indexOf(mw.config.get("wgPageName")) !== -1) {
    mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/wiki/فهرست ویکی‌پدیاها', 'فهرست کامل', 'interwiki-completelist', 'فهرست کامل');
    $(function() {
  });
      mw.util.addPortletLink("p-lang", "//meta.wikimedia.org/wiki/List_of_Wikipedias/fa", "فهرست کامل", "interwiki-completelist", "فهرست کامل");
}
    });
  }
});


/**
/**
خط ۲۹۸: خط ۲۸۳:
  *
  *
  * Description: WikiMiniAtlas is a popup click and drag world map.
  * Description: WikiMiniAtlas is a popup click and drag world map.
  *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
  *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
  *              The script itself is located on meta because it is used by many projects.
  *              The script itself is located on meta because it is used by many projects.
خط ۳۰۴: خط ۲۸۸:
  * Maintainers: [[User:Dschwen]]
  * Maintainers: [[User:Dschwen]]
  */
  */
( function () {
(function() {
    var require_wikiminiatlas = false;
  var require_wikiminiatlas = false;
    var coord_filter = /geohack/;
  var coord_filter = /geohack/;
    $( function () {
  $(function() {
        $( 'a.external.text' ).each( function( key, link ) {
    $("a.external.text").each(function(key, link) {
            if ( link.href && coord_filter.exec( link.href ) ) {
      if (link.href && coord_filter.exec(link.href)) {
                require_wikiminiatlas = true;
        require_wikiminiatlas = true;
                // break from loop
        // break from loop
                return false;
        return false;
            }
      }
        } );
    });
        if ( $( 'div.kmldata' ).length ) {
    if ($("div.kmldata").length) {
            require_wikiminiatlas = true;
      require_wikiminiatlas = true;
        }
    }
        if ( require_wikiminiatlas ) {
    if (require_wikiminiatlas) {
            mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
      mw.loader.load("//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript");
        }
    }
    } );
  });
} )();
})();


/**
/**
  * قراردادن فرمول‌های ریاضی در سمت چپ مناسب برای ویکی‌های راست به چپ
  * Source codes pages direction and and pre white-space
  */
  */
$(function(){
mw.loader.using(["mediawiki.util"], function() {
$("img.tex, span.texhtml").each(function () {
  if ([2, 4, 8].indexOf(mw.config.get("wgNamespaceNumber")) !== -1) {
if ($(this).parent().text().trim() === $(this).text() && $(this).parent().is("p, dd")) {
    if (/\.(js|css|py)$/.test(mw.config.get("wgPageName"))) {
$(this).parent().css({
      mw.util.addCSS(".diff-addedline, .diff-deletedline, .diff-context { direction: ltr; } " +
direction: 'ltr',
        "#wpTextbox1 { direction: ltr; }");
padding: '1em 0'
    }
});
  }
}
 
});
  // Newbies are misusing wikilove instead using talk pages add new section
  // hiding WikiLove from not autoconfirmed users or without more than 100 edits
  if ($.inArray("autoconfirmed", mw.config.get("wgUserGroups")) === -1 || mw.config.get("wgUserEditCount") < 100) {
    mw.util.addCSS("#ca-wikilove { display: none; }");
  }
});
});
/**
/**
  * Source codes pages direction and and pre white-space
  * قراردادن فرمول‌های ریاضی در سمت چپ مناسب برای ویکی‌های راست به چپ
  */
  */
if ([2, 4, 8].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) {
$(function() {
if (/\.(js|css|py)$/.test(mw.config.get('wgPageName'))) {
  $("span.mwe-math-mathml-inline").each(function() {
mw.util.addCSS('.diff-addedline, .diff-deletedline, .diff-context { direction: ltr; } ' +
    if ($(this).parent().parent().text().trim() === $(this).parent().text().trim() && $(this).parent().parent().is("p, dd")) {
'#wpTextbox1 { direction: ltr; }');
      $(this).parent().parent().css({
}
        direction: "ltr",
}
        padding: "1em 0"
      });
    }
  });
});


// Newbies are misusing wikilove instead using talk pages add new section
// هشدار به کاربرها در مورد عنوان ایمیل
// hiding WikiLove from not autoconfirmed users or without more than 100 edits
$(function() {
if ($.inArray('autoconfirmed', mw.config.get('wgUserGroups')) === -1 || mw.config.get('wgUserEditCount') < 100) {
  if ( $('#mw-input-wpSubject').parents('tr').length > 0 ) {
mw.util.addCSS('#ca-wikilove { display: none; }');
    $('#mw-input-wpSubject').parents('tr').before('<tr><td></td><td style="color: red; font-weight: bold">لطفاً عبارت Wikipedia e-mail ‌را با یک عنوان مناسب جایگزین کنید!</td><tr>');
}
  }
});


// Hiding Sandbox pages in content categories, temp. workaround
// Make refrence number that you clicked on bold for proper navigation
$(function () {
// Author: User:Ladsgroup
if (mw.config.get('wgNamespaceNumber') === 14 && (mw.config.get('wgPageName').search(/ویکی|نامزد_حذف_سریع/i) === -1)) {
$( 'sup.reference' ).click( function () {
    $('ul li > a[title$="/صفحه تمرین"]').parent().hide();
    var citeId = $( this ).attr( 'id' );
}
    $( 'sup > a[href="#' + citeId + '"]').css('color', '#2a4b8d').css('font-weight', 'bold');
});
    $( 'sup > a[href="#' + citeId + '"]').click( function() {
        $( this ).css('color', '').css('font-weight', '');
    } );
} );

نسخهٔ ‏۱۶ مارس ۲۰۱۹، ساعت ۱۰:۰۳

/* global mw, $ */
// Editing-related javascripts
if (mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" || mw.config.get("wgCanonicalSpecialPageName") === "Upload") {
  /* scripts specific to editing pages */
  importScript("مدیاویکی:Common.js/edit.js");
}
/** Magic editintros ****************************************************
 *
 *  Description: Adds editintros on disambiguation pages and BLP pages.
 *  Maintainers: [[User:RockMFR]]
 */
function addEditIntro(name) {
  $(".mw-editsection, #ca-edit").find("a").each(function(i, el) {
    el.href = $(this).attr("href") + "&editintro=" + name;
  });
}

if (mw.config.get("wgNamespaceNumber") === 0) {
  $(function() {
    if (document.getElementById("disambigbox")) {
      addEditIntro("Template:Disambig_editintro");
    }
  });

  $(function() {
    var cats = mw.config.get("wgCategories");
    if (!cats) {
      return;
    }
    if ($.inArray("افراد زنده", cats) !== -1) {
      addEditIntro("Template:BLP_editintro");
    }
  });
}

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util', 'mediawiki.notify'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		// DONT REMOVE THIS IF (unless you are OK with CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		// DONT REMOVE THIS IF (unless you are OK with XSS & CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}
});

/**
 * Opening preload.js to add interactive training keys
 */
mw.loader.using(["mediawiki.util"], function() {
  if (mw.util.getParamValue("preload")) {
    importScript("MediaWiki:Preloaded.js");
  }
});

/** 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 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 [[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);

/** Main Page layout fixes *********************************************************
 *
 *  Description: Adds an additional link to the complete list of languages available.
 *  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
 */
mw.loader.using(["mediawiki.util"], function() {
  if (["صفحهٔ_اصلی", "بحث:صفحه_اصلی"].indexOf(mw.config.get("wgPageName")) !== -1) {
    $(function() {
      mw.util.addPortletLink("p-lang", "//meta.wikimedia.org/wiki/List_of_Wikipedias/fa", "فهرست کامل", "interwiki-completelist", "فهرست کامل");
    });
  }
});

/**
 * WikiMiniAtlas
 *
 * Description: WikiMiniAtlas is a popup click and drag world map.
 *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
 *              The script itself is located on meta because it is used by many projects.
 *              See [[Meta:WikiMiniAtlas]] for more information.
 * Maintainers: [[User:Dschwen]]
 */
(function() {
  var require_wikiminiatlas = false;
  var coord_filter = /geohack/;
  $(function() {
    $("a.external.text").each(function(key, link) {
      if (link.href && coord_filter.exec(link.href)) {
        require_wikiminiatlas = true;
        // break from loop
        return false;
      }
    });
    if ($("div.kmldata").length) {
      require_wikiminiatlas = true;
    }
    if (require_wikiminiatlas) {
      mw.loader.load("//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript");
    }
  });
})();

/**
 * Source codes pages direction and and pre white-space 
 */
mw.loader.using(["mediawiki.util"], function() {
  if ([2, 4, 8].indexOf(mw.config.get("wgNamespaceNumber")) !== -1) {
    if (/\.(js|css|py)$/.test(mw.config.get("wgPageName"))) {
      mw.util.addCSS(".diff-addedline, .diff-deletedline, .diff-context { direction: ltr; } " +
        "#wpTextbox1 { direction: ltr; }");
    }
  }

  // Newbies are misusing wikilove instead using talk pages add new section
  // hiding WikiLove from not autoconfirmed users or without more than 100 edits
  if ($.inArray("autoconfirmed", mw.config.get("wgUserGroups")) === -1 || mw.config.get("wgUserEditCount") < 100) {
    mw.util.addCSS("#ca-wikilove { display: none; }");
  }
});
/**
 * قراردادن فرمول‌های ریاضی در سمت چپ مناسب برای ویکی‌های راست به چپ
 */
$(function() {
  $("span.mwe-math-mathml-inline").each(function() {
    if ($(this).parent().parent().text().trim() === $(this).parent().text().trim() && $(this).parent().parent().is("p, dd")) {
      $(this).parent().parent().css({
        direction: "ltr",
        padding: "1em 0"
      });
    }
  });
});

// هشدار به کاربرها در مورد عنوان ایمیل
$(function() {
  if ( $('#mw-input-wpSubject').parents('tr').length > 0 ) {
    $('#mw-input-wpSubject').parents('tr').before('<tr><td></td><td style="color: red; font-weight: bold">لطفاً عبارت Wikipedia e-mail ‌را با یک عنوان مناسب جایگزین کنید!</td><tr>');
  }
});

// Make refrence number that you clicked on bold for proper navigation
// Author: User:Ladsgroup
$( 'sup.reference' ).click( function () {
    var citeId = $( this ).attr( 'id' );
    $( 'sup > a[href="#' + citeId + '"]').css('color', '#2a4b8d').css('font-weight', 'bold');
    $( 'sup > a[href="#' + citeId + '"]').click( function() {
        $( this ).css('color', '').css('font-weight', '');
    } );
} );