]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/_base/window.js
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
[tt-rss.git] / lib / dojo / _base / window.js
1 /*
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
5 */
6
7
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");
11
12 /*=====
13 dojo.doc = {
14 // summary:
15 // Alias for the current document. 'dojo.doc' can be modified
16 // for temporary context shifting. Also see dojo.withDoc().
17 // description:
18 // Refer to dojo.doc rather
19 // than referring to 'window.document' to ensure your code runs
20 // correctly in managed contexts.
21 // example:
22 // | n.appendChild(dojo.doc.createElement('div'));
23 }
24 =====*/
25 dojo.doc = window["document"] || null;
26
27 dojo.body = function(){
28 // summary:
29 // Return the body element of the document
30 // return the body object associated with dojo.doc
31 // example:
32 // | dojo.body().appendChild(dojo.doc.createElement('div'));
33
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
37 }
38
39 dojo.setContext = function(/*Object*/globalObject, /*DocumentElement*/globalDocument){
40 // summary:
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;
48 };
49
50 dojo.withGlobal = function( /*Object*/globalObject,
51 /*Function*/callback,
52 /*Object?*/thisObject,
53 /*Array?*/cbArguments){
54 // summary:
55 // Invoke callback with globalObject as dojo.global and
56 // globalObject.document as dojo.doc.
57 // description:
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.
63
64 var oldGlob = dojo.global;
65 try{
66 dojo.global = globalObject;
67 return dojo.withDoc.call(null, globalObject.document, callback, thisObject, cbArguments);
68 }finally{
69 dojo.global = oldGlob;
70 }
71 }
72
73 dojo.withDoc = function( /*DocumentElement*/documentObject,
74 /*Function*/callback,
75 /*Object?*/thisObject,
76 /*Array?*/cbArguments){
77 // summary:
78 // Invoke callback with documentObject as dojo.doc.
79 // description:
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.
84
85 var oldDoc = dojo.doc,
86 oldLtr = dojo._bodyLtr,
87 oldQ = dojo.isQuirks;
88
89 try{
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
93
94 if(thisObject && typeof callback == "string"){
95 callback = thisObject[callback];
96 }
97
98 return callback.apply(thisObject, cbArguments || []);
99 }finally{
100 dojo.doc = oldDoc;
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;
104 }
105 };
106
107
108 }