Requires

Provides

The Browser Object. Contains Browser initialization, Window and Document, and the Browser Hash.

License:
MIT-style license.
  1. 18
  2. 19
  3. 20
  4. 21
  5. 22
  6. 23
  7. 24
  8. 25
  9. 26
  10. 27
  11. 28
  12. 29
  13. 30
  14. 31
  15. 32
  16. 33
  17. 34
  18. 35
  19. 36
  20. 37
  21. 38
  22. 39
  23. 40
  24. 41
  25. 42
  26. 43
  27. 44
  28. 45
  29. 46
  30. 47
  31. 48
  32. 49
  33. 50
  34. 51
  35. 52
  36. 53
  37. 54
  38. 55
  39. 56
  40. 57
  41. 58
  42. 59
  43. 60
  44. 61
  45. 62
  46. 63
  47. 64
(function(){ var document = this.document; var window = document.window = this; var UID = 1; this.$uid = (window.ActiveXObject) ? function(item){ return (item.uid || (item.uid = [UID++]))[0]; } : function(item){ return item.uid || (item.uid = UID++); }; $uid(window); $uid(document); var ua = navigator.userAgent.toLowerCase(), platform = navigator.platform.toLowerCase(), UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0], mode = UA[1] == 'ie' && document.documentMode; var Browser = this.Browser = { extend: Function.prototype.extend, name: (UA[1] == 'version') ? UA[3] : UA[1], version: mode || parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]), Platform: { name: ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0] }, Features: { xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector), json: !!(window.JSON) }, Plugins: {} }; Browser[Browser.name] = true; Browser[Browser.name + parseInt(Browser.version, 10)] = true; Browser.Platform[Browser.Platform.name] = true;

Request

  1. 68
  2. 69
  3. 70
  4. 71
  5. 72
  6. 73
  7. 74
  8. 75
  9. 76
  10. 77
  11. 78
  12. 79
  13. 80
  14. 81
  15. 82
  16. 83
  17. 84
  18. 85
  19. 86
  20. 87
  21. 88
  22. 89
  23. 90
  24. 91
  25. 92
  26. 93
  27. 94
  28. 95
Browser.Request = (function(){ var XMLHTTP = function(){ return new XMLHttpRequest(); }; var MSXML2 = function(){ return new ActiveXObject('MSXML2.XMLHTTP'); }; var MSXML = function(){ return new ActiveXObject('Microsoft.XMLHTTP'); }; return Function.attempt(function(){ XMLHTTP(); return XMLHTTP; }, function(){ MSXML2(); return MSXML2; }, function(){ MSXML(); return MSXML; }); })(); Browser.Features.xhr = !!(Browser.Request);

Flash detection

  1. 99
  2. 100
  3. 101
  4. 102
  5. 103
  6. 104
  7. 105
  8. 106
  9. 107
  10. 108
