You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2018/02/21 21:31:03 UTC

[GitHub] janpio closed pull request #86: CB-7847 Page Visibility API should be supported

janpio closed pull request #86: CB-7847 Page Visibility API should be supported
URL: https://github.com/apache/cordova-js/pull/86
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/common/init.js b/src/common/init.js
index 758544eb..e6160649 100644
--- a/src/common/init.js
+++ b/src/common/init.js
@@ -24,6 +24,7 @@ var cordova = require('cordova');
 var modulemapper = require('cordova/modulemapper');
 var platform = require('cordova/platform');
 var pluginloader = require('cordova/pluginloader');
+var utils = require('cordova/utils');
 
 var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
 
@@ -90,6 +91,19 @@ channel.onPause = cordova.addDocumentEventHandler('pause');
 channel.onResume = cordova.addDocumentEventHandler('resume');
 channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
 
+// We Replace the default visibilityState to make it accessible for us
+var _visibilityState = 'visible';
+function setVisibilityState() {
+    _visibilityState = this; 
+    cordova.fireDocumentEvent('visibilitychange');  
+}
+utils.defineGetter(document, 'visibilityState', function () {
+    return _visibilityState;
+});
+
+channel.onPause.subscribe(setVisibilityState, 'hidden');
+channel.onResume.subscribe(setVisibilityState, 'visible');
+
 // Listen for DOMContentLoaded and notify our channel subscribers.
 if (document.readyState == 'complete' || document.readyState == 'interactive') {
     channel.onDOMContentLoaded.fire();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org