Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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