]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/_base/window.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojo / _base / window.js
1 if(!dojo._hasResource["dojo._base.window"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo._base.window"] = true;
3 dojo.provide("dojo._base.window");
4
5 dojo._gearsObject = function(){
6         // summary: 
7         //              factory method to get a Google Gears plugin instance to
8         //              expose in the browser runtime environment, if present
9         var factory;
10         var results;
11         
12         var gearsObj = dojo.getObject("google.gears");
13         if(gearsObj){ return gearsObj; } // already defined elsewhere
14         
15         if(typeof GearsFactory != "undefined"){ // Firefox
16                 factory = new GearsFactory();
17         }else{
18                 if(dojo.isIE){
19                         // IE
20                         try{
21                                 factory = new ActiveXObject("Gears.Factory");
22                         }catch(e){
23                                 // ok to squelch; there's no gears factory.  move on.
24                         }
25                 }else if(navigator.mimeTypes["application/x-googlegears"]){
26                         // Safari?
27                         factory = document.createElement("object");
28                         factory.setAttribute("type", "application/x-googlegears");
29                         factory.setAttribute("width", 0);
30                         factory.setAttribute("height", 0);
31                         factory.style.display = "none";
32                         document.documentElement.appendChild(factory);
33                 }
34         }
35
36         // still nothing?
37         if(!factory){ return null; }
38         
39         // define the global objects now; don't overwrite them though if they
40         // were somehow set internally by the Gears plugin, which is on their
41         // dev roadmap for the future
42         dojo.setObject("google.gears.factory", factory);
43         return dojo.getObject("google.gears");
44 };
45
46 /*=====
47 dojo.isGears = {
48         // summary: True if client is using Google Gears
49 };
50 =====*/
51 // see if we have Google Gears installed, and if
52 // so, make it available in the runtime environment
53 // and in the Google standard 'google.gears' global object
54 dojo.isGears = (!!dojo._gearsObject())||0;
55
56 /*=====
57 dojo.doc = {
58         // summary:
59         //              Alias for the current document. 'dojo.doc' can be modified
60         //              for temporary context shifting. Also see dojo.withDoc().
61         // description:
62         //    Refer to dojo.doc rather
63         //    than referring to 'window.document' to ensure your code runs
64         //    correctly in managed contexts.
65         // example:
66         //      |       n.appendChild(dojo.doc.createElement('div'));
67 }
68 =====*/
69 dojo.doc = window["document"] || null;
70
71 dojo.body = function(){
72         // summary:
73         //              Return the body element of the document
74         //              return the body object associated with dojo.doc
75         // example:
76         //      |       dojo.body().appendChild(dojo.doc.createElement('div'));
77
78         // Note: document.body is not defined for a strict xhtml document
79         // Would like to memoize this, but dojo.doc can change vi dojo.withDoc().
80         return dojo.doc.body || dojo.doc.getElementsByTagName("body")[0]; // Node
81 }
82
83 dojo.setContext = function(/*Object*/globalObject, /*DocumentElement*/globalDocument){
84         // summary:
85         //              changes the behavior of many core Dojo functions that deal with
86         //              namespace and DOM lookup, changing them to work in a new global
87         //              context (e.g., an iframe). The varibles dojo.global and dojo.doc
88         //              are modified as a result of calling this function and the result of
89         //              `dojo.body()` likewise differs.
90         dojo.global = globalObject;
91         dojo.doc = globalDocument;
92 };
93
94 dojo._fireCallback = function(callback, context, cbArguments){
95         if(context && dojo.isString(callback)){
96                 callback = context[callback];
97         }
98         return callback.apply(context, cbArguments || [ ]);
99 }
100
101 dojo.withGlobal = function(     /*Object*/globalObject, 
102                                                         /*Function*/callback, 
103                                                         /*Object?*/thisObject, 
104                                                         /*Array?*/cbArguments){
105         // summary:
106         //              Call callback with globalObject as dojo.global and
107         //              globalObject.document as dojo.doc. If provided, globalObject
108         //              will be executed in the context of object thisObject
109         // description:
110         //              When callback() returns or throws an error, the dojo.global
111         //              and dojo.doc will be restored to its previous state.
112         var rval;
113         var oldGlob = dojo.global;
114         var oldDoc = dojo.doc;
115         try{
116                 dojo.setContext(globalObject, globalObject.document);
117                 rval = dojo._fireCallback(callback, thisObject, cbArguments);
118         }finally{
119                 dojo.setContext(oldGlob, oldDoc);
120         }
121         return rval;
122 }
123
124 dojo.withDoc = function(        /*Object*/documentObject, 
125                                                         /*Function*/callback, 
126                                                         /*Object?*/thisObject, 
127                                                         /*Array?*/cbArguments){
128         // summary:
129         //              Call callback with documentObject as dojo.doc. If provided,
130         //              callback will be executed in the context of object thisObject
131         // description:
132         //              When callback() returns or throws an error, the dojo.doc will
133         //              be restored to its previous state.
134         var rval;
135         var oldDoc = dojo.doc;
136         try{
137                 dojo.doc = documentObject;
138                 rval = dojo._fireCallback(callback, thisObject, cbArguments);
139         }finally{
140                 dojo.doc = oldDoc;
141         }
142         return rval;
143 };
144
145 }