/js/lib/Socket.IO-node/support/socket.io-client/lib/util.js
JavaScript | 61 lines | 40 code | 13 blank | 8 comment | 10 complexity | 882670187d3ed4a257853cad7a6d64c0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
- /**
- * Socket.IO client
- *
- * @author Guillermo Rauch <guillermo@learnboost.com>
- * @license The MIT license.
- * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
- */
- (function(){
- var io = this.io;
- var _pageLoaded = false;
- io.util = {
- ios: false,
- load: function(fn){
- if (/loaded|complete/.test(document.readyState) || _pageLoaded) return fn();
- if ('attachEvent' in window){
- window.attachEvent('onload', fn);
- } else {
- window.addEventListener('load', fn, false);
- }
- },
- inherit: function(ctor, superCtor){
- // no support for `instanceof` for now
- for (var i in superCtor.prototype){
- ctor.prototype[i] = superCtor.prototype[i];
- }
- },
- indexOf: function(arr, item, from){
- for (var l = arr.length, i = (from < 0) ? Math.max(0, l + from) : from || 0; i < l; i++){
- if (arr[i] === item) return i;
- }
- return -1;
- },
- isArray: function(obj){
- return Object.prototype.toString.call(obj) === '[object Array]';
- },
-
- merge: function(target, additional){
- for (var i in additional)
- if (additional.hasOwnProperty(i))
- target[i] = additional[i];
- }
- };
- io.util.ios = /iphone|ipad/i.test(navigator.userAgent);
- io.util.android = /android/i.test(navigator.userAgent);
- io.util.opera = /opera/i.test(navigator.userAgent);
- io.util.load(function(){
- _pageLoaded = true;
- });
- })();