summaryrefslogtreecommitdiff
path: root/lib/dojo/_base/window.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-03-04 19:02:28 +0300
committerAndrew Dolgov <[email protected]>2011-03-04 19:02:59 +0300
commita089699c8915636ba4f158d77dba9b012bc93208 (patch)
treeb2d7d051f1f55d44a6be07d3ee137e5a7ccfcefb /lib/dojo/_base/window.js
parentcfad9259a6feacfa8194b1312770ae6db1ecce50 (diff)
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
Diffstat (limited to 'lib/dojo/_base/window.js')
-rw-r--r--lib/dojo/_base/window.js129
1 files changed, 94 insertions, 35 deletions
diff --git a/lib/dojo/_base/window.js b/lib/dojo/_base/window.js
index 44239d92c..5c6e2e952 100644
--- a/lib/dojo/_base/window.js
+++ b/lib/dojo/_base/window.js
@@ -5,45 +5,104 @@
*/
-if(!dojo._hasResource["dojo._base.window"]){
-dojo._hasResource["dojo._base.window"]=true;
+if(!dojo._hasResource["dojo._base.window"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojo._base.window"] = true;
dojo.provide("dojo._base.window");
-dojo.doc=window["document"]||null;
-dojo.body=function(){
-return dojo.doc.body||dojo.doc.getElementsByTagName("body")[0];
-};
-dojo.setContext=function(_1,_2){
-dojo.global=_1;
-dojo.doc=_2;
-};
-dojo.withGlobal=function(_3,_4,_5,_6){
-var _7=dojo.global;
-try{
-dojo.global=_3;
-return dojo.withDoc.call(null,_3.document,_4,_5,_6);
+
+/*=====
+dojo.doc = {
+ // summary:
+ // Alias for the current document. 'dojo.doc' can be modified
+ // for temporary context shifting. Also see dojo.withDoc().
+ // description:
+ // Refer to dojo.doc rather
+ // than referring to 'window.document' to ensure your code runs
+ // correctly in managed contexts.
+ // example:
+ // | n.appendChild(dojo.doc.createElement('div'));
}
-finally{
-dojo.global=_7;
+=====*/
+dojo.doc = window["document"] || null;
+
+dojo.body = function(){
+ // summary:
+ // Return the body element of the document
+ // return the body object associated with dojo.doc
+ // example:
+ // | dojo.body().appendChild(dojo.doc.createElement('div'));
+
+ // Note: document.body is not defined for a strict xhtml document
+ // Would like to memoize this, but dojo.doc can change vi dojo.withDoc().
+ return dojo.doc.body || dojo.doc.getElementsByTagName("body")[0]; // Node
}
+
+dojo.setContext = function(/*Object*/globalObject, /*DocumentElement*/globalDocument){
+ // summary:
+ // changes the behavior of many core Dojo functions that deal with
+ // namespace and DOM lookup, changing them to work in a new global
+ // context (e.g., an iframe). The varibles dojo.global and dojo.doc
+ // are modified as a result of calling this function and the result of
+ // `dojo.body()` likewise differs.
+ dojo.global = globalObject;
+ dojo.doc = globalDocument;
};
-dojo.withDoc=function(_8,_9,_a,_b){
-var _c=dojo.doc,_d=dojo._bodyLtr,_e=dojo.isQuirks;
-try{
-dojo.doc=_8;
-delete dojo._bodyLtr;
-dojo.isQuirks=dojo.doc.compatMode=="BackCompat";
-if(_a&&typeof _9=="string"){
-_9=_a[_9];
-}
-return _9.apply(_a,_b||[]);
-}
-finally{
-dojo.doc=_c;
-delete dojo._bodyLtr;
-if(_d!==undefined){
-dojo._bodyLtr=_d;
-}
-dojo.isQuirks=_e;
+
+dojo.withGlobal = function( /*Object*/globalObject,
+ /*Function*/callback,
+ /*Object?*/thisObject,
+ /*Array?*/cbArguments){
+ // summary:
+ // Invoke callback with globalObject as dojo.global and
+ // globalObject.document as dojo.doc.
+ // description:
+ // Invoke callback with globalObject as dojo.global and
+ // globalObject.document as dojo.doc. If provided, globalObject
+ // will be executed in the context of object thisObject
+ // When callback() returns or throws an error, the dojo.global
+ // and dojo.doc will be restored to its previous state.
+
+ var oldGlob = dojo.global;
+ try{
+ dojo.global = globalObject;
+ return dojo.withDoc.call(null, globalObject.document, callback, thisObject, cbArguments);
+ }finally{
+ dojo.global = oldGlob;
+ }
}
+
+dojo.withDoc = function( /*DocumentElement*/documentObject,
+ /*Function*/callback,
+ /*Object?*/thisObject,
+ /*Array?*/cbArguments){
+ // summary:
+ // Invoke callback with documentObject as dojo.doc.
+ // description:
+ // Invoke callback with documentObject as dojo.doc. If provided,
+ // callback will be executed in the context of object thisObject
+ // When callback() returns or throws an error, the dojo.doc will
+ // be restored to its previous state.
+
+ var oldDoc = dojo.doc,
+ oldLtr = dojo._bodyLtr,
+ oldQ = dojo.isQuirks;
+
+ try{
+ dojo.doc = documentObject;
+ delete dojo._bodyLtr; // uncache
+ dojo.isQuirks = dojo.doc.compatMode == "BackCompat"; // no need to check for QuirksMode which was Opera 7 only
+
+ if(thisObject && typeof callback == "string"){
+ callback = thisObject[callback];
+ }
+
+ return callback.apply(thisObject, cbArguments || []);
+ }finally{
+ dojo.doc = oldDoc;
+ delete dojo._bodyLtr; // in case it was undefined originally, and set to true/false by the alternate document
+ if(oldLtr !== undefined){ dojo._bodyLtr = oldLtr; }
+ dojo.isQuirks = oldQ;
+ }
};
+
+
}