1 define("dojo/_base/window", ["./kernel", "./lang", "../sniff"], function(dojo, lang, has){
7 // API to save/set/restore the global/document scope.
13 // Alias for the current window. 'global' can be modified
14 // for temporary context shifting. See also withGlobal().
16 // Use this rather than referring to 'window' to ensure your code runs
17 // correctly in managed contexts.
21 doc: this["document"] || null,
25 // Alias for the current document. 'doc' can be modified
26 // for temporary context shifting. See also withDoc().
28 // Use this rather than referring to 'window.document' to ensure your code runs
29 // correctly in managed contexts.
31 // | n.appendChild(dojo.doc.createElement('div'));
35 body: function(/*Document?*/ doc){
37 // Return the body element of the specified document or of dojo/_base/window::doc.
39 // | win.body().appendChild(dojo.doc.createElement('div'));
41 // Note: document.body is not defined for a strict xhtml document
42 // Would like to memoize this, but dojo.doc can change vi dojo.withDoc().
43 doc = doc || dojo.doc;
44 return doc.body || doc.getElementsByTagName("body")[0]; // Node
47 setContext: function(/*Object*/ globalObject, /*DocumentElement*/ globalDocument){
49 // changes the behavior of many core Dojo functions that deal with
50 // namespace and DOM lookup, changing them to work in a new global
51 // context (e.g., an iframe). The varibles dojo.global and dojo.doc
52 // are modified as a result of calling this function and the result of
53 // `dojo.body()` likewise differs.
54 dojo.global = ret.global = globalObject;
55 dojo.doc = ret.doc = globalDocument;
58 withGlobal: function( /*Object*/ globalObject,
59 /*Function*/ callback,
60 /*Object?*/ thisObject,
61 /*Array?*/ cbArguments){
63 // Invoke callback with globalObject as dojo.global and
64 // globalObject.document as dojo.doc.
66 // Invoke callback with globalObject as dojo.global and
67 // globalObject.document as dojo.doc. If provided, globalObject
68 // will be executed in the context of object thisObject
69 // When callback() returns or throws an error, the dojo.global
70 // and dojo.doc will be restored to its previous state.
72 var oldGlob = dojo.global;
74 dojo.global = ret.global = globalObject;
75 return ret.withDoc.call(null, globalObject.document, callback, thisObject, cbArguments);
77 dojo.global = ret.global = oldGlob;
81 withDoc: function( /*DocumentElement*/ documentObject,
82 /*Function*/ callback,
83 /*Object?*/ thisObject,
84 /*Array?*/ cbArguments){
86 // Invoke callback with documentObject as dojo/_base/window::doc.
88 // Invoke callback with documentObject as dojo/_base/window::doc. If provided,
89 // callback will be executed in the context of object thisObject
90 // When callback() returns or throws an error, the dojo/_base/window::doc will
91 // be restored to its previous state.
95 oldIE = has("ie"), isIE, mode, pwin;
98 dojo.doc = ret.doc = documentObject;
99 // update dojo.isQuirks and the value of the has feature "quirks".
100 // remove setting dojo.isQuirks and dojo.isIE for 2.0
101 dojo.isQuirks = has.add("quirks", dojo.doc.compatMode == "BackCompat", true, true); // no need to check for QuirksMode which was Opera 7 only
104 if((pwin = documentObject.parentWindow) && pwin.navigator){
105 // re-run IE detection logic and update dojo.isIE / has("ie")
106 // (the only time parentWindow/navigator wouldn't exist is if we were not
107 // passed an actual legitimate document object)
108 isIE = parseFloat(pwin.navigator.appVersion.split("MSIE ")[1]) || undefined;
109 mode = documentObject.documentMode;
110 if(mode && mode != 5 && Math.floor(isIE) != mode){
113 dojo.isIE = has.add("ie", isIE, true, true);
117 if(thisObject && typeof callback == "string"){
118 callback = thisObject[callback];
121 return callback.apply(thisObject, cbArguments || []);
123 dojo.doc = ret.doc = oldDoc;
124 dojo.isQuirks = has.add("quirks", oldQ, true, true);
125 dojo.isIE = has.add("ie", oldIE, true, true);
130 1 && lang.mixin(dojo, ret);