website/conservancy/static/js/conservancy.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

/* 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-07 00:46:34 +00:00
function qs (selector) {
return document.querySelector(selector);
}
function init () {
/* When the browser doesn't support any video source, replace it
with the HTML inside the <video> element. */
var showVideoInnerHTML = function(event) {
var video = event.target.parentNode;
var div = document.createElement('div');
div.classList = video.classList;
div.innerHTML = video.innerHTML;
video.parentNode.replaceChild(div, video);
}
$('video').each(function(index, video) {
$('source', video).last().on('error', showVideoInnerHTML);
});
$('input[name=on0]:radio').on('change', function(event, duration) {
2024-05-07 00:46:34 +00:00
var input = $(this);
var wantShirt = input.val() == "wantGiftYes";
var form = input.parents('form').last();
var tShirtSelector = $('.t-shirt-size-selector', form);
$('input', tShirtSelector).prop('disabled', wantShirt);
$('input[name=no_shipping]', form).val(wantShirt ? '2' : '0');
if (wantShirt) {
2024-05-07 00:46:34 +00:00
tShirtSelector.slideDown(duration);
} else {
2024-05-07 00:46:34 +00:00
tShirtSelector.slideUp(duration);
}
}).filter(':checked').trigger('change', 0);
// Open mobile/search menu.
2024-05-07 00:46:34 +00:00
qs('#menu-icon').addEventListener('click', function(event) {
qs('#navbar').classList.toggle('mobile');
});
2024-05-07 00:46:34 +00:00
qs('#search-icon').addEventListener('click', function(event) {
qs('#navbar').classList.toggle('mobile');
qs('#search-query').focus();
});
2024-05-07 00:46:34 +00:00
}
init();