MediaWiki:Common.js: Difference between revisions
Soldier facts editor: remove education/marital/occupation fields |
Add Internet Archive click-to-play embeds for interview watchlist |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 711: | Line 711: | ||
ev.preventDefault(); | ev.preventDefault(); | ||
playAviary($slot, mediaId, title); | playAviary($slot, mediaId, title); | ||
}); | |||
}); | |||
}()); | |||
(function buildInternetArchiveEmbeds() { | |||
// archive.org item identifiers (e.g. RobertA.Potash13january2012YiddishBookCenter) | |||
var IA_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{5,120}$/; | |||
function playInternetArchive($slot, itemId, title) { | |||
var src = 'https://archive.org/embed/' + encodeURIComponent(itemId); | |||
var $iframe = $('<iframe class="ia-embed-frame" allowfullscreen allow="autoplay; encrypted-media; fullscreen; picture-in-picture"></iframe>') | |||
.attr({ | |||
src: src, | |||
title: title || 'Internet Archive media', | |||
loading: 'lazy' | |||
}); | |||
$slot.empty().append($iframe).addClass('ia-embed-playing'); | |||
} | |||
$('.mw-parser-output .ia-embed[data-archive-id]').each(function () { | |||
var $slot = $(this); | |||
if ($slot.data('rbIaEmbed')) { | |||
return; | |||
} | |||
var itemId = String($slot.attr('data-archive-id') || ''); | |||
if (!IA_ID.test(itemId)) { | |||
return; | |||
} | |||
$slot.data('rbIaEmbed', 1); | |||
var title = String($slot.attr('data-title') || 'Internet Archive media'); | |||
var playLabel = String($slot.attr('data-play-label') || 'Play interview'); | |||
var $fallback = $slot.find('.ia-embed-fallback').first(); | |||
var $btn = $('<button type="button" class="ia-embed-play"></button>') | |||
.attr('aria-label', playLabel + ' — ' + title) | |||
.append($('<span class="ia-embed-play-icon" aria-hidden="true"></span>')) | |||
.append($('<span class="ia-embed-play-text"></span>').text(playLabel)); | |||
var $poster = $('<div class="ia-embed-poster"></div>').append($btn); | |||
if ($fallback.length) { | |||
$fallback.before($poster); | |||
$fallback.hide(); | |||
} else { | |||
$slot.prepend($poster); | |||
} | |||
$poster.on('click', function (ev) { | |||
ev.preventDefault(); | |||
playInternetArchive($slot, itemId, title); | |||
}); | }); | ||
}); | }); | ||
| Line 1,383: | Line 1,429: | ||
{ key: 'death_year', label: 'Death year', hint: 'Four digits, e.g. 2001' }, | { key: 'death_year', label: 'Death year', hint: 'Four digits, e.g. 2001' }, | ||
{ key: 'nativity', label: 'Nativity (birthplace)' }, | { key: 'nativity', label: 'Nativity (birthplace)' }, | ||
{ key: 'religion', label: 'Religion | { key: 'religion', label: 'Religion' } | ||
] | ] | ||
}, | }, | ||
| Line 1,406: | Line 1,451: | ||
collapsed: true, | collapsed: true, | ||
fields: [ | fields: [ | ||
{ key: 'other_class', label: 'Other class' }, | { | ||
key: 'other_class', | |||
label: 'Other class', | |||
hint: 'Roster code, e.g. SC8, DC36, MITU4 (shown expanded on the page)' | |||
}, | |||
{ key: 'division', label: 'Unit / division' }, | { key: 'division', label: 'Unit / division' }, | ||
{ key: 'loc', label: 'LOC | { key: 'loc', label: 'LOC' } | ||
] | ] | ||
} | } | ||