GWT

Google UI widget GWT 中的主JS文件代码

1. // Copyright 2006 Google Inc. All Rights Reserved.
2. // This startup script should be included in host pages.
3. //
4. //
5. // Common
6. //
7. var __GWT_JS_INCLUDED;
8. if (!__GWT_JS_INCLUDED) {
9. __GWT_JS_INCLUDED = true;
10. var __gwt_retryWaitMs = 50;
11. var __gwt_moduleNames = [];
12. var __gwt_isHostPageLoaded = false;
13. var __gwt_metaProps = {};
14. var __gwt_onPropertyError = null;
15. var __gwt_onLoadError = null;
16. function __gwt_isHosted() {
17. if (window.external && window.external.gwtOnLoad) {
18. if (document.location.href.indexOf("gwt.hybrid") == -1) {
19. return true;
20. }
21. }
22. return false;
23. }
24. function __gwt_processMetas() {
25. var metas = document.getElementsByTagName("meta");
26. for (var i = 0, n = metas.length; i < n; ++i) {
27. var meta = metas[i];
28. var name = meta.getAttribute("name");
29. if (name) {
30. if (name == "gwt:module") {
31. var content = meta.getAttribute("content");
32. if (content) {
33. __gwt_moduleNames = __gwt_moduleNames.concat(content);
34. }
35. } else if (name == "gwt:property") {
36. var content = meta.getAttribute("content");
37. if (content) {
38. var name = content, value = "";
39. var eq = content.indexOf("=");
40. if (eq != -1) {
41. name = content.substring(0, eq);
42. value = content.substring(eq+1);
43. }
44. __gwt_metaProps[name] = value;
45. }
46. } else if (name == "gwt:onPropertyErrorFn") {
47. var content = meta.getAttribute("content");
48. if (content) {
49. try {
50. __gwt_onPropertyError = eval(content);
51. } catch (e) {
52. window.alert("Bad handler \"" + content + "\" for \"gwt:onPropertyErrorFn\"");
53. }
54. }
55. } else if (name == "gwt:onLoadErrorFn") {
56. var content = meta.getAttribute("content");
57. if (content) {
58. try {
59. __gwt_onLoadError = eval(content);
60. } catch (e) {
61. window.alert("Bad handler \"" + content + "\" for \"gwt:onLoadErrorFn\"");
62. }
63. }
64. }
65. }
66. }
67. }
68. function __gwt_getMetaProperty(name) {
69. var value = __gwt_metaProps[name];
70. if (value) {
71. return value;
72. } else {
73. return null;
74. }
75. }
76. function __gwt_forEachModule(lambda) {
77. for (var i = 0; i < __gwt_moduleNames.length; ++i) {
78. lambda(__gwt_moduleNames[i]);
79. }
80. }
81. // Called by the selection script when a property has a bad value or is missing.
82. // 'allowedValues' is an array of strings.
83. // Can be hooked in the host page.
84. //
85. function __gwt_onBadProperty(moduleName, propName, allowedValues, badValue) {
86. if (__gwt_onPropertyError) {
87. __gwt_onPropertyError(moduleName, propName, allowedValues, badValue);
88. return;
89. } else {
90. var msg = "While attempting to load module \"" + moduleName + "\", ";
91. if (badValue != null) {
92. msg += "property \"" + propName + "\" was set to the unexpected value \"" + badValue + "\"";
93. } else {
94. msg += "property \"" + propName + "\" was not specified";
95. }
96.
97. msg += "\n\nAllowed values: " + allowedValues;
98.
99. window.alert(msg);
100. }
101. }
102. // Returns an array that splits the module name from the meta content into
103. // [0] the prefix url, if any, guaranteed to end with a slash
104. // [1] the dotted module name
105. //
106. function __gwt_splitModuleNameRef(moduleName) {
107. var parts = ['', moduleName];
108. var i = moduleName.lastIndexOf("=");
109. if (i != -1) {
110. parts[0] = moduleName.substring(0, i) + '/';
111. parts[1] = moduleName.substring(i+1);
112. }
113. return parts;
114. }
115. //
116. // Called directly from compiled code
117. //
118. function __gwt_initHandlers(resize, beforeunload, unload) {
119. var oldOnResize = window.onresize;
120. window.onresize = function() {
121. resize();
122. if (oldOnResize)
123. oldOnResize();
124. };
125. var oldOnBeforeUnload = window.onbeforeunload;
126. window.onbeforeunload = function() {
127. var ret = beforeunload();
128. var oldRet;
129. if (oldOnBeforeUnload)
130. oldRet = oldOnBeforeUnload();
131. if (ret !== null)
132. return ret;
133. return oldRet;
134. };
135. var oldOnUnload = window.onunload;
136. window.onunload = function() {
137. unload();
138. if (oldOnUnload)
139. oldOnUnload();
140. };
141. }
142. //
143. // Web Mode
144. //
145. function __gwt_injectWebModeFrame(name) {
146. if (document.body) {
147. var parts = __gwt_splitModuleNameRef(name);
148.
149. // Insert an IFRAME
150. var iframe = document.createElement("iframe");
151. var selectorURL = parts[0] + parts[1] + ".nocache.html";
152. iframe.src = selectorURL;
153. iframe.style.border = '0px';
154. iframe.style.width = '0px';
155. iframe.style.height = '0px';
156. if (document.body.firstChild) {
157. document.body.insertBefore(iframe, document.body.firstChild);
158. } else {
159. document.body.appendChild(iframe);
160. }
161. } else {
162. // Try again in a moment.
163. //
164. window.setTimeout(function() { __gwt_injectWebModeFrame(name); }, __gwt_retryWaitMs);
165. }
166. }
167. // When nested IFRAMEs load, they reach up into the parent page to announce that
168. // they are ready to run. Because IFRAMEs load asynchronously relative to the
169. // host page, one of two things can happen when they reach up:
170. // (1) The host page's onload handler has not yet been called, in which case we
171. // retry until it has been called.
172. // (2) The host page's onload handler has already been called, in which case the
173. // nested IFRAME should be initialized immediately.
174. //
175. function __gwt_webModeFrameOnLoad(iframeWindow, name) {
176. var moduleInitFn = iframeWindow.gwtOnLoad;
177. if (__gwt_isHostPageLoaded && moduleInitFn) {
178. var old = window.status;
179. window.status = "Initializing module '" + name + "'";
180. try {
181. moduleInitFn(__gwt_onLoadError, name);
182. } finally {
183. window.status = old;
184. }
185. } else {
186. setTimeout(function() { __gwt_webModeFrameOnLoad(iframeWindow, name); }, __gwt_retryWaitMs);
187. }
188. }
189. function __gwt_hookOnLoad() {
190. var oldHandler = window.onload;
191. window.onload = function() {
192. __gwt_isHostPageLoaded = true;
193. if (oldHandler) {
194. oldHandler();
195. }
196. };
197. }
198. //
199. // Hosted Mode
200. //
201. function __gwt_injectHostedModeFrame(name) {
202. if (document.body) {
203. // Insert an empty IFRAME
204. var iframe = document.createElement("iframe");
205. iframe.style.display = "none";
206. document.body.insertBefore(iframe, document.body.firstChild);
207. iframe.src = "gwt-hosted.html?" + name;
208. } else {
209. // Try again in a moment.
210. //
211. window.setTimeout(function() { __gwt_injectHostedModeFrame(name); }, __gwt_retryWaitMs);
212. }
213. }
214. function __gwt_initHostedModeModule(moduleFrame, moduleName) {
215. if (!window.external.gwtOnLoad(moduleFrame, moduleName)) {
216. // Module failed to load.
217. //
218. if (__gwt_onLoadError) {
219. __gwt_onLoadError(moduleName);
220. } else {
221. window.alert("Failed to load module '" + moduleName + "'.\nPlease see the log in the development shell for details.");
222. }
223. }
224. }
225. function __gwt_onUnload() {
226. window.external.gwtOnLoad(null, null);
227. if (__gwt_onUnload.oldUnloadHandler) {
228. __gwt_onUnload.oldUnloadHandler();
229. }
230. }
231. //
232. // Set it up
233. //
234. __gwt_processMetas();
235. if (__gwt_isHosted()) {
236. __gwt_onUnload.oldUnloadHandler = window.onunload;
237. window.onunload = __gwt_onUnload;
238. __gwt_forEachModule(__gwt_injectHostedModeFrame);
239. }
240. else {
241. __gwt_hookOnLoad();
242. __gwt_forEachModule(__gwt_injectWebModeFrame);
243. }
244. } // __GWT_JS_INCLUDED
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值