]>
Commit | Line | Data |
---|---|---|
2f01fe57 | 1 | /* |
81bea17a | 2 | Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. |
2f01fe57 AD |
3 | Available via Academic Free License >= 2.1 OR the modified BSD license. |
4 | see: http://dojotoolkit.org/license for details | |
5 | */ | |
6 | ||
7 | ||
a089699c AD |
8 | if(!dojo._hasResource["dojo._base.window"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. |
9 | dojo._hasResource["dojo._base.window"] = true; | |
2f01fe57 | 10 | dojo.provide("dojo._base.window"); |
a089699c | 11 | |
81bea17a | 12 | |
a089699c AD |
13 | /*===== |
14 | dojo.doc = { | |
15 | // summary: | |
16 | // Alias for the current document. 'dojo.doc' can be modified | |
17 | // for temporary context shifting. Also see dojo.withDoc(). | |
18 | // description: | |
19 | // Refer to dojo.doc rather | |
20 | // than referring to 'window.document' to ensure your code runs | |
21 | // correctly in managed contexts. | |
22 | // example: | |
23 | // | n.appendChild(dojo.doc.createElement('div')); | |
2f01fe57 | 24 | } |
a089699c AD |
25 | =====*/ |
26 | dojo.doc = window["document"] || null; | |
27 | ||
28 | dojo.body = function(){ | |
29 | // summary: | |
30 | // Return the body element of the document | |
31 | // return the body object associated with dojo.doc | |
32 | // example: | |
33 | // | dojo.body().appendChild(dojo.doc.createElement('div')); | |
34 | ||
35 | // Note: document.body is not defined for a strict xhtml document | |
36 | // Would like to memoize this, but dojo.doc can change vi dojo.withDoc(). | |
37 | return dojo.doc.body || dojo.doc.getElementsByTagName("body")[0]; // Node | |
81bea17a | 38 | }; |
a089699c AD |
39 | |
40 | dojo.setContext = function(/*Object*/globalObject, /*DocumentElement*/globalDocument){ | |
41 | // summary: | |
42 | // changes the behavior of many core Dojo functions that deal with | |
43 | // namespace and DOM lookup, changing them to work in a new global | |
44 | // context (e.g., an iframe). The varibles dojo.global and dojo.doc | |
45 | // are modified as a result of calling this function and the result of | |
46 | // `dojo.body()` likewise differs. | |
47 | dojo.global = globalObject; | |
48 | dojo.doc = globalDocument; | |
2f01fe57 | 49 | }; |
a089699c | 50 | |
81bea17a AD |
51 | dojo.withGlobal = function( /*Object*/globalObject, |
52 | /*Function*/callback, | |
53 | /*Object?*/thisObject, | |
a089699c AD |
54 | /*Array?*/cbArguments){ |
55 | // summary: | |
56 | // Invoke callback with globalObject as dojo.global and | |
57 | // globalObject.document as dojo.doc. | |
58 | // description: | |
59 | // Invoke callback with globalObject as dojo.global and | |
60 | // globalObject.document as dojo.doc. If provided, globalObject | |
61 | // will be executed in the context of object thisObject | |
62 | // When callback() returns or throws an error, the dojo.global | |
63 | // and dojo.doc will be restored to its previous state. | |
64 | ||
65 | var oldGlob = dojo.global; | |
66 | try{ | |
67 | dojo.global = globalObject; | |
68 | return dojo.withDoc.call(null, globalObject.document, callback, thisObject, cbArguments); | |
69 | }finally{ | |
70 | dojo.global = oldGlob; | |
71 | } | |
81bea17a | 72 | }; |
a089699c | 73 | |
81bea17a AD |
74 | dojo.withDoc = function( /*DocumentElement*/documentObject, |
75 | /*Function*/callback, | |
76 | /*Object?*/thisObject, | |
a089699c AD |
77 | /*Array?*/cbArguments){ |
78 | // summary: | |
79 | // Invoke callback with documentObject as dojo.doc. | |
80 | // description: | |
81 | // Invoke callback with documentObject as dojo.doc. If provided, | |
82 | // callback will be executed in the context of object thisObject | |
83 | // When callback() returns or throws an error, the dojo.doc will | |
84 | // be restored to its previous state. | |
85 | ||
86 | var oldDoc = dojo.doc, | |
87 | oldLtr = dojo._bodyLtr, | |
88 | oldQ = dojo.isQuirks; | |
89 | ||
90 | try{ | |
91 | dojo.doc = documentObject; | |
92 | delete dojo._bodyLtr; // uncache | |
93 | dojo.isQuirks = dojo.doc.compatMode == "BackCompat"; // no need to check for QuirksMode which was Opera 7 only | |
94 | ||
95 | if(thisObject && typeof callback == "string"){ | |
96 | callback = thisObject[callback]; | |
97 | } | |
98 | ||
99 | return callback.apply(thisObject, cbArguments || []); | |
100 | }finally{ | |
101 | dojo.doc = oldDoc; | |
102 | delete dojo._bodyLtr; // in case it was undefined originally, and set to true/false by the alternate document | |
103 | if(oldLtr !== undefined){ dojo._bodyLtr = oldLtr; } | |
104 | dojo.isQuirks = oldQ; | |
105 | } | |
2f01fe57 | 106 | }; |
a089699c | 107 | |
2f01fe57 | 108 | } |