MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| 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 | ||
var SHOW_RETRIEVAL_DATE = | // 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,003: | 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,214: | 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,519: | 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){ | ||