modified the getWindow methods for Document and Element to reflect the latest changes
[mootools/dkf.git] / Source / Core / Browser.js
blob73a98b5edc740654ea002b65d20e480ef55a2356
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                 win.document.window = win;
81                 return $extend(win, Window.Prototype);
82         },
84         afterImplement: function(property, value){
85                 window[property] = Window.Prototype[property] = value;
86         }
88 });
90 Window.Prototype = {$family: {name: 'window'}};
92 new Window(window);
94 var Document = new Native({
96         name: 'Document',
98         legacy: (Browser.Engine.trident) ? null: window.Document,
100         initialize: function(doc){
101                 $uid(doc);
102                 doc.head = doc.getElementsByTagName('head')[0];
103                 doc.html = doc.getElementsByTagName('html')[0];
104                 if (Browser.Engine.trident4) $try(function(){
105                         doc.execCommand("BackgroundImageCache", false, true);
106                 });
107                 return $extend(doc, Document.Prototype);
108         },
110         afterImplement: function(property, value){
111                 document[property] = Document.Prototype[property] = value;
112         }
116 Document.Prototype = {$family: {name: 'document'}};
118 new Document(document);