MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 948: | 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,000: | 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 | 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,023: | 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,204: | Line 1,234: | ||
// in a sentence, but it copies on click rather than earning a | // in a sentence, but it copies on click rather than earning a | ||
// button of its own. | // 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-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"' | ||
| Line 1,509: | Line 1,542: | ||
if ($(e.target).hasClass('gra-bookmark-del')) return; | if ($(e.target).hasClass('gra-bookmark-del')) return; | ||
if ($(e.target).hasClass('gra-cite-copy')) return; | if ($(e.target).hasClass('gra-cite-copy')) return; | ||
var id = $(this).attr('data-gra-id'); | var id = $(this).attr('data-gra-id'); | ||
if (id) { closePanel(); scrollToHighlight(id); } | if (id) { closePanel(); scrollToHighlight(id); } | ||
}); | }); | ||
$paneBookmarks.on('click', '.gra-cite-copy', function(e){ | $paneBookmarks.on('click', '.gra-cite-copy', function(e){ | ||