Dialog.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:9k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.widget.Dialog");
  9. dojo.require("dojo.widget.*");
  10. dojo.require("dojo.widget.ContentPane");
  11. dojo.require("dojo.event.*");
  12. dojo.require("dojo.gfx.color");
  13. dojo.require("dojo.html.layout");
  14. dojo.require("dojo.html.display");
  15. dojo.require("dojo.html.iframe");
  16. dojo.declare("dojo.widget.ModalDialogBase", null, {isContainer:true, focusElement:"", bgColor:"black", bgOpacity:0.4, followScroll:true, closeOnBackgroundClick:false, trapTabs:function (e) {
  17. if (e.target == this.tabStartOuter) {
  18. if (this._fromTrap) {
  19. this.tabStart.focus();
  20. this._fromTrap = false;
  21. } else {
  22. this._fromTrap = true;
  23. this.tabEnd.focus();
  24. }
  25. } else {
  26. if (e.target == this.tabStart) {
  27. if (this._fromTrap) {
  28. this._fromTrap = false;
  29. } else {
  30. this._fromTrap = true;
  31. this.tabEnd.focus();
  32. }
  33. } else {
  34. if (e.target == this.tabEndOuter) {
  35. if (this._fromTrap) {
  36. this.tabEnd.focus();
  37. this._fromTrap = false;
  38. } else {
  39. this._fromTrap = true;
  40. this.tabStart.focus();
  41. }
  42. } else {
  43. if (e.target == this.tabEnd) {
  44. if (this._fromTrap) {
  45. this._fromTrap = false;
  46. } else {
  47. this._fromTrap = true;
  48. this.tabStart.focus();
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }, clearTrap:function (e) {
  55. var _this = this;
  56. setTimeout(function () {
  57. _this._fromTrap = false;
  58. }, 100);
  59. }, postCreate:function () {
  60. with (this.domNode.style) {
  61. position = "absolute";
  62. zIndex = 999;
  63. display = "none";
  64. overflow = "visible";
  65. }
  66. var b = dojo.body();
  67. b.appendChild(this.domNode);
  68. this.bg = document.createElement("div");
  69. this.bg.className = "dialogUnderlay";
  70. with (this.bg.style) {
  71. position = "absolute";
  72. left = top = "0px";
  73. zIndex = 998;
  74. display = "none";
  75. }
  76. b.appendChild(this.bg);
  77. this.setBackgroundColor(this.bgColor);
  78. this.bgIframe = new dojo.html.BackgroundIframe();
  79. if (this.bgIframe.iframe) {
  80. with (this.bgIframe.iframe.style) {
  81. position = "absolute";
  82. left = top = "0px";
  83. zIndex = 90;
  84. display = "none";
  85. }
  86. }
  87. if (this.closeOnBackgroundClick) {
  88. dojo.event.kwConnect({srcObj:this.bg, srcFunc:"onclick", adviceObj:this, adviceFunc:"onBackgroundClick", once:true});
  89. }
  90. }, uninitialize:function () {
  91. this.bgIframe.remove();
  92. dojo.html.removeNode(this.bg, true);
  93. }, setBackgroundColor:function (color) {
  94. if (arguments.length >= 3) {
  95. color = new dojo.gfx.color.Color(arguments[0], arguments[1], arguments[2]);
  96. } else {
  97. color = new dojo.gfx.color.Color(color);
  98. }
  99. this.bg.style.backgroundColor = color.toString();
  100. return this.bgColor = color;
  101. }, setBackgroundOpacity:function (op) {
  102. if (arguments.length == 0) {
  103. op = this.bgOpacity;
  104. }
  105. dojo.html.setOpacity(this.bg, op);
  106. try {
  107. this.bgOpacity = dojo.html.getOpacity(this.bg);
  108. }
  109. catch (e) {
  110. this.bgOpacity = op;
  111. }
  112. return this.bgOpacity;
  113. }, _sizeBackground:function () {
  114. if (this.bgOpacity > 0) {
  115. var viewport = dojo.html.getViewport();
  116. var h = viewport.height;
  117. var w = viewport.width;
  118. with (this.bg.style) {
  119. width = w + "px";
  120. height = h + "px";
  121. }
  122. var scroll_offset = dojo.html.getScroll().offset;
  123. this.bg.style.top = scroll_offset.y + "px";
  124. this.bg.style.left = scroll_offset.x + "px";
  125. var viewport = dojo.html.getViewport();
  126. if (viewport.width != w) {
  127. this.bg.style.width = viewport.width + "px";
  128. }
  129. if (viewport.height != h) {
  130. this.bg.style.height = viewport.height + "px";
  131. }
  132. }
  133. this.bgIframe.size(this.bg);
  134. }, _showBackground:function () {
  135. if (this.bgOpacity > 0) {
  136. this.bg.style.display = "block";
  137. }
  138. if (this.bgIframe.iframe) {
  139. this.bgIframe.iframe.style.display = "block";
  140. }
  141. }, placeModalDialog:function () {
  142. var scroll_offset = dojo.html.getScroll().offset;
  143. var viewport_size = dojo.html.getViewport();
  144. var mb;
  145. if (this.isShowing()) {
  146. mb = dojo.html.getMarginBox(this.domNode);
  147. } else {
  148. dojo.html.setVisibility(this.domNode, false);
  149. dojo.html.show(this.domNode);
  150. mb = dojo.html.getMarginBox(this.domNode);
  151. dojo.html.hide(this.domNode);
  152. dojo.html.setVisibility(this.domNode, true);
  153. }
  154. var x = scroll_offset.x + (viewport_size.width - mb.width) / 2;
  155. var y = scroll_offset.y + (viewport_size.height - mb.height) / 2;
  156. with (this.domNode.style) {
  157. left = x + "px";
  158. top = y + "px";
  159. }
  160. }, _onKey:function (evt) {
  161. if (evt.key) {
  162. var node = evt.target;
  163. while (node != null) {
  164. if (node == this.domNode) {
  165. return;
  166. }
  167. node = node.parentNode;
  168. }
  169. if (evt.key != evt.KEY_TAB) {
  170. dojo.event.browser.stopEvent(evt);
  171. } else {
  172. if (!dojo.render.html.opera) {
  173. try {
  174. this.tabStart.focus();
  175. }
  176. catch (e) {
  177. }
  178. }
  179. }
  180. }
  181. }, showModalDialog:function () {
  182. if (this.followScroll && !this._scrollConnected) {
  183. this._scrollConnected = true;
  184. dojo.event.connect(window, "onscroll", this, "_onScroll");
  185. }
  186. dojo.event.connect(document.documentElement, "onkey", this, "_onKey");
  187. this.placeModalDialog();
  188. this.setBackgroundOpacity();
  189. this._sizeBackground();
  190. this._showBackground();
  191. this._fromTrap = true;
  192. setTimeout(dojo.lang.hitch(this, function () {
  193. try {
  194. this.tabStart.focus();
  195. }
  196. catch (e) {
  197. }
  198. }), 50);
  199. }, hideModalDialog:function () {
  200. if (this.focusElement) {
  201. dojo.byId(this.focusElement).focus();
  202. dojo.byId(this.focusElement).blur();
  203. }
  204. this.bg.style.display = "none";
  205. this.bg.style.width = this.bg.style.height = "1px";
  206. if (this.bgIframe.iframe) {
  207. this.bgIframe.iframe.style.display = "none";
  208. }
  209. dojo.event.disconnect(document.documentElement, "onkey", this, "_onKey");
  210. if (this._scrollConnected) {
  211. this._scrollConnected = false;
  212. dojo.event.disconnect(window, "onscroll", this, "_onScroll");
  213. }
  214. }, _onScroll:function () {
  215. var scroll_offset = dojo.html.getScroll().offset;
  216. this.bg.style.top = scroll_offset.y + "px";
  217. this.bg.style.left = scroll_offset.x + "px";
  218. this.placeModalDialog();
  219. }, checkSize:function () {
  220. if (this.isShowing()) {
  221. this._sizeBackground();
  222. this.placeModalDialog();
  223. this.onResized();
  224. }
  225. }, onBackgroundClick:function () {
  226. if (this.lifetime - this.timeRemaining >= this.blockDuration) {
  227. return;
  228. }
  229. this.hide();
  230. }});
  231. dojo.widget.defineWidget("dojo.widget.Dialog", [dojo.widget.ContentPane, dojo.widget.ModalDialogBase], {templateString:"<div id="${this.widgetId}" class="dojoDialog" dojoattachpoint="wrapper">nt<span dojoattachpoint="tabStartOuter" dojoonfocus="trapTabs" dojoonblur="clearTrap"ttabindex="0"></span>nt<span dojoattachpoint="tabStart" dojoonfocus="trapTabs" dojoonblur="clearTrap" tabindex="0"></span>nt<div dojoattachpoint="containerNode" style="position: relative; z-index: 2;"></div>nt<span dojoattachpoint="tabEnd" dojoonfocus="trapTabs" dojoonblur="clearTrap" tabindex="0"></span>nt<span dojoattachpoint="tabEndOuter" dojoonfocus="trapTabs" dojoonblur="clearTrap" tabindex="0"></span>n</div>n", blockDuration:0, lifetime:0, closeNode:"", postMixInProperties:function () {
  232. dojo.widget.Dialog.superclass.postMixInProperties.apply(this, arguments);
  233. if (this.closeNode) {
  234. this.setCloseControl(this.closeNode);
  235. }
  236. }, postCreate:function () {
  237. dojo.widget.Dialog.superclass.postCreate.apply(this, arguments);
  238. dojo.widget.ModalDialogBase.prototype.postCreate.apply(this, arguments);
  239. }, show:function () {
  240. if (this.lifetime) {
  241. this.timeRemaining = this.lifetime;
  242. if (this.timerNode) {
  243. this.timerNode.innerHTML = Math.ceil(this.timeRemaining / 1000);
  244. }
  245. if (this.blockDuration && this.closeNode) {
  246. if (this.lifetime > this.blockDuration) {
  247. this.closeNode.style.visibility = "hidden";
  248. } else {
  249. this.closeNode.style.display = "none";
  250. }
  251. }
  252. if (this.timer) {
  253. clearInterval(this.timer);
  254. }
  255. this.timer = setInterval(dojo.lang.hitch(this, "_onTick"), 100);
  256. }
  257. this.showModalDialog();
  258. dojo.widget.Dialog.superclass.show.call(this);
  259. }, onLoad:function () {
  260. this.placeModalDialog();
  261. dojo.widget.Dialog.superclass.onLoad.call(this);
  262. }, fillInTemplate:function () {
  263. }, hide:function () {
  264. this.hideModalDialog();
  265. dojo.widget.Dialog.superclass.hide.call(this);
  266. if (this.timer) {
  267. clearInterval(this.timer);
  268. }
  269. }, setTimerNode:function (node) {
  270. this.timerNode = node;
  271. }, setCloseControl:function (node) {
  272. this.closeNode = dojo.byId(node);
  273. dojo.event.connect(this.closeNode, "onclick", this, "hide");
  274. }, setShowControl:function (node) {
  275. node = dojo.byId(node);
  276. dojo.event.connect(node, "onclick", this, "show");
  277. }, _onTick:function () {
  278. if (this.timer) {
  279. this.timeRemaining -= 100;
  280. if (this.lifetime - this.timeRemaining >= this.blockDuration) {
  281. if (this.closeNode) {
  282. this.closeNode.style.visibility = "visible";
  283. }
  284. }
  285. if (!this.timeRemaining) {
  286. clearInterval(this.timer);
  287. this.hide();
  288. } else {
  289. if (this.timerNode) {
  290. this.timerNode.innerHTML = Math.ceil(this.timeRemaining / 1000);
  291. }
  292. }
  293. }
  294. }});