diff options
author | David Lawrence <dkl@mozilla.com> | 2016-05-12 21:22:51 +0200 |
---|---|---|
committer | David Lawrence <dkl@mozilla.com> | 2016-05-12 21:22:51 +0200 |
commit | 44a2e60b4f7030a06471a03699e2a167875f250e (patch) | |
tree | 31feaf091280d583fe043ae693a709df508600e7 | |
parent | 6a48e0211dec6ec2d5a73ad1982682b744fb3474 (diff) | |
download | bugzilla-44a2e60b4f7030a06471a03699e2a167875f250e.tar.gz bugzilla-44a2e60b4f7030a06471a03699e2a167875f250e.tar.xz |
Bug 1270295 - don't update timestamps when the tab is not active / in the background
-rw-r--r-- | extensions/BugModal/template/en/default/bug_modal/header.html.tmpl | 1 | ||||
-rw-r--r-- | extensions/BugModal/web/bug_modal.js | 13 | ||||
-rw-r--r-- | js/jquery/plugins/visibility/visibility-min.js | 2 |
3 files changed, 14 insertions, 2 deletions
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 = []; diff --git a/js/jquery/plugins/visibility/visibility-min.js b/js/jquery/plugins/visibility/visibility-min.js new file mode 100644 index 000000000..e47b5c808 --- /dev/null +++ b/js/jquery/plugins/visibility/visibility-min.js @@ -0,0 +1,2 @@ +/*! jquery-visibility v1.0.12 | MIT license | http://mths.be/visibility */ +!function(e,i){"function"==typeof define&&define.amd?define(["jquery"],function(t){return i(e,t)}):"object"==typeof exports?module.exports=i(e,require("jquery")):i(e,jQuery)}("undefined"!=typeof window?window:this,function(e,i,t){"use strict";function n(){"hidden"!==o&&(r.hidden=s.pageVisibility?r[o]:t)}for(var o,u,r=e.document,f=["webkit","o","ms","moz",""],s=i.support||{},d=("onfocusin"in r&&"hasFocus"in r?"focusin focusout":"focus blur");(u=f.pop())!==t;)if(o=(u?u+"H":"h")+"idden",s.pageVisibility=r[o]!==t,s.pageVisibility){d=u+"visibilitychange";break}n(),i(/blur$/.test(d)?e:r).on(d,function(e){var u=e.type,f=e.originalEvent;if(f){var s=f.toElement;(!/^focus./.test(u)||s===t&&f.fromElement===t&&f.relatedTarget===t)&&i(r).triggerHandler(o&&r[o]||/^(?:blur|focusout)$/.test(u)?"hide":"show"),n()}})}); |