MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
Line 1,728: Line 1,728:
                             if (g.authorIAST) el.setAttribute('data-cite-author-iast', g.authorIAST);
                             if (g.authorIAST) el.setAttribute('data-cite-author-iast', g.authorIAST);
                             var h = el.querySelector('.teeka-title');
                             var h = el.querySelector('.teeka-title');
                             if (h && g.name) h.textContent = g.name;
                            var label = teekaLabel(g);
                             if (h && label) h.textContent = label;
                            var slug = el.getAttribute('data-teeka-slug');
                            if (slug && label) {
                                labelBySlug[slug] = label;
                                // A footnote section for this commentary may
                                // already be on screen; rename it too.
                                document.querySelectorAll(
                                    '.gr-teeka-notes-group[data-teeka-slug="' + slug +
                                    '"] .gr-teeka-notes-title').forEach(function (t) {
                                        t.textContent = label;
                                    });
                            }
                         });
                         });
                     }($entry[0], entry.teekaGranthaId, entry.teekaPage));
                     }($entry[0], entry.teekaGranthaId, entry.teekaPage));
Line 3,007: Line 3,019:
             var h = document.createElement('div');
             var h = document.createElement('div');
             h.className = 'gr-teeka-notes-title';
             h.className = 'gr-teeka-notes-title';
             h.textContent = g.title || g.slug;
             h.textContent = (window.grLibrary && window.grLibrary.labelFor(g.slug))
                            || g.title || g.slug;
             wrap.appendChild(h);
             wrap.appendChild(h);
             var ol = document.createElement('ol');
             var ol = document.createElement('ol');
Line 3,336: Line 3,349:
             return lookup(gid).then(function (g) {
             return lookup(gid).then(function (g) {
                 if (!g) return;
                 if (!g) return;
                // On a commentary's own page the heading still reads as the
                // docx colophon ("...विरचिता प्रकाशिका"). Name it the way the
                // blocks are named instead.
                if (t.getAttribute('data-parent-doc')) {
                    var lab = teekaLabel(g);
                    if (lab) t.textContent = lab;
                } else if (g.name) {
                    t.textContent = g.name;
                }
                 if (g.name)      t.setAttribute('data-doc-title', g.name);
                 if (g.name)      t.setAttribute('data-doc-title', g.name);
                 if (g.nameIAST)  t.setAttribute('data-doc-title-iast', g.nameIAST);
                 if (g.nameIAST)  t.setAttribute('data-doc-title-iast', g.nameIAST);
Line 3,379: Line 3,401:
             return out;
             return out;
         });
         });
    }
    // How a commentary is named on screen: its author, then the work.
    // "श्रीवादिराजतीर्थः: काठकोपनिषद्भाष्यप्रकाशिका" - because several
    // commentaries on one moola share a work-type name (प्रकाशिका,
    // विवरणम्, खण्डार्थः), and the author is what actually tells them
    // apart for a reader scanning down the page.
    var labelBySlug = {};
    function teekaLabel(g) {
        if (!g) return '';
        var name = g.name || g.nameIAST || '';
        var author = g.author || g.authorIAST || '';
        if (!author || !name) return name || author;
        // Nothing to prefix if the work already opens with the author.
        if (name.indexOf(author) === 0) return name;
        return author + ': ' + name;
     }
     }


Line 3,420: Line 3,458:
     window.grLibraryVersion = '2026-09-30a';
     window.grLibraryVersion = '2026-09-30a';
     window.grLibrary = { lookup: lookup, lookupMany: lookupMany, catalogue: catalogue,
     window.grLibrary = { lookup: lookup, lookupMany: lookupMany, catalogue: catalogue,
                        teekaLabel: teekaLabel,
                        labelFor: function (slug) { return labelBySlug[slug] || ''; },
                         idForPage: idForPage, map: granthaMap, api: API,
                         idForPage: idForPage, map: granthaMap, api: API,
                         relabelDocLinks: relabelDocLinks };
                         relabelDocLinks: relabelDocLinks };