2016-12-31 19:46:10 +00:00
|
|
|
/* Copyright (C) 2012-2013 Denver Gingerich,
|
|
|
|
** Copyright (C) 2013-2014 Bradley M. Kuhn,
|
|
|
|
** Copyright (C) 2016 Brett Smith.
|
|
|
|
** License: GPLv3-or-later
|
|
|
|
** Find a copy of GPL at https://sfconservancy.org/GPLv3
|
|
|
|
*/
|
|
|
|
|
2024-05-08 07:23:45 +00:00
|
|
|
'use strict';
|
2024-05-07 01:00:14 +00:00
|
|
|
|
2024-05-08 07:23:45 +00:00
|
|
|
function qs (selector, parent) {
|
2024-05-08 08:05:27 +00:00
|
|
|
return parent ? parent.querySelector(selector) : document.querySelector(selector);
|
2024-05-07 00:46:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 07:23:45 +00:00
|
|
|
function qsa (selector, parent) {
|
2024-05-08 08:05:27 +00:00
|
|
|
return parent ? parent.querySelectorAll(selector) : document.querySelectorAll(selector);
|
2024-05-08 07:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hide(el) {
|
|
|
|
el.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
function show(el) {
|
|
|
|
el.style.display = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function showVideoInnerHTML (event) {
|
|
|
|
let video = event.target.parentNode;
|
|
|
|
let div = document.createElement('div');
|
|
|
|
div.classList = video.classList;
|
|
|
|
div.innerHTML = video.innerHTML;
|
|
|
|
video.parentNode.replaceChild(div, video);
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleShirtSize (form) {
|
|
|
|
let wantShirt = form.elements['on0'].value === 'wantGiftYes';
|
2024-05-08 08:05:27 +00:00
|
|
|
let shirtSizeRow = qs('.t-shirt-size-selector', form);
|
|
|
|
let shirtSizeSelect = form.elements['os0'];
|
|
|
|
shirtSizeSelect.disabled = !wantShirt;
|
2024-05-08 07:23:45 +00:00
|
|
|
form.elements['no_shipping'].value = wantShirt ? '2' : '0';
|
|
|
|
if (wantShirt) {
|
2024-05-08 08:05:27 +00:00
|
|
|
show(shirtSizeRow);
|
2024-05-08 07:23:45 +00:00
|
|
|
} else {
|
2024-05-08 08:05:27 +00:00
|
|
|
hide(shirtSizeRow);
|
2016-12-31 20:19:59 +00:00
|
|
|
}
|
2024-05-07 00:46:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 07:23:45 +00:00
|
|
|
/* When the browser doesn't support any video source, replace it
|
|
|
|
with the HTML inside the <video> element. */
|
|
|
|
qsa('video').forEach(function(video, _index) {
|
|
|
|
let last_source = Array.from(qsa('source', video)).at(-1);
|
|
|
|
last_source.addEventListener('error', showVideoInnerHTML);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Hide the T-shirt size selector when not needed. */
|
|
|
|
qsa('.supporter-form').forEach(function(form) {
|
|
|
|
toggleShirtSize(form); // set initial state
|
|
|
|
form.addEventListener('change', () => toggleShirtSize(form));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Open mobile/search menu.
|
|
|
|
qs('#menu-icon').addEventListener('click', function(event) {
|
|
|
|
qs('#navbar').classList.toggle('mobile');
|
|
|
|
});
|
|
|
|
qs('#search-icon').addEventListener('click', function(event) {
|
|
|
|
qs('#navbar').classList.toggle('mobile');
|
|
|
|
qs('#search-query').focus();
|
|
|
|
});
|