MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
Line 843: Line 843:
   var apiBase = mw.util.wikiScript('api');
   var apiBase = mw.util.wikiScript('api');
   var allRows = [];
   var allRows = [];
  function getTableBody() {
    var table = document.getElementById('article-overview-table');
    if (!table) return null;
    var tb = table.querySelector('tbody');
    return tb;
  }


   // Inject the Download button and status span above the table
   // Inject the Download button and status span above the table
Line 850: Line 857:
     if (!wrapper || !table) return;
     if (!wrapper || !table) return;


     // Create controls div if it doesn't exist
     // Create or find controls div
     var controls = document.getElementById('article-overview-controls');
     var controls = document.getElementById('article-overview-controls');
     if (!controls) {
     if (!controls) {
Line 857: Line 864:
       controls.style.marginBottom = '14px';
       controls.style.marginBottom = '14px';
       wrapper.insertBefore(controls, table);
       wrapper.insertBefore(controls, table);
    } else {
      controls.style.marginBottom = '14px';
     }
     }


Line 899: Line 908:


   function renderTable(rows) {
   function renderTable(rows) {
     var tbody = document.getElementById('article-overview-body');
     var tbody = getTableBody();
     if (!tbody) return;
     if (!tbody) return;
     if (!rows || rows.length === 0) {
     if (!rows || rows.length === 0) {
Line 931: Line 940:


         if (totalCats === 0) {
         if (totalCats === 0) {
           var tbody = document.getElementById('article-overview-body');
           var tbody = getTableBody();
           if (tbody) tbody.innerHTML = '<tr><td colspan="5" style="padding:10px;text-align:center;color:#aaa;">No categories found.</td></tr>';
           if (tbody) tbody.innerHTML = '<tr><td colspan="5" style="padding:10px;text-align:center;color:#aaa;">No categories found.</td></tr>';
           if (status) status.textContent = '';
           if (status) status.textContent = '';
Line 989: Line 998:
       })
       })
       .fail(function() {
       .fail(function() {
         var tbody = document.getElementById('article-overview-body');
         var tbody = getTableBody();
         if (tbody) tbody.innerHTML = '<tr><td colspan="5" style="padding:10px;text-align:center;color:#f55;">Error loading data. Check API access.</td></tr>';
         if (tbody) tbody.innerHTML = '<tr><td colspan="5" style="padding:10px;text-align:center;color:#f55;">Error loading data. Check API access.</td></tr>';
       });
       });