PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 36ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/util.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 61 lines | 40 code | 13 blank | 8 comment | 10 complexity | 882670187d3ed4a257853cad7a6d64c0 MD5 | raw file
 1/**
 2 * Socket.IO client
 3 * 
 4 * @author Guillermo Rauch <guillermo@learnboost.com>
 5 * @license The MIT license.
 6 * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
 7 */
 8
 9(function(){
10	var io = this.io;
11
12	var _pageLoaded = false;
13
14	io.util = {
15
16		ios: false,
17
18		load: function(fn){
19			if (/loaded|complete/.test(document.readyState) || _pageLoaded) return fn();
20			if ('attachEvent' in window){
21				window.attachEvent('onload', fn);
22			} else {
23				window.addEventListener('load', fn, false);
24			}
25		},
26
27		inherit: function(ctor, superCtor){
28			// no support for `instanceof` for now
29			for (var i in superCtor.prototype){
30				ctor.prototype[i] = superCtor.prototype[i];
31			}
32		},
33
34		indexOf: function(arr, item, from){
35			for (var l = arr.length, i = (from < 0) ? Math.max(0, l + from) : from || 0; i < l; i++){
36				if (arr[i] === item) return i;
37			}
38			return -1;
39		},
40
41		isArray: function(obj){
42			return Object.prototype.toString.call(obj) === '[object Array]';
43		},
44		
45    merge: function(target, additional){
46      for (var i in additional)
47        if (additional.hasOwnProperty(i))
48          target[i] = additional[i];
49    }
50
51	};
52
53	io.util.ios = /iphone|ipad/i.test(navigator.userAgent);
54	io.util.android = /android/i.test(navigator.userAgent);
55	io.util.opera = /opera/i.test(navigator.userAgent);
56
57	io.util.load(function(){
58		_pageLoaded = true;
59	});
60
61})();