You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/02/21 21:32:00 UTC

[jira] [Commented] (CB-7847) Page Visibility API should be supported

    [ https://issues.apache.org/jira/browse/CB-7847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16372045#comment-16372045 ] 

ASF GitHub Bot commented on CB-7847:
------------------------------------

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


> Page Visibility API should be supported
> ---------------------------------------
>
>                 Key: CB-7847
>                 URL: https://issues.apache.org/jira/browse/CB-7847
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: cordova-js
>    Affects Versions: 3.5.0
>            Reporter: Damien Antipa
>            Priority: Major
>             Fix For: 3.6.0
>
>
> If the browser supports the API currently, he may return a wrong value by accessing the visibilityState when the application went into pause mode. Imo the visibility API should be supported without breaking code relying on pause/resume. 
> http://www.w3.org/TR/page-visibility/#sec-visibilitychange-event
> I created a patch which relies on the fact that all platform code will handle pause/resume properly. It currently supports the visibilityState and the visibilitychange event. Missing parts of the spec are:
> - handle hidden attribute on window
> - prerender/unloaded



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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