var version = (Function.attempt(function(){ return navigator.plugins['Shockwave Flash'].description; }, function(){ return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version'); }) || '0 r0').match(/\d+/g); Browser.Plugins.Flash = { version: Number(version[0] || '0.' + version[1]) || 0, build: Number(version[2]) || 0 };

String scripts

  1. 112
  2. 113
  3. 114
  4. 115
  5. 116
  6. 117
  7. 118
  8. 119
  9. 120
  10. 121
  11. 122
  12. 123
  13. 124
  14. 125
  15. 126
  16. 127
  17. 128
  18. 129
  19. 130
  20. 131
  21. 132
  22. 133
  23. 134
  24. 135
Browser.exec = function(text){ if (!text) return text; if (window.execScript){ window.execScript(text); } else { var script = document.createElement('script'); script.setAttribute('type', 'text/javascript'); script.text = text; document.head.appendChild(script); document.head.removeChild(script); } return text; }; String.implement('stripScripts', function(exec){ var scripts = ''; var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(all, code){ scripts += code + '\n'; return ''; }); if (exec === true) Browser.exec(scripts); else if (typeOf(exec) == 'function') exec(scripts, text); return text; });

Window, Document

  1. 139
  2. 140
  3. 141
  4. 142
  5. 143
  6. 144
  7. 145
  8. 146
  9. 147
  10. 148
  11. 149
  12. 150
  13. 151
  14. 152
  15. 153
  16. 154
  17. 155
  18. 156
  19. 157
  20. 158
  21. 159
  22. 160
  23. 161
  24. 162
  25. 163
  26. 164
  27. 165
  28. 166
  29. 167
  30. 168
  31. 169
  32. 170
  33. 171
  34. 172
  35. 173
  36. 174
  37. 175
Browser.extend({ Document: this.Document, Window: this.Window, Element: this.Element, Event: this.Event }); this.Window = this.$constructor = new Type('Window', function(){}); this.$family = Function.from('window').hide(); Window.mirror(function(name, method){ window[name] = method; }); this.Document = document.$constructor = new Type('Document', function(){}); document.$family = Function.from('document').hide(); Document.mirror(function(name, method){ document[name] = method; }); document.html = document.documentElement; document.head = document.getElementsByTagName('head')[0]; if (document.execCommand) try { document.execCommand("BackgroundImageCache", false, true); } catch (e){} if (this.attachEvent && !this.addEventListener){ var unloadEvent = function(){ this.detachEvent('onunload', unloadEvent); document.head = document.html = document.window = null; }; this.attachEvent('onunload', unloadEvent); }

IE fails on collections and )

  1. 178
  2. 179
  3. 180
  4. 181
  5. 182
  6. 183
  7. 184
  8. 185
  9. 186
  10. 187
  11. 188
  12. 189
  13. 190
  14. 191
  15. 192
  16. 193
  17. 194
  18. 195
  19. 196
  20. 197
  21. 198
  22. 199
var arrayFrom = Array.from; try { arrayFrom(document.html.childNodes); } catch(e){ Array.from = function(item){ if (typeof item != 'string' && Type.isEnumerable(item) && typeOf(item) != 'array'){ var i = item.length, array = new Array(i); while (i--) array[i] = item[i]; return array; } return arrayFrom(item); }; var prototype = Array.prototype, slice = prototype.slice; ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice'].each(function(name){ var method = prototype[name]; Array[name] = function(item){ return method.apply(Array.from(item), slice.call(arguments, 1)); }; }); }

<1.2compat>

  1. 203
  2. 204
  3. 205
  4. 206
  5. 207
  6. 208
  7. 209
  8. 210
  9. 211
  10. 212
  11. 213
  12. 214
  13. 215
  14. 216
  15. 217
  16. 218
  17. 219
  18. 220
  19. 221
  20. 222
  21. 223
  22. 224
  23. 225
  24. 226
  25. 227
  26. 228
  27. 229
  28. 230
  29. 231
  30. 232
  31. 233
  32. 234
  33. 235
  34. 236
  35. 237
  36. 238
  37. 239
  38. 240
  39. 241
  40. 242
  41. 243
  42. 244
  43. 245
  44. 246
  45. 247
  46. 248
  47. 249
  48. 250
  49. 251
  50. 252
  51. 253
  52. 254
  53. 255
  54. 256
  55. 257
  56. 258
  57. 259
if (Browser.Platform.ios) Browser.Platform.ipod = true; Browser.Engine = {}; var setEngine = function(name, version){ Browser.Engine.name = name; Browser.Engine[name + version] = true; Browser.Engine.version = version; }; if (Browser.ie){ Browser.Engine.trident = true; switch (Browser.version){ case 6: setEngine('trident', 4); break; case 7: setEngine('trident', 5); break; case 8: setEngine('trident', 6); } } if (Browser.firefox){ Browser.Engine.gecko = true; if (Browser.version >= 3) setEngine('gecko', 19); else setEngine('gecko', 18); } if (Browser.safari || Browser.chrome){ Browser.Engine.webkit = true; switch (Browser.version){ case 2: setEngine('webkit', 419); break; case 3: setEngine('webkit', 420); break; case 4: setEngine('webkit', 525); } } if (Browser.opera){ Browser.Engine.presto = true; if (Browser.version >= 9.6) setEngine('presto', 960); else if (Browser.version >= 9.5) setEngine('presto', 950); else setEngine('presto', 925); } if (Browser.name == 'unknown'){ switch ((ua.match(/(?:webkit|khtml|gecko)/) || [])[0]){ case 'webkit': case 'khtml': Browser.Engine.webkit = true; break; case 'gecko': Browser.Engine.gecko = true; } } this.$exec = Browser.exec;

</1.2compat>

  1. 263
})();