MediaWiki:Common.js

De la The Spiritual Training for Business Romania & EU
Sari la navigare Sari la căutare

Notă: După publicare, trebuie să treceți peste memoria cache a navigatorului pentru a putea vedea modificările:

  • Firefox / Safari: Țineți apăsat pe Shift în timp ce faceți clic pe Reîncărcare ori apăsați Ctrl-F5 sau Ctrl-R (⌘-R pe un sistem Mac);
  • Google Chrome: Apăsați Ctrl-Shift-R (⌘-Shift-R pe un sistem Mac);
  • Internet Explorer / Edge: Țineți apăsat pe Ctrl în timp ce faceți clic pe Reîmprosptare sau apăsați Ctrl-F5;
  • Opera: Apăsați Ctrl-F5.
/* Adaptare pentru ecrane înguste; fără modificări de conținut sau date. */
(function () {
  'use strict';
  function adaptViewport() {
    var viewport = document.querySelector('meta[name="viewport"]');
    if (viewport && /^width=1000(?:,|$)/.test(viewport.getAttribute('content') || '')) {
      viewport.setAttribute('content', 'width=device-width, initial-scale=1');
    }
  }
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', adaptViewport);
  } else {
    adaptViewport();
  }
}());

/* Căutare locală în bibliotecă: nu stochează și nu transmite căutările. */
(function () {
  'use strict';
  function setupLibrary() {
    var host = document.getElementById('tst-library-controls');
    var content = document.querySelector('.tst-library-content');
    if (!host || !content || host.children.length) return;
    var searchLabel = document.createElement('label');
    searchLabel.textContent = 'Caută un titlu / Find a title';
    var search = document.createElement('input');
    search.type = 'search'; search.placeholder = 'Ex.: geometrie, meditație, business';
    searchLabel.appendChild(search);
    var langLabel = document.createElement('label');
    langLabel.textContent = 'Limba / Language';
    var language = document.createElement('select');
    [['all','Toate / All'],['RO','Română'],['EN','English']].forEach(function(pair) {
      var option = document.createElement('option'); option.value = pair[0]; option.textContent = pair[1]; language.appendChild(option);
    });
    langLabel.appendChild(language);
    var reset = document.createElement('button'); reset.type = 'button'; reset.textContent = 'Arată tot / Show all';
    var count = document.createElement('p'); count.setAttribute('role','status'); count.setAttribute('aria-live','polite');
    host.appendChild(searchLabel); host.appendChild(langLabel); host.appendChild(reset); host.appendChild(count);
    var sections = Array.prototype.slice.call(content.querySelectorAll('.tst-library-section'));
    var items = Array.prototype.slice.call(content.querySelectorAll('li'));
    function normalise(text) { return text.normalize('NFD').replace(/[̀-ͯ]/g,'').toLowerCase(); }
    function filter() {
      var query = normalise(search.value.trim()); var shown = 0;
      items.forEach(function(item) {
        var text = item.textContent; var marker = text.split('—').pop().trim();
        var languageMatch = language.value === 'all' || !/^(RO|EN)/.test(marker) || marker.indexOf(language.value) !== -1;
        var match = normalise(text).indexOf(query) !== -1 && languageMatch;
        item.hidden = !match; if (match) shown++;
      });
      sections.forEach(function(section) { section.hidden = !Array.prototype.some.call(section.querySelectorAll('li'),function(item) { return !item.hidden; }); });
      count.textContent = shown ? shown + ' / ' + items.length + ' legături afișate · links shown' : 'Niciun rezultat. Încearcă un alt cuvânt sau „Arată tot”. / No results. Try another word or Show all.';
    }
    search.addEventListener('input',filter); language.addEventListener('change',filter);
    reset.addEventListener('click',function() { search.value=''; language.value='all'; filter(); search.focus(); });
    filter();
  }
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded',setupLibrary); else setupLibrary();
}());