`
huangchao200701
  • 浏览: 58700 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
阅读更多

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
分享到:
评论

相关推荐

    gwt入门-gwt从这里开始

    gwt 入门,是你开始学习gwt的大道 安装之后的目录结构为: C:\程序开发\Java\gwt-windows-1.4.59 doc(文档目录,开发文档和Java API文档) samples(示例代码目录,非常有名的KitchenSink示例代码即在此目录中)...

    GWT安装和使用

    GWT(Google Web Toolkit) 是 Google 最近推出的一个开发 Ajax 应用的框架,它支持用 Java 开发和调试 Ajax 应用,本文主要介绍如何利用 GWT 进行 Ajax 的开发。 Ajax技术是当前开发web应用的非常热门的技术,也是Web...

    gwt 练习 gwt学习

    gwt 练习gwt 练习gwt 练习gwt 练习

    GWT揭秘(书签整理版)

    2. Hello GWT 3. 模块 4. JSNI 5. 在GWT中使用XML 6. GWT控件详解 7. 使用GWT控件 8. GWT-RPC 9. Ext GWT 10. (实战)俄罗斯方块游戏 11. (实战)费用申请审批流程 12. GWT与Flex整合 13. 图片缓存 CSS Sprite 14. ...

    GWT入门 GWT中文教程

    EXT-GWT2.0.1+API+DOC gwtdesigner Gwt-Ext基础-中级-进阶 GWT快速开发 GWT入门 GWT中文教程

    [GWT揭秘].徐彬.扫描版

    本书内容全面,不仅详细介绍了 GWT 的主要模块和控件、GWT 与 JavaScript 对象的交互、在 GWT 中使用 XML、开发自定义 GWT 控件、GWT-RPC 和 Ext GWT 等必备的基础知识,而且还深入讲解了 GWT 与 Flex整合、图片缓存...

    GWT(Google Web Toolkit)

    GWT(Google Web Toolkit) 是 Google 最近推出的一个开发 Ajax 应用的框架,它支持用 Java 开发和调试 Ajax 应用,本文主要介绍如何利用 GWT 进行 Ajax 的开发。 GWT特性简介  1.动态,可重用的UI组件  GWT提供的...

    GWT eclipse4.4离线插件

    GWT的eclipse4.4离线开发插件,国内现在没有

    GWT FireFox最新插件

    最新火狐浏览器GWT开发插件,离线安装。不用在线等待!

    Gwt中文手册,GWt入门

    Gwt中文手册,GWt入门Gwt中文手册,GWt入门Gwt中文手册,GWt入门

    gwt简单服务端返回数据代码

    客户端请求,服务端返回数据完成,虽然代码很简单,但代表这整个GWT流程;接下来就需要熟悉GWT各种控件、面板、样式等。 具体说明可参考:http://blog.csdn.net/chiperfect/article/details/7666102

    gwt+spring+hibernate

    gwt+spring+hibernate整合例子,导入myeclipse中(要安gwt插件)即可用,数据库自己去代码中查看。包是精简版的,去掉很多不必要的包

    Maven2 + gwt 详细配置指南.doc

    %GWT_HOME%\gwt-dev-windows.jar; 三、MAVEN配置 1、进入MAVEN_HOME,此处我们在之前已设为D:\project tools\maven-2.0.7; 然后进入conf目录,修改settings.xml,找到标签里面的标签(通常它会在注释里面...

    Ext GWT 2.0, Beginner's Guide.pdf

    Ext GWT 2.0: Beginner's Guide is a practical book that teaches you how to use the Ext GWT library to its full potential. It provides a thorough, no-nonsense explanation of the Ext GWT library, what ...

    GWT DEMO 增删改查

    该DEMO适合初学GWT的人观看,希望能帮到初学者,注释详细。

    GWT工具GWT工具GWT工具GWT工具GWT工具GWT工具

    fwefwefwGWT工具GWT工具GWT工具GWT工具GWT工具GWT工具

    gwt-2.8.2 SDK 最新下载 google web toolkit

    官网gwt SDK ,通过java 开发前端页面,并且自动解决页面兼容及国际化问题,以MVP为主开发模式

    stata命令:GWT转spmat

    stata命令:GWT转spmat

    gwt-2.8.0.zip

    gwt包,用于java前端开发,google工具,使用eclipse,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...

    stata命令:GWT转dta 或者GAL转dta

    stata命令:GWT转dta 或者GAL转dta

Global site tag (gtag.js) - Google Analytics