mathiasbynens/jquery-visibility — Issue #2: Cleanup code and tweak weak inferences.
Author: jdalton
Created: 2012-01-26 00:30:45+00:00
State: open

~~~ js
;(function($, document) {
var prefix,
prop,
eventName = 'onfocusin' in document && 'hasFocus' in document ? 'focusin focusout' : 'focus blur',
prefixes = ['', 'moz', 'ms', 'o', 'webkit'];

while ((prop = prefix = prefixes.pop()) != null) {
prop = (prefix ? prefix + 'H': 'h') + 'idden';
if ($.support.pageVisibility = typeof document[prop] == 'boolean') {
eventName = prefix + 'visibilitychange';
break;
}
}

$(/bl/.test(eventName) ? window : document).on(eventName, function(event) {
$.event.trigger(prop && document[prop] || /bl|ut/.test(event.type) ? 'hide.visibility' : 'show.visibility');
});
}(jQuery, document));
~~~