7b6b48dff6f37818d8c42574ffc391e30b7524d7.svn-base 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. if (!dojo._hasResource["dojo._base.window"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dojo._base.window"] = true;
  6. dojo.provide("dojo._base.window");
  7. dojo._gearsObject = function() {
  8. // summary:
  9. // factory method to get a Google Gears plugin instance to
  10. // expose in the browser runtime environment, if present
  11. var factory;
  12. var results;
  13. var gearsObj = dojo.getObject("google.gears");
  14. if (gearsObj) {
  15. return gearsObj;
  16. } // already defined elsewhere
  17. if (typeof GearsFactory != "undefined") { // Firefox
  18. factory = new GearsFactory();
  19. } else {
  20. if (dojo.isIE) {
  21. // IE
  22. try {
  23. factory = new ActiveXObject("Gears.Factory");
  24. } catch (e) {
  25. // ok to squelch; there's no gears factory. move on.
  26. }
  27. } else if (navigator.mimeTypes["application/x-googlegears"]) {
  28. // Safari?
  29. factory = document.createElement("object");
  30. factory.setAttribute("type", "application/x-googlegears");
  31. factory.setAttribute("width", 0);
  32. factory.setAttribute("height", 0);
  33. factory.style.display = "none";
  34. document.documentElement.appendChild(factory);
  35. }
  36. }
  37. // still nothing?
  38. if (!factory) {
  39. return null;
  40. }
  41. // define the global objects now; don't overwrite them though if they
  42. // were somehow set internally by the Gears plugin, which is on their
  43. // dev roadmap for the future
  44. dojo.setObject("google.gears.factory", factory);
  45. return dojo.getObject("google.gears");
  46. };
  47. // see if we have Google Gears installed, and if
  48. // so, make it available in the runtime environment
  49. // and in the Google standard 'google.gears' global object
  50. dojo.isGears = (!!dojo._gearsObject()) || 0;
  51. // @global: dojo.doc
  52. // summary:
  53. // Current document object. 'dojo.doc' can be modified
  54. // for temporary context shifting. Also see dojo.withDoc().
  55. // description:
  56. // Refer to dojo.doc rather
  57. // than referring to 'window.document' to ensure your code runs
  58. // correctly in managed contexts.
  59. dojo.doc = window["document"] || null;
  60. dojo.body = function() {
  61. // summary:
  62. // return the body object associated with dojo.doc
  63. // Note: document.body is not defined for a strict xhtml document
  64. // Would like to memoize this, but dojo.doc can change vi
  65. // dojo.withDoc().
  66. return dojo.doc.body || dojo.doc.getElementsByTagName("body")[0];
  67. }
  68. dojo.setContext = function(/* Object */globalObject, /* DocumentElement */
  69. globalDocument) {
  70. // summary:
  71. // changes the behavior of many core Dojo functions that deal with
  72. // namespace and DOM lookup, changing them to work in a new global
  73. // context. The varibles dojo.global and dojo.doc
  74. // are modified as a result of calling this function.
  75. dojo.global = globalObject;
  76. dojo.doc = globalDocument;
  77. };
  78. dojo._fireCallback = function(callback, context, cbArguments) {
  79. // FIXME: should migrate to using "dojo.isString"!
  80. if (context && dojo.isString(callback)) {
  81. callback = context[callback];
  82. }
  83. return (context
  84. ? callback.apply(context, cbArguments || [])
  85. : callback());
  86. }
  87. dojo.withGlobal = function( /* Object */globalObject,
  88. /* Function */callback,
  89. /* Object? */thisObject,
  90. /* Array? */cbArguments) {
  91. // summary:
  92. // Call callback with globalObject as dojo.global and
  93. // globalObject.document as dojo.doc. If provided, globalObject
  94. // will be executed in the context of object thisObject
  95. // description:
  96. // When callback() returns or throws an error, the dojo.global
  97. // and dojo.doc will be restored to its previous state.
  98. var rval;
  99. var oldGlob = dojo.global;
  100. var oldDoc = dojo.doc;
  101. try {
  102. dojo.setContext(globalObject, globalObject.document);
  103. rval = dojo._fireCallback(callback, thisObject, cbArguments);
  104. } finally {
  105. dojo.setContext(oldGlob, oldDoc);
  106. }
  107. return rval;
  108. }
  109. dojo.withDoc = function( /* Object */documentObject,
  110. /* Function */callback,
  111. /* Object? */thisObject,
  112. /* Array? */cbArguments) {
  113. // summary:
  114. // Call callback with documentObject as dojo.doc. If provided,
  115. // callback will be executed in the context of object thisObject
  116. // description:
  117. // When callback() returns or throws an error, the dojo.doc will
  118. // be restored to its previous state.
  119. var rval;
  120. var oldDoc = dojo.doc;
  121. try {
  122. dojo.doc = documentObject;
  123. rval = dojo._fireCallback(callback, thisObject, cbArguments);
  124. } finally {
  125. dojo.doc = oldDoc;
  126. }
  127. return rval;
  128. };
  129. // Register any module paths set up in djConfig. Need to do this
  130. // in the hostenvs since hostenv_browser can read djConfig from a
  131. // script tag's attribute.
  132. (function() {
  133. var mp = djConfig["modulePaths"];
  134. if (mp) {
  135. for (var param in mp) {
  136. dojo.registerModulePath(param, mp[param]);
  137. }
  138. }
  139. })();
  140. }