MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
Line 11: Line 11:
     gridContainer.style.gridTemplateColumns = 'repeat(2, 1fr)';
     gridContainer.style.gridTemplateColumns = 'repeat(2, 1fr)';
     gridContainer.style.gap = '14px';
     gridContainer.style.gap = '14px';
     // Collect the 8 category hero cards by their hero div IDs
     // Collect cards by hero IDs
     var heroIds = ['ax-sexual-health-hero','ax-dating-hero','ax-kink-hero','ax-culture-hero','ax-fashion-hero'];
     var heroIds = ['ax-sexual-health-hero','ax-dating-hero','ax-kink-hero','ax-culture-hero','ax-fashion-hero'];
    // Also collect the non-hero category cards (Community, Drugs, Life Planning)
    // They follow the hero cards in the DOM
     var allKnowledgeCards = [];
     var allKnowledgeCards = [];
     heroIds.forEach(function(id) {
     heroIds.forEach(function(id) {
Line 20: Line 18:
       if (h) { var c = h.closest('.ax-card'); if (c) allKnowledgeCards.push(c); }
       if (h) { var c = h.closest('.ax-card'); if (c) allKnowledgeCards.push(c); }
     });
     });
     // Find remaining category cards (no hero) - they are siblings after the grid
     // Find remaining 3 knowledge cards by keyword match (Community, Drugs, Life Planning)
     var parent = gridContainer.parentElement;
    // These have no hero images. Identify by checking they are NOT Start Learning or Featured
     Array.from(parent.querySelectorAll('.ax-card')).forEach(function(c) {
     var keywords = ['Community & Identity', 'Drugs, Party Culture', 'Life Planning'];
       if (allKnowledgeCards.indexOf(c) < 0) {
     Array.from(document.querySelectorAll('.ax-card')).forEach(function(c) {
        var heroInside = c.querySelector('[id*="-hero"]');
       if (allKnowledgeCards.indexOf(c) >= 0) return;
         if (!heroInside) allKnowledgeCards.push(c);
      var txt = c.innerText || '';
       }
      keywords.forEach(function(kw) {
         if (txt.indexOf(kw) >= 0 && allKnowledgeCards.indexOf(c) < 0) {
          allKnowledgeCards.push(c);
        }
       });
     });
     });
     // Move all 8 cards into the grid container
     // Move all knowledge cards into grid
     allKnowledgeCards.forEach(function(c) {
     allKnowledgeCards.forEach(function(c) {
       if (c.parentElement !== gridContainer) gridContainer.appendChild(c);
       if (c.parentElement !== gridContainer) gridContainer.appendChild(c);