From 44a2e60b4f7030a06471a03699e2a167875f250e Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Thu, 12 May 2016 19:22:51 +0000 Subject: Bug 1270295 - don't update timestamps when the tab is not active / in the background --- .../BugModal/template/en/default/bug_modal/header.html.tmpl | 1 + extensions/BugModal/web/bug_modal.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'extensions') diff --git a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl index 84efbd077..48064f06c 100644 --- a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl @@ -60,6 +60,7 @@ jquery.push( "datetimepicker", "contextMenu", + "visibility" ); style_urls.push( "extensions/BugModal/web/bug_modal.css", diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index e0ef40a13..6c10c6fb0 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -51,7 +51,16 @@ $(function() { 'use strict'; // update relative dates - window.setInterval(function() { + var relative_timer_duration = 60000; + var relative_timer_id = window.setInterval(relativeTimer, relative_timer_duration); + $(document).on('show.visibility', function() { + relative_timer_id = window.setInterval(relativeTimer, relative_timer_duration) + }); + $(document).on('hide.visibility', function() { + window.clearInterval(relative_timer_id); + }); + + function relativeTimer() { var now = Math.floor(new Date().getTime() / 1000); $('.rel-time').each(function() { $(this).text(timeAgo(now - $(this).data('time'))); @@ -59,7 +68,7 @@ $(function() { $('.rel-time-title').each(function() { $(this).attr('title', timeAgo(now - $(this).data('time'))); }); - }, 60000); + } // all keywords for autocompletion (lazy-loaded on edit) var keywords = []; -- cgit v1.2.3-24-g4f1b