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

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.FloatingPane");
  9. dojo.require("dojo.widget.*");
  10. dojo.require("dojo.widget.Manager");
  11. dojo.require("dojo.html.*");
  12. dojo.require("dojo.html.layout");
  13. dojo.require("dojo.html.iframe");
  14. dojo.require("dojo.html.selection");
  15. dojo.require("dojo.lfx.shadow");
  16. dojo.require("dojo.widget.html.layout");
  17. dojo.require("dojo.widget.ContentPane");
  18. dojo.require("dojo.dnd.HtmlDragMove");
  19. dojo.require("dojo.widget.Dialog");
  20. dojo.require("dojo.widget.ResizeHandle");
  21. dojo.declare("dojo.widget.FloatingPaneBase", null, {title:"", iconSrc:"", hasShadow:false, constrainToContainer:false, taskBarId:"", resizable:true, titleBarDisplay:true, windowState:"normal", displayCloseAction:false, displayMinimizeAction:false, displayMaximizeAction:false, _max_taskBarConnectAttempts:5, _taskBarConnectAttempts:0, templateString:"<div id="${this.widgetId}" dojoAttachEvent="onMouseDown" class="dojoFloatingPane">nt<div dojoAttachPoint="titleBar" class="dojoFloatingPaneTitleBar"  style="display:none">nt  t<img dojoAttachPoint="titleBarIcon"  class="dojoFloatingPaneTitleBarIcon">ntt<div dojoAttachPoint="closeAction" dojoAttachEvent="onClick:closeWindow"n   t  ttclass="dojoFloatingPaneCloseIcon"></div>ntt<div dojoAttachPoint="restoreAction" dojoAttachEvent="onClick:restoreWindow"n   t  ttclass="dojoFloatingPaneRestoreIcon"></div>ntt<div dojoAttachPoint="maximizeAction" dojoAttachEvent="onClick:maximizeWindow"n   t  ttclass="dojoFloatingPaneMaximizeIcon"></div>ntt<div dojoAttachPoint="minimizeAction" dojoAttachEvent="onClick:minimizeWindow"n   t  ttclass="dojoFloatingPaneMinimizeIcon"></div>nt  t<div dojoAttachPoint="titleBarText" class="dojoFloatingPaneTitleText">${this.title}</div>nt</div>nnt<div id="${this.widgetId}_container" dojoAttachPoint="containerNode" class="dojoFloatingPaneClient"></div>nnt<div dojoAttachPoint="resizeBar" class="dojoFloatingPaneResizebar" style="display:none"></div>n</div>n", templateCssString:"n/********** Outer Window ***************/nn.dojoFloatingPane {nt/* essential css */ntposition: absolute;ntoverflow: visible;tt/* so drop shadow is displayed */ntz-index: 10;nnt/* styling css */ntborder: 1px solid;ntborder-color: ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight;ntbackground-color: ThreeDFace;n}nnn/********** Title Bar ****************/nn.dojoFloatingPaneTitleBar {ntvertical-align: top;ntmargin: 2px 2px 2px 2px;ntz-index: 10;ntbackground-color: #7596c6;ntcursor: default;ntoverflow: hidden;ntborder-color: ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight;ntvertical-align: middle;n}nn.dojoFloatingPaneTitleText {ntfloat: left;ntpadding: 2px 4px 2px 2px;ntwhite-space: nowrap;ntcolor: CaptionText;ntfont: small-caption;n}nn.dojoTitleBarIcon {ntfloat: left;ntheight: 22px;ntwidth: 22px;ntvertical-align: middle;ntmargin-right: 5px;ntmargin-left: 5px;n}nn.dojoFloatingPaneActions{ntfloat: right;ntposition: absolute;ntright: 2px;nttop: 2px;ntvertical-align: middle;n}nnn.dojoFloatingPaneActionItem {ntvertical-align: middle;ntmargin-right: 1px;ntheight: 22px;ntwidth: 22px;n}nnn.dojoFloatingPaneTitleBarIcon {nt/* essential css */ntfloat: left;nnt/* styling css */ntmargin-left: 2px;ntmargin-right: 4px;ntheight: 22px;n}nn/* minimize/maximize icons are specified by CSS only */n.dojoFloatingPaneMinimizeIcon,n.dojoFloatingPaneMaximizeIcon,n.dojoFloatingPaneRestoreIcon,n.dojoFloatingPaneCloseIcon {ntvertical-align: middle;ntheight: 22px;ntwidth: 22px;ntfloat: right;n}n.dojoFloatingPaneMinimizeIcon {ntbackground-image: url(images/floatingPaneMinimize.gif);n}n.dojoFloatingPaneMaximizeIcon {ntbackground-image: url(images/floatingPaneMaximize.gif);n}n.dojoFloatingPaneRestoreIcon {ntbackground-image: url(images/floatingPaneRestore.gif);n}n.dojoFloatingPaneCloseIcon {ntbackground-image: url(images/floatingPaneClose.gif);n}nn/* bar at bottom of window that holds resize handle */n.dojoFloatingPaneResizebar {ntz-index: 10;ntheight: 13px;ntbackground-color: ThreeDFace;n}nn/************* Client Area ***************/nn.dojoFloatingPaneClient {ntposition: relative;ntz-index: 10;ntborder: 1px solid;ntborder-color: ThreeDShadow ThreeDHighlight ThreeDHighlight ThreeDShadow;ntmargin: 2px;ntbackground-color: ThreeDFace;ntpadding: 8px;ntfont-family: Verdana, Helvetica, Garamond, sans-serif;ntfont-size: 12px;ntoverflow: auto;n}nn", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/FloatingPane.css"), fillInFloatingPaneTemplate:function (args, frag) {
  22. var source = this.getFragNodeRef(frag);
  23. dojo.html.copyStyle(this.domNode, source);
  24. dojo.body().appendChild(this.domNode);
  25. if (!this.isShowing()) {
  26. this.windowState = "minimized";
  27. }
  28. if (this.iconSrc == "") {
  29. dojo.html.removeNode(this.titleBarIcon);
  30. } else {
  31. this.titleBarIcon.src = this.iconSrc.toString();
  32. }
  33. if (this.titleBarDisplay) {
  34. this.titleBar.style.display = "";
  35. dojo.html.disableSelection(this.titleBar);
  36. this.titleBarIcon.style.display = (this.iconSrc == "" ? "none" : "");
  37. this.minimizeAction.style.display = (this.displayMinimizeAction ? "" : "none");
  38. this.maximizeAction.style.display = (this.displayMaximizeAction && this.windowState != "maximized" ? "" : "none");
  39. this.restoreAction.style.display = (this.displayMaximizeAction && this.windowState == "maximized" ? "" : "none");
  40. this.closeAction.style.display = (this.displayCloseAction ? "" : "none");
  41. this.drag = new dojo.dnd.HtmlDragMoveSource(this.domNode);
  42. if (this.constrainToContainer) {
  43. this.drag.constrainTo();
  44. }
  45. this.drag.setDragHandle(this.titleBar);
  46. var self = this;
  47. dojo.event.topic.subscribe("dragMove", function (info) {
  48. if (info.source.domNode == self.domNode) {
  49. dojo.event.topic.publish("floatingPaneMove", {source:self});
  50. }
  51. });
  52. }
  53. if (this.resizable) {
  54. this.resizeBar.style.display = "";
  55. this.resizeHandle = dojo.widget.createWidget("ResizeHandle", {targetElmId:this.widgetId, id:this.widgetId + "_resize"});
  56. this.resizeBar.appendChild(this.resizeHandle.domNode);
  57. }
  58. if (this.hasShadow) {
  59. this.shadow = new dojo.lfx.shadow(this.domNode);
  60. }
  61. this.bgIframe = new dojo.html.BackgroundIframe(this.domNode);
  62. if (this.taskBarId) {
  63. this._taskBarSetup();
  64. }
  65. dojo.body().removeChild(this.domNode);
  66. }, postCreate:function () {
  67. if (dojo.hostenv.post_load_) {
  68. this._setInitialWindowState();
  69. } else {
  70. dojo.addOnLoad(this, "_setInitialWindowState");
  71. }
  72. }, maximizeWindow:function (evt) {
  73. var mb = dojo.html.getMarginBox(this.domNode);
  74. this.previous = {width:mb.width || this.width, height:mb.height || this.height, left:this.domNode.style.left, top:this.domNode.style.top, bottom:this.domNode.style.bottom, right:this.domNode.style.right};
  75. if (this.domNode.parentNode.style.overflow.toLowerCase() != "hidden") {
  76. this.parentPrevious = {overflow:this.domNode.parentNode.style.overflow};
  77. dojo.debug(this.domNode.parentNode.style.overflow);
  78. this.domNode.parentNode.style.overflow = "hidden";
  79. }
  80. this.domNode.style.left = dojo.html.getPixelValue(this.domNode.parentNode, "padding-left", true) + "px";
  81. this.domNode.style.top = dojo.html.getPixelValue(this.domNode.parentNode, "padding-top", true) + "px";
  82. if ((this.domNode.parentNode.nodeName.toLowerCase() == "body")) {
  83. var viewport = dojo.html.getViewport();
  84. var padding = dojo.html.getPadding(dojo.body());
  85. this.resizeTo(viewport.width - padding.width, viewport.height - padding.height);
  86. } else {
  87. var content = dojo.html.getContentBox(this.domNode.parentNode);
  88. this.resizeTo(content.width, content.height);
  89. }
  90. this.maximizeAction.style.display = "none";
  91. this.restoreAction.style.display = "";
  92. if (this.resizeHandle) {
  93. this.resizeHandle.domNode.style.display = "none";
  94. }
  95. this.drag.setDragHandle(null);
  96. this.windowState = "maximized";
  97. }, minimizeWindow:function (evt) {
  98. this.hide();
  99. for (var attr in this.parentPrevious) {
  100. this.domNode.parentNode.style[attr] = this.parentPrevious[attr];
  101. }
  102. this.lastWindowState = this.windowState;
  103. this.windowState = "minimized";
  104. }, restoreWindow:function (evt) {
  105. if (this.windowState == "minimized") {
  106. this.show();
  107. if (this.lastWindowState == "maximized") {
  108. this.domNode.parentNode.style.overflow = "hidden";
  109. this.windowState = "maximized";
  110. } else {
  111. this.windowState = "normal";
  112. }
  113. } else {
  114. if (this.windowState == "maximized") {
  115. for (var attr in this.previous) {
  116. this.domNode.style[attr] = this.previous[attr];
  117. }
  118. for (var attr in this.parentPrevious) {
  119. this.domNode.parentNode.style[attr] = this.parentPrevious[attr];
  120. }
  121. this.resizeTo(this.previous.width, this.previous.height);
  122. this.previous = null;
  123. this.parentPrevious = null;
  124. this.restoreAction.style.display = "none";
  125. this.maximizeAction.style.display = this.displayMaximizeAction ? "" : "none";
  126. if (this.resizeHandle) {
  127. this.resizeHandle.domNode.style.display = "";
  128. }
  129. this.drag.setDragHandle(this.titleBar);
  130. this.windowState = "normal";
  131. } else {
  132. }
  133. }
  134. }, toggleDisplay:function () {
  135. if (this.windowState == "minimized") {
  136. this.restoreWindow();
  137. } else {
  138. this.minimizeWindow();
  139. }
  140. }, closeWindow:function (evt) {
  141. dojo.html.removeNode(this.domNode);
  142. this.destroy();
  143. }, onMouseDown:function (evt) {
  144. this.bringToTop();
  145. }, bringToTop:function () {
  146. var floatingPanes = dojo.widget.manager.getWidgetsByType(this.widgetType);
  147. var windows = [];
  148. for (var x = 0; x < floatingPanes.length; x++) {
  149. if (this.widgetId != floatingPanes[x].widgetId) {
  150. windows.push(floatingPanes[x]);
  151. }
  152. }
  153. windows.sort(function (a, b) {
  154. return a.domNode.style.zIndex - b.domNode.style.zIndex;
  155. });
  156. windows.push(this);
  157. var floatingPaneStartingZ = 100;
  158. for (x = 0; x < windows.length; x++) {
  159. windows[x].domNode.style.zIndex = floatingPaneStartingZ + x * 2;
  160. }
  161. }, _setInitialWindowState:function () {
  162. if (this.isShowing()) {
  163. this.width = -1;
  164. var mb = dojo.html.getMarginBox(this.domNode);
  165. this.resizeTo(mb.width, mb.height);
  166. }
  167. if (this.windowState == "maximized") {
  168. this.maximizeWindow();
  169. this.show();
  170. return;
  171. }
  172. if (this.windowState == "normal") {
  173. this.show();
  174. return;
  175. }
  176. if (this.windowState == "minimized") {
  177. this.hide();
  178. return;
  179. }
  180. this.windowState = "minimized";
  181. }, _taskBarSetup:function () {
  182. var taskbar = dojo.widget.getWidgetById(this.taskBarId);
  183. if (!taskbar) {
  184. if (this._taskBarConnectAttempts < this._max_taskBarConnectAttempts) {
  185. dojo.lang.setTimeout(this, this._taskBarSetup, 50);
  186. this._taskBarConnectAttempts++;
  187. } else {
  188. dojo.debug("Unable to connect to the taskBar");
  189. }
  190. return;
  191. }
  192. taskbar.addChild(this);
  193. }, showFloatingPane:function () {
  194. this.bringToTop();
  195. }, onFloatingPaneShow:function () {
  196. var mb = dojo.html.getMarginBox(this.domNode);
  197. this.resizeTo(mb.width, mb.height);
  198. }, resizeTo:function (width, height) {
  199. dojo.html.setMarginBox(this.domNode, {width:width, height:height});
  200. dojo.widget.html.layout(this.domNode, [{domNode:this.titleBar, layoutAlign:"top"}, {domNode:this.resizeBar, layoutAlign:"bottom"}, {domNode:this.containerNode, layoutAlign:"client"}]);
  201. dojo.widget.html.layout(this.containerNode, this.children, "top-bottom");
  202. this.bgIframe.onResized();
  203. if (this.shadow) {
  204. this.shadow.size(width, height);
  205. }
  206. this.onResized();
  207. }, checkSize:function () {
  208. }, destroyFloatingPane:function () {
  209. if (this.resizeHandle) {
  210. this.resizeHandle.destroy();
  211. this.resizeHandle = null;
  212. }
  213. }});
  214. dojo.widget.defineWidget("dojo.widget.FloatingPane", [dojo.widget.ContentPane, dojo.widget.FloatingPaneBase], {fillInTemplate:function (args, frag) {
  215. this.fillInFloatingPaneTemplate(args, frag);
  216. dojo.widget.FloatingPane.superclass.fillInTemplate.call(this, args, frag);
  217. }, postCreate:function () {
  218. dojo.widget.FloatingPaneBase.prototype.postCreate.apply(this, arguments);
  219. dojo.widget.FloatingPane.superclass.postCreate.apply(this, arguments);
  220. }, show:function () {
  221. dojo.widget.FloatingPane.superclass.show.apply(this, arguments);
  222. this.showFloatingPane();
  223. }, onShow:function () {
  224. dojo.widget.FloatingPane.superclass.onShow.call(this);
  225. this.onFloatingPaneShow();
  226. }, destroy:function () {
  227. this.destroyFloatingPane();
  228. dojo.widget.FloatingPane.superclass.destroy.apply(this, arguments);
  229. }});
  230. dojo.widget.defineWidget("dojo.widget.ModalFloatingPane", [dojo.widget.FloatingPane, dojo.widget.ModalDialogBase], {windowState:"minimized", displayCloseAction:true, postCreate:function () {
  231. dojo.widget.ModalDialogBase.prototype.postCreate.call(this);
  232. dojo.widget.ModalFloatingPane.superclass.postCreate.call(this);
  233. }, show:function () {
  234. this.showModalDialog();
  235. dojo.widget.ModalFloatingPane.superclass.show.apply(this, arguments);
  236. this.bg.style.zIndex = this.domNode.style.zIndex - 1;
  237. }, hide:function () {
  238. this.hideModalDialog();
  239. dojo.widget.ModalFloatingPane.superclass.hide.apply(this, arguments);
  240. }, closeWindow:function () {
  241. this.hide();
  242. dojo.widget.ModalFloatingPane.superclass.closeWindow.apply(this, arguments);
  243. }});