+ // 'screenId' can be added from settings on the front-end where the JS global 'pagenow' is not set
+ if ( ! settings.screenId ) {
+ settings.screenId = options.screenId || 'front';
+ }
+
+ if ( options.suspension === 'disable' ) {
+ settings.suspendEnabled = false;
+ }
+ }
+
+ // Convert to milliseconds
+ settings.mainInterval = settings.mainInterval * 1000;
+ settings.originalInterval = settings.mainInterval;
+
+ // Set focus/blur events on the window
+ $(window).on( 'blur.wp-heartbeat-focus', function() {
+ setFrameFocusEvents();
+ // We don't know why the 'blur' was fired. Either the user clicked in an iframe or outside the browser.
+ // Running blurred() after some timeout lets us cancel it if the user clicked in an iframe.
+ settings.winBlurTimer = window.setTimeout( function(){ blurred(); }, 500 );
+ }).on( 'focus.wp-heartbeat-focus', function() {
+ removeFrameFocusEvents();
+ focused();
+ }).on( 'unload.wp-heartbeat', function() {
+ // Don't connect any more
+ settings.suspend = true;
+
+ // Abort the last request if not completed
+ if ( settings.xhr && settings.xhr.readyState !== 4 ) {
+ settings.xhr.abort();
+ }
+ });
+
+ // Check for user activity every 30 seconds.
+ window.setInterval( function(){ checkUserActivity(); }, 30000 );