document.window is now set in Window instantiation. it means you have to instantiate...
[mootools/dkf.git] / Source / Core / Browser.js
blobc33c24ffee9eccc3263f029674dcd2a86566ec2e
1 /*
2 Script: Browser.js
3         The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash.
5 License:
6         MIT-style license.
7 */
9 var Browser = new Hash({
10         Engine: {name: 'unknown', version: ''},
11         Platform: {name: (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase()},
12         Features: {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)},
13         Plugins: {}
14 });
16 if (window.opera) Browser.Engine = {name: 'presto', version: (document.getElementsByClassName) ? 950 : 925};
17 else if (window.ActiveXObject) Browser.Engine = {name: 'trident', version: (window.XMLHttpRequest) ? 5 : 4};
18 else if (!navigator.taintEnabled) Browser.Engine = {name: 'webkit', version: (Browser.Features.xpath) ? ((Browser.Features.query) ? 525 : 420) : 419};
19 else if (document.getBoxObjectFor != null) Browser.Engine = {name: 'gecko', version: (document.getElementsByClassName) ? 19 : 18};
20 Browser.Engine[Browser.Engine.name] = Browser.Engine[Browser.Engine.name + Browser.Engine.version] = true;
22 if (window.orientation != undefined) Browser.Platform.name = 'ipod';
24 Browser.Platform[Browser.Platform.name] = true;
26 Browser.Request = function(){
27         return $try(function(){
28                 return new XMLHttpRequest();
29         }, function(){
30                 return new ActiveXObject('MSXML2.XMLHTTP');
31         });
34 Browser.Features.xhr = !!(Browser.Request());
36 Browser.Plugins.Flash = (function(){
37         var version = ($try(function(){
38                 return navigator.plugins['Shockwave Flash'].description;
39         }, function(){
40                 return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
41         }) || '0 r0').match(/\d+/g);
42         return {version: parseInt(version[0] || 0 + '.' + version[1] || 0), build: parseInt(version[2] || 0)};
43 })();
45 function $exec(text){
46         if (!text) return text;
47         if (window.execScript){
48                 window.execScript(text);
49         } else {
50                 var script = document.createElement('script');
51                 script.setAttribute('type', 'text/javascript');
52                 script.text = text;
53                 document.head.appendChild(script);
54                 document.head.removeChild(script);
55         }
56         return text;
59 Native.UID = 1;
61 var $uid = (Browser.Engine.trident) ? function(item){
62         return (item.uid || (item.uid = [Native.UID++]))[0];
63 } : function(item){
64         return item.uid || (item.uid = Native.UID++);
67 var Window = new Native({
69         name: 'Window',
71         legacy: (Browser.Engine.trident) ? null: window.Window,
73         initialize: function(win){
74                 $uid(win);
75                 if (!win.Element){
76                         win.Element = $empty;
77                         if (Browser.Engine.webkit) win.document.createElement("iframe"); //fixes safari 2
78                         win.Element.prototype = (Browser.Engine.webkit) ? window["[[DOMElement.prototype]]"] : {};
79                 }
80                 var doc = win.document;
81                 doc.window = win;
82                 return $extend(win, Window.Prototype);
83         },
85         afterImplement: function(property, value){
86                 window[property] = Window.Prototype[property] = value;
87         }
89 });
91 Window.Prototype = {$family: {name: 'window'}};
93 new Window(window);
95 var Document = new Native({
97         name: 'Document',
99         legacy: (Browser.Engine.trident) ? null: window.Document,
101         initialize: function(doc){
102                 $uid(doc);
103                 doc.head = doc.getElementsByTagName('head')[0];
104                 doc.html = doc.getElementsByTagName('html')[0];
105                 if (Browser.Engine.trident4) $try(function(){
106                         doc.execCommand("BackgroundImageCache", false, true);
107                 });
108                 return $extend(doc, Document.Prototype);
109         },
111         afterImplement: function(property, value){
112                 document[property] = Document.Prototype[property] = value;
113         }
117 Document.Prototype = {$family: {name: 'document'}};
119 new Document(document);