From 2ac87ba839e4ed7847a9d411cfa9d5c237d7d2ae Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Sun, 15 Mar 2020 13:32:10 -0700 Subject: [PATCH] Remove usage of setInterval (#4481) * Migrate from setInterval to setTimeout, fixes #4480 * Add fail case --- web/assets/javascripts/application.js | 35 +++++++++++++++------------ 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/web/assets/javascripts/application.js b/web/assets/javascripts/application.js index 75b260ea..a34198b1 100644 --- a/web/assets/javascripts/application.js +++ b/web/assets/javascripts/application.js @@ -19,7 +19,8 @@ Sidekiq = {}; $(function() { var pollpath = $('body').data('poll-path'); if (pollpath != "") { - updatePage(pollpath); + var ti = parseInt(localStorage.timeInterval) || 2000; + setTimeout(function(){updatePage(pollpath)}, ti); } $(document).on('click', '.check_all', function() { @@ -55,26 +56,28 @@ function updateFuzzyTimes(locale) { } function updatePage(url) { - setInterval(function () { - $.ajax({ - url: url, - dataType: 'html' - }).done(function (data) { - $data = $(data) + $.ajax({ + url: url, + dataType: 'html' + }).done(function(data) { + $data = $(data) - var $page = $data.filter('#page') - $('#page').replaceWith($page) + var $page = $data.filter('#page') + $('#page').replaceWith($page) - var $header_status = $data.find('.status') - $('.status').replaceWith($header_status) + var $header_status = $data.find('.status') + $('.status').replaceWith($header_status) - updateFuzzyTimes($('body').data('locale')); - }) - }, parseInt(localStorage.timeInterval) || 2000); + updateFuzzyTimes($('body').data('locale')); + + var ti = parseInt(localStorage.timeInterval) || 2000; + setTimeout(function(){updatePage(url)}, ti) + }).fail(function() { + var ti = parseInt(localStorage.timeInterval) || 2000; + setTimeout(function(){updatePage(url)}, ti) + }) } - - $(function() { 'use strict';