PageRenderTime 34ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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. (function(){
  9. var io = this.io;
  10. var _pageLoaded = false;
  11. io.util = {
  12. ios: false,
  13. load: function(fn){
  14. if (/loaded|complete/.test(document.readyState) || _pageLoaded) return fn();
  15. if ('attachEvent' in window){
  16. window.attachEvent('onload', fn);
  17. } else {
  18. window.addEventListener('load', fn, false);
  19. }
  20. },
  21. inherit: function(ctor, superCtor){
  22. // no support for `instanceof` for now
  23. for (var i in superCtor.prototype){
  24. ctor.prototype[i] = superCtor.prototype[i];
  25. }
  26. },
  27. indexOf: function(arr, item, from){
  28. for (var l = arr.length, i = (from < 0) ? Math.max(0, l + from) : from || 0; i < l; i++){
  29. if (arr[i] === item) return i;
  30. }
  31. return -1;
  32. },
  33. isArray: function(obj){
  34. return Object.prototype.toString.call(obj) === '[object Array]';
  35. },
  36. merge: function(target, additional){
  37. for (var i in additional)
  38. if (additional.hasOwnProperty(i))
  39. target[i] = additional[i];
  40. }
  41. };
  42. io.util.ios = /iphone|ipad/i.test(navigator.userAgent);
  43. io.util.android = /android/i.test(navigator.userAgent);
  44. io.util.opera = /opera/i.test(navigator.userAgent);
  45. io.util.load(function(){
  46. _pageLoaded = true;
  47. });
  48. })();