MediaWiki:Gadget-GrAnnotations.js: Difference between revisions

No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 588: Line 588:
       '<button id="gra-toggle" aria-label="Notes">',
       '<button id="gra-toggle" aria-label="Notes">',
       '  <span class="gra-icon gra-icon-note" id="gra-toggle-icon" aria-hidden="true"></span>',
       '  <span class="gra-icon gra-icon-note" id="gra-toggle-icon" aria-hidden="true"></span>',
      '  <span id="gra-toggle-badge" aria-live="polite"></span>',
       '</button>',
       '</button>',
     ].join('') );
     ].join('') );
Line 949: Line 948:
   // which build of this gadget a page is actually running. Check with
   // which build of this gadget a page is actually running. Check with
   //  window.grAnnotationsVersion
   //  window.grAnnotationsVersion
  // APA 7 asks for a retrieval date only when the content is designed to
  // change and is not archived. These are settled texts with a fixed
  // structure, so the date is omitted. Set true to restore it.
  var SHOW_RETRIEVAL_DATE = false;
   window.grAnnotationsVersion = '2026-09-30a';
   window.grAnnotationsVersion = '2026-09-30a';


Line 1,001: Line 1,005:
   // Titles of standalone works are italicised, which only the HTML flavour
   // Titles of standalone works are italicised, which only the HTML flavour
   // of the clipboard can carry.
   // of the clipboard can carry.
  // The library records names with their honorifics and, often, a
  // parenthetical alias: "Śrīman Madhvācārya (Ānandatīrtha)". A reference
  // entry carries the name a reader would look up, so the honorific and
  // the alias come off - leaving "Madhvācārya". Only applied to the
  // romanised form; the Devanagari is left exactly as the library has it,
  // because there the honorific is fused to the name by sandhi
  // (श्रीमत् + आनन्दतीर्थः -> श्रीमदानन्दतीर्थः) and cannot be sliced off safely.
  var HONORIFIC_RE = /^(?:\u015br\u012b|\u015br\u012bman|\u015br\u012bmat|\u015br\u012bmad|sri|shri|sree)\s+/i;
  function citationAuthor(name) {
    var n = (name || '').trim();
    if (!/[A-Za-z]/.test(n)) return n;            // Devanagari - leave alone
    n = n.replace(/\s*\([^)]*\)\s*$/, '').trim();
    for (var i = 0; i < 3 && HONORIFIC_RE.test(n); i++) {
      n = n.replace(HONORIFIC_RE, '').trim();
    }
    return n || (name || '').trim();
  }
   function buildCitation(rec) {
   function buildCitation(rec) {
     var src    = rec.citeSource || {};
     var src    = rec.citeSource || {};
     var author = (src.author || '').trim();
     var author = citationAuthor(src.author);
     var title  = (src.title  || '').trim();
     var title  = (src.title  || '').trim();
     var anchor = rec.anchor || '';
     var anchor = rec.anchor || '';
Line 1,024: Line 1,046:
     }
     }


     var tail = ' Retrieved ' + retrieved + ', from ' + url;
    // APA 7 (section 9.16) asks for a retrieval date only when the content
    // is designed to change and is not archived. A wiki page can change, so
    // the date is defensible - but these are settled texts, and a reader may
    // reasonably prefer the shorter form. Set SHOW_RETRIEVAL_DATE to false
    // for: Author. (n.d.). Title. Site. URL
     var tail = SHOW_RETRIEVAL_DATE
        ? ' Retrieved ' + retrieved + ', from ' + url
        : ' ' + url;
     var reference = head + (showSite ? ' ' + site + '.' : '') + tail;
     var reference = head + (showSite ? ' ' + site + '.' : '') + tail;
     var referenceHtml = headHtml + (showSite ? ' ' + esc(site) + '.' : '')
     var referenceHtml = headHtml + (showSite ? ' ' + esc(site) + '.' : '') + ' '
         + ' Retrieved ' + esc(retrieved) + ', from '
         + (SHOW_RETRIEVAL_DATE ? 'Retrieved ' + esc(retrieved) + ', from ' : '')
         + '<a href="' + esc(url) + '">' + esc(url) + '</a>';
         + '<a href="' + esc(url) + '">' + esc(url) + '</a>';


Line 1,199: Line 1,228:
             + '<div class="gra-bookmark-name">'+esc(b.name)+'</div>'
             + '<div class="gra-bookmark-name">'+esc(b.name)+'</div>'
             + (b.quote ? '<div class="gra-bookmark-quote">'+esc(b.quote)+'</div>' : '')
             + (b.quote ? '<div class="gra-bookmark-quote">'+esc(b.quote)+'</div>' : '')
            // One button. The reference already carries the work, the
            // locator's page and the link, so a separate "copy link" only
            // asked the reader to decide something they don't need to.
            // The in-text form stays on the card because it is what goes
            // in a sentence, but it copies on click rather than earning a
            // button of its own.
            // Where in the text this sits, spelled out - "Adhyaya 3,
            // Mantra 4" rather than MUN_C03_V04. Not part of the citation
            // (APA keeps a locator out of the reference entry), so it is
            // set apart as a caption and is not included in the copy.
            + (cite.locatorSpelled || cite.locator
                ? '<div class="gra-bookmark-locator">'
                    + esc(cite.locatorSpelled || cite.locator) + '</div>'
                : '')
             + '<div class="gra-bookmark-cite">'+cite.referenceHtml+'</div>'
             + '<div class="gra-bookmark-cite">'+cite.referenceHtml+'</div>'
            + '<div class="gra-bookmark-intext">In text: '+esc(cite.inText)
            + (cite.locatorSpelled ? ' <span class="gra-cite-locator">('
                + esc(cite.locatorSpelled) + ')</span>' : '')
            + '</div>'
             + '<div class="gra-cite-actions">'
             + '<div class="gra-cite-actions">'
             + '<button type="button" class="gra-cite-copy" data-cite-what="reference"'
             + '<button type="button" class="gra-cite-copy" data-cite-what="reference"'
             + ' data-cite-id="'+esc(b.id)+'">Copy reference</button>'
             + ' data-cite-id="'+esc(b.id)+'">Copy citation</button>'
            + '<button type="button" class="gra-cite-copy" data-cite-what="inText"'
            + ' data-cite-id="'+esc(b.id)+'">Copy in-text</button>'
            + '<button type="button" class="gra-cite-copy" data-cite-what="url"'
            + ' data-cite-id="'+esc(b.id)+'">Copy link</button>'
             + '</div>'
             + '</div>'
             + '</div>'
             + '</div>'
Line 1,715: Line 1,750:
   // the panel without opening it — worth having now that notes can arrive
   // the panel without opening it — worth having now that notes can arrive
   // from another device.
   // from another device.
   function updateBadge() {
   // The count badge is gone. It sat on the round toggle, which clips its
    var n = _notes.length + _bookmarks.length;
  // own overflow to stay circular, so the badge was cut off on every side
    var $b = $('#gra-toggle-badge');
  // and told the reader nothing they could act on. Kept as a no-op so the
    if (!$b.length) return;
  // five call sites that report a change still read clearly.
    $b.text(n > 99 ? '99+' : String(n)).css('display', n ? 'block' : 'none');
  function updateBadge() { }
  }


}() );
}() );