/* * Copyright 2011 Andrey “A.I.” Sitnik , * sponsored by Evil Martians. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // Add Page Visibility API support to old browsers by focus/blur hack. // // Include this script _before_ Visibility.js. // // Note, that this hack doesn’t correctly emulate Page Visibility API: // when user change focus from browser to another window (browser and your // page may stay visible), this hack will decide, that you page is hidden. // // For Firefox 5 it will be better to use MozVisibility hack without this issue. // See . ;(function() { "use strict"; if ( document.visibilityState || document.webkitVisibilityState || document.msVisibilityState || document.mozVisibilityState || document.oVisibilityState ) { return; } document.hidden = false; document.visibilityState = 'visible'; var event = null var i = 0 var fireEvent = function () { if( document.createEvent ) { if ( !event ) { event = document.createEvent('HTMLEvents'); event.initEvent('visibilitychange', true, true); } document.dispatchEvent(event); } else { if ( typeof(Visibility) == 'object' ) { Visibility._onVisibilityChange.call(Visibility, { }) } } } var onfocus = function () { document.hidden = false; document.visibilityState = 'visible'; fireEvent(); }; var onblur = function () { document.hidden = true; document.visibilityState = 'hidden'; fireEvent(); } if ( document.addEventListener ) { window.addEventListener('focus', onfocus, true); window.addEventListener('blur', onblur, true); } else { document.attachEvent('onfocusin', onfocus); document.attachEvent('onfocusout', onblur); } })();