From a6ee26f489dbcf2b3e2c2a37dbe61390d43f2cda Mon Sep 17 00:00:00 2001 From: Matt Lee Date: Thu, 5 Mar 2015 15:11:58 -0800 Subject: [PATCH] ads: Use visibilitychange event if supported. For loading new ads, use visibilitychange event if supported (it generally is). This means that, in theory, a new ad should load in one of the following cases: 1. Active tab changes. 2. Browser is minimized then maximized. 3. Browser window is covered up then uncovered. 4. OS goes to sleep/is locked then woken up/unlocked. This makes a lot more sense than the current trigger, which is just focus. Unfortunately support for cases 2-4 is spotty, but almost all browsers support case 1. --- r2/r2/public/static/js/spotlight.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/r2/r2/public/static/js/spotlight.js b/r2/r2/public/static/js/spotlight.js index 12dc7b82c..bcca76329 100644 --- a/r2/r2/public/static/js/spotlight.js +++ b/r2/r2/public/static/js/spotlight.js @@ -50,7 +50,15 @@ r.spotlight.setup = function(organic_links, interest_prob, show_promo, srnames) this.init() - $(window).on('focus', r.spotlight.requestNewPromo.bind(this)); + if ('hidden' in document) { + $(window).on('visibilitychange', function(e) { + if (!document.hidden) { + this.requestNewPromo(); + } + }.bind(this)); + } else { + $(window).on('focus', this.requestNewPromo.bind(this)); + } } r.spotlight.requestNewPromo = function() { -- 2.11.4.GIT