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.
48 lines
1.6 KiB
JavaScript
48 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,
|
|
};
|
|
|
|
var isSupported = Visible.isSupported = function () {
|
|
return !(typeof(document.addEventListener) === "undefined" ||
|
|
typeof document[hidden] === "undefined");
|
|
};
|
|
|
|
var onChange = Visible.onChange = function (f) {
|
|
document.addEventListener(visibilityChange, function (ev) {
|
|
f(!document[hidden], ev);
|
|
}, false);
|
|
};
|
|
|
|
var currently = 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;
|
|
}
|
|
}());
|