You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB
JavaScript

(function () {
// Set the name of the hidden property and the change event for visibility
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
var Visible = {
hidden: hidden,
visibilityChange: visibilityChange,
};
Visible.isSupported = function () {
return !(typeof(document.addEventListener) === "undefined" ||
typeof document[hidden] === "undefined");
};
Visible.onChange = function (f, once) {
document.addEventListener(visibilityChange, function (ev) {
f(!document[hidden], ev);
}, {
once: once
});
};
Visible.currently = function () {
return !document[hidden];
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = Visible;
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define(function () {
return Visible;
});
} else {
window.Visible = Visible;
}
}());