«ميدياويكي:Common.js»: الفرق بين المراجعتين

(DSVGO)
 
(١٥ مراجعة متوسطة بواسطة ٣ مستخدمين غير معروضة)
سطر ١: سطر ١:
 
/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */
 
/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */
  
$('div#content').append( "<div class='content-footer'></div>" );
+
/* =====================================
 +
FUNCTIONS DECLARATION
 +
======================================== */
  
var autoCollapse = 2;
+
/* Favicon */
var collapseCaption = 'أخف';
+
function fixInsecureFavicon() {
var expandCaption = 'أظهر';
+
  document.querySelector('link[rel="shortcut icon"]').href = "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
+
}
function collapseTable( tableIndex ) {
+
 
        var Button = document.getElementById( 'collapseButton' + tableIndex );
+
/* TOP BUTTON */
        var Table = document.getElementById( 'collapsibleTable' + tableIndex );
+
function addButtonTop() {
+
 
        if ( !Table || !Button ) {
+
  var contentText = document.querySelector("div#mw-content-text");
                return false;
+
 
        }
+
  if (contentText !== null) {
+
   
        var Rows = Table.rows;
+
    var divButtonTop = document.createElement("div");
+
    divButtonTop.classList.add("top-button");
        if ( Button.firstChild.data == collapseCaption ) {
+
    contentText.appendChild(divButtonTop);
                for ( var i = 1; i < Rows.length; i++ ) {
+
  }
                        Rows[i].style.display = 'none';
+
}
                }
+
 
                Button.firstChild.data = expandCaption;
+
function buttonTop() {
 +
 
 +
  var balise = document.querySelector("div#mw-page-header-links");
 +
  var topButton = document.querySelector(".top-button");
 +
 
 +
  if (balise !== null) {
 +
    var options = {
 +
      root: null,
 +
      rootMargin: "0px",
 +
      threshold: 0,
 +
    };
 +
 
 +
    var observer = new IntersectionObserver(callback, options);
 +
    observer.observe(balise);
 +
 
 +
    function callback(entries) {
 +
      entries.forEach(function(entry) {
 +
        if (entry.isIntersecting) {
 +
          topButton.classList.remove("show-button");
 
         } else {
 
         } else {
                for ( var i = 1; i < Rows.length; i++ ) {
+
        topButton.classList.add("show-button");
                        Rows[i].style.display = Rows[0].style.display;
 
                }
 
                Button.firstChild.data = collapseCaption;
 
 
         }
 
         }
 +
      });
 +
    }
 +
 +
    topButton.addEventListener("click", function(){
 +
      document.documentElement.scrollTo({
 +
        top: 0
 +
      });
 +
    });
 +
  }
 
}
 
}
+
 
function createCollapseButtons() {
+
/* Cookies */
        var tableIndex = 0;
+
function cookies() {
        var NavigationBoxes = new Object();
 
        var Tables = document.getElementsByTagName( 'table' );
 
 
        for ( var i = 0; i < Tables.length; i++ ) {
 
                if ( hasClass( Tables[i], '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 [[MediaWiki:Common.css]]
 
 
                        ButtonLink.style.color = Header.style.color;
 
                        ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
 
                        ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
 
                        ButtonLink.appendChild( ButtonText );
 
 
                        Button.appendChild( document.createTextNode( '[' ) );
 
                        Button.appendChild( ButtonLink );
 
                        Button.appendChild( document.createTextNode( ']' ) );
 
 
                        Header.insertBefore( Button, Header.childNodes[0] );
 
                        tableIndex++;
 
                }
 
        }
 
 
        for ( var i = 0;  i < tableIndex; i++ ) {
 
                if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
 
                        collapseTable( i );
 
                } else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {
 
                        var element = NavigationBoxes[i];
 
                        while ( element = element.parentNode ) {
 
                                if ( hasClass( element, 'outercollapse' ) ) {
 
                                        collapseTable( i );
 
                                        break;
 
                                }
 
                        }
 
                }
 
        }
 
}
 
 
addOnloadHook( createCollapseButtons );
 
 
/** Test if an element has a certain class **************************************
 
*
 
* Description: Uses regular expressions and caching for better performance.
 
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[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 );
 
        };
 
})();
 
(function () {
 
 
     var req = new XMLHttpRequest();
 
     var req = new XMLHttpRequest();
 
     req.addEventListener('load', function (ev) {
 
     req.addEventListener('load', function (ev) {
سطر ١١٤: سطر ٧١:
 
     req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
 
     req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
 
     req.send();
 
     req.send();
 +
}
 +
 +
/* =======================================
 +
GLOBAL FUNCTION
 +
Executed once on page load
 +
========================================== */
 +
 +
(function(){
 +
  fixInsecureFavicon()
 +
 +
  var loadScripts = document.querySelectorAll("div[data-load-javascript]");
 +
 
 +
  /* Load specific scripts when loading certain pages */
 +
  if (loadScripts.length) {
 +
    var checkArray = new Array(0);
 +
    loadScripts.forEach(function(loadScript){
 +
      script = loadScript.dataset["loadJavascript"];
 +
      if (checkArray.indexOf(script) === -1) {
 +
        checkArray.push(script);
 +
        switch (script) {
 +
          case "tabber" :
 +
            mw.loader.load("/index.php?title=MediaWiki:Script/Tabber.js&action=raw&ctype=text/javascript");
 +
            break;
 +
          case "skills" : // charge le script pour utiliser le simulateur de compétence
 +
            mw.loader.load("/index.php?title=MediaWiki:Script/Skills.js&action=raw&ctype=text/javascript");
 +
            break;
 +
          case "modal" : // charge le script pour utiliser les modal
 +
            mw.loader.load("/index.php?title=MediaWiki:Script/Modal.js&action=raw&ctype=text/javascript");
 +
            break;
 +
          case "switch" : // charge le script pour utiliser les changements de contenu
 +
            mw.loader.load("/index.php?title=MediaWiki:Script/Switch.js&action=raw&ctype=text/javascript");
 +
            break;
 +
          case "loot" :
 +
            mw.loader.load("/index.php?title=MediaWiki:Script/Loot.js&action=raw&ctype=text/javascript");
 +
            break;
 +
          case "map" :
 +
            mw.loader.load("/index.php?title=MediaWiki:Script/map.js&action=raw&ctype=text/javascript");
 +
            break;
 +
        }
 +
      }
 +
    });
 +
  }
 +
 +
  addButtonTop();
 +
  buttonTop();
 +
  cookies()
 
})();
 
})();

