mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
125 lines
1.9 KiB
JavaScript
125 lines
1.9 KiB
JavaScript
|
|
var global = require('global');
|
|
|
|
/**
|
|
* Status of page load.
|
|
*/
|
|
|
|
var pageLoaded = false;
|
|
|
|
/**
|
|
* Inheritance.
|
|
*
|
|
* @param {Function} ctor a
|
|
* @param {Function} ctor b
|
|
* @api private
|
|
*/
|
|
|
|
exports.inherits = function inherits (a, b) {
|
|
function c () { }
|
|
c.prototype = b.prototype;
|
|
a.prototype = new c;
|
|
};
|
|
|
|
/**
|
|
* Object.keys
|
|
*/
|
|
|
|
exports.keys = Object.keys || function (obj) {
|
|
var ret = [];
|
|
var has = Object.prototype.hasOwnProperty;
|
|
|
|
for (var i in obj) {
|
|
if (has.call(obj, i)) {
|
|
ret.push(i);
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
};
|
|
|
|
/**
|
|
* Adds an event.
|
|
*
|
|
* @api private
|
|
*/
|
|
|
|
exports.on = function (element, event, fn, capture) {
|
|
if (element.attachEvent) {
|
|
element.attachEvent('on' + event, fn);
|
|
} else if (element.addEventListener) {
|
|
element.addEventListener(event, fn, capture);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Load utility.
|
|
*
|
|
* @api private
|
|
*/
|
|
|
|
exports.load = function (fn) {
|
|
if (global.document && document.readyState === 'complete' || pageLoaded) {
|
|
return fn();
|
|
}
|
|
|
|
exports.on(global, 'load', fn, false);
|
|
};
|
|
|
|
/**
|
|
* Change the internal pageLoaded value.
|
|
*/
|
|
|
|
if ('undefined' != typeof window) {
|
|
exports.load(function () {
|
|
pageLoaded = true;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* UA / engines detection namespace.
|
|
*
|
|
* @namespace
|
|
*/
|
|
|
|
exports.ua = {};
|
|
|
|
/**
|
|
* Detect webkit.
|
|
*
|
|
* @api private
|
|
*/
|
|
|
|
exports.ua.webkit = 'undefined' != typeof navigator &&
|
|
/webkit/i.test(navigator.userAgent);
|
|
|
|
/**
|
|
* Detect gecko.
|
|
*
|
|
* @api private
|
|
*/
|
|
|
|
exports.ua.gecko = 'undefined' != typeof navigator &&
|
|
/gecko/i.test(navigator.userAgent);
|
|
|
|
/**
|
|
* Detect android;
|
|
*/
|
|
|
|
exports.ua.android = 'undefined' != typeof navigator &&
|
|
/android/i.test(navigator.userAgent);
|
|
|
|
/**
|
|
* Detect iOS.
|
|
*/
|
|
|
|
exports.ua.ios = 'undefined' != typeof navigator &&
|
|
/^(iPad|iPhone|iPod)$/.test(navigator.platform);
|
|
exports.ua.ios6 = exports.ua.ios && /OS 6_/.test(navigator.userAgent);
|
|
|
|
/**
|
|
* Detect Chrome Frame.
|
|
*/
|
|
|
|
exports.ua.chromeframe = Boolean(global.externalHost);
|