prevent incorrect removal of form submission buttons

...by guarding against overflow of a setTimeout delay
pull/1/head
ansuz 3 years ago
parent 5f32a38f3e
commit f80aacc177

@ -2784,6 +2784,11 @@ define([
var endDateEl = h('div.alert.alert-warning.cp-burn-after-reading'); var endDateEl = h('div.alert.alert-warning.cp-burn-after-reading');
var endDate; var endDate;
var endDateTo; var endDateTo;
// numbers greater than this overflow the maximum delay for a setTimeout
// which results in it being executed immediately (oops)
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#maximum_delay_value
var MAX_TIMEOUT_DELAY = 2147483647;
var refreshEndDateBanner = function (force) { var refreshEndDateBanner = function (force) {
if (APP.isEditor) { return; } if (APP.isEditor) { return; }
var _endDate = content.answers.endDate; var _endDate = content.answers.endDate;
@ -2804,10 +2809,21 @@ define([
APP.isClosed = endDate && endDate < (+new Date()); APP.isClosed = endDate && endDate < (+new Date());
clearTimeout(endDateTo); clearTimeout(endDateTo);
if (!APP.isClosed && endDate) { if (!APP.isClosed && endDate) {
setTimeout(function () { // calculate how many ms in the future the poll will be closed
var diff = (endDate - +new Date() + 100);
// if that value would overflow, then check again in a day
// (if the tab is still open)
if (diff > MAX_TIMEOUT_DELAY) {
endDateTo = setTimeout(function () {
refreshEndDateBanner(true);
}, 1000 * 3600 * 24);
return;
}
endDateTo = setTimeout(function () {
refreshEndDateBanner(true); refreshEndDateBanner(true);
$('.cp-form-send-container').find('.cp-open').remove(); $('.cp-form-send-container').find('.cp-open').hide();
},(endDate - +new Date() + 100)); }, diff);
} }
}; };

Loading…
Cancel
Save