المراجعة الحالية بتاريخ ١٦:٠٠، ٢٠ يناير ٢٠٢٣

/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */

/* =====================================
FUNCTIONS DECLARATION
======================================== */

/* Favicon */
function fixInsecureFavicon() {
  document.querySelector('link[rel="shortcut icon"]').href = "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
}

/* TOP BUTTON */
function addButtonTop() {
  
  var contentText = document.querySelector("div#mw-content-text");
  
  if (contentText !== null) {
    
    var divButtonTop = document.createElement("div");
    divButtonTop.classList.add("top-button");
    contentText.appendChild(divButtonTop);
  }
}

function buttonTop() {
  
  var balise = document.querySelector("div#mw-page-header-links");
  var topButton = document.querySelector(".top-button");
  
  if (balise !== null) {
    var options = {
      root: null,
      rootMargin: "0px",
      threshold: 0,
    };
  
    var observer = new IntersectionObserver(callback, options);
    observer.observe(balise);

    function callback(entries) {
      entries.forEach(function(entry) {
        if (entry.isIntersecting) {
          topButton.classList.remove("show-button");
        } else {
        topButton.classList.add("show-button");
        }
      });
    }

    topButton.addEventListener("click", function(){
      document.documentElement.scrollTo({
        top: 0
      });
    });
  }
}

/* Cookies */
function cookies() {
    var req = new XMLHttpRequest();
    req.addEventListener('load', function (ev) {
        if (this.status >= 200 && this.status < 300) {
            var data = JSON.parse(this.responseText);
            if (data.hasOwnProperty('version')) {
                var gdpr = document.createElement("script");
                gdpr.src = "https://s3-static.geo.gfsrv.net/cookiebanner/" + data.version + "/cookie.min.js";
                document.head.appendChild(gdpr);
            }
        }
    });
    req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
    req.send();
}

/* =======================================
GLOBAL FUNCTION
Executed once on page load
========================================== */

(function(){
  fixInsecureFavicon()

  var loadScripts = document.querySelectorAll("div[data-load-javascript]");
  
  /* Load specific scripts when loading certain pages */
  if (loadScripts.length) {
    var checkArray = new Array(0);
    loadScripts.forEach(function(loadScript){
      script = loadScript.dataset["loadJavascript"];
      if (checkArray.indexOf(script) === -1) {
        checkArray.push(script);
        switch (script) {
          case "tabber" :
            mw.loader.load("/index.php?title=MediaWiki:Script/Tabber.js&action=raw&ctype=text/javascript");
            break;
          case "skills" : // charge le script pour utiliser le simulateur de compétence
            mw.loader.load("/index.php?title=MediaWiki:Script/Skills.js&action=raw&ctype=text/javascript");
            break;
          case "modal" : // charge le script pour utiliser les modal
            mw.loader.load("/index.php?title=MediaWiki:Script/Modal.js&action=raw&ctype=text/javascript");
            break;
          case "switch" : // charge le script pour utiliser les changements de contenu
            mw.loader.load("/index.php?title=MediaWiki:Script/Switch.js&action=raw&ctype=text/javascript");
            break;
          case "loot" :
            mw.loader.load("/index.php?title=MediaWiki:Script/Loot.js&action=raw&ctype=text/javascript");
            break;
          case "map" :
            mw.loader.load("/index.php?title=MediaWiki:Script/map.js&action=raw&ctype=text/javascript");
            break;
        }
      }
    });
  }

  addButtonTop();
  buttonTop();
  cookies()
})();