]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/_base/window.js
2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
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;
10 dojo
.provide("dojo._base.window");
15 // Alias for the current document. 'dojo.doc' can be modified
16 // for temporary context shifting. Also see dojo.withDoc().
18 // Refer to dojo.doc rather
19 // than referring to 'window.document' to ensure your code runs
20 // correctly in managed contexts.
22 // | n.appendChild(dojo.doc.createElement('div'));
25 dojo
.doc
= window
["document"] || null;
27 dojo
.body = function(){
29 // Return the body element of the document
30 // return the body object associated with dojo.doc
32 // | dojo.body().appendChild(dojo.doc.createElement('div'));
34 // Note: document.body is not defined for a strict xhtml document
35 // Would like to memoize this, but dojo.doc can change vi dojo.withDoc().
36 return dojo
.doc
.body
|| dojo
.doc
.getElementsByTagName("body")[0]; // Node
39 dojo
.setContext = function(/*Object*/globalObject
, /*DocumentElement*/globalDocument
){
41 // changes the behavior of many core Dojo functions that deal with
42 // namespace and DOM lookup, changing them to work in a new global
43 // context (e.g., an iframe). The varibles dojo.global and dojo.doc
44 // are modified as a result of calling this function and the result of
45 // `dojo.body()` likewise differs.
46 dojo
.global
= globalObject
;
47 dojo
.doc
= globalDocument
;
50 dojo
.withGlobal = function( /*Object*/globalObject
,
52 /*Object?*/thisObject
,
53 /*Array?*/cbArguments
){
55 // Invoke callback with globalObject as dojo.global and
56 // globalObject.document as dojo.doc.
58 // Invoke callback with globalObject as dojo.global and
59 // globalObject.document as dojo.doc. If provided, globalObject
60 // will be executed in the context of object thisObject
61 // When callback() returns or throws an error, the dojo.global
62 // and dojo.doc will be restored to its previous state.
64 var oldGlob
= dojo
.global
;
66 dojo
.global
= globalObject
;
67 return dojo
.withDoc
.call(null, globalObject
.document
, callback
, thisObject
, cbArguments
);
69 dojo
.global
= oldGlob
;
73 dojo
.withDoc = function( /*DocumentElement*/documentObject
,
75 /*Object?*/thisObject
,
76 /*Array?*/cbArguments
){
78 // Invoke callback with documentObject as dojo.doc.
80 // Invoke callback with documentObject as dojo.doc. If provided,
81 // callback will be executed in the context of object thisObject
82 // When callback() returns or throws an error, the dojo.doc will
83 // be restored to its previous state.
85 var oldDoc
= dojo
.doc
,
86 oldLtr
= dojo
._bodyLtr
,
90 dojo
.doc
= documentObject
;
91 delete dojo
._bodyLtr
; // uncache
92 dojo
.isQuirks
= dojo
.doc
.compatMode
== "BackCompat"; // no need to check for QuirksMode which was Opera 7 only
94 if(thisObject
&& typeof callback
== "string"){
95 callback
= thisObject
[callback
];
98 return callback
.apply(thisObject
, cbArguments
|| []);
101 delete dojo
._bodyLtr
; // in case it was undefined originally, and set to true/false by the alternate document
102 if(oldLtr
!== undefined){ dojo
._bodyLtr
= oldLtr
; }
103 dojo
.isQuirks
= oldQ
;