window_rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. data/CHANGELOG.rdoc +0 -0
  2. data/LICENSE +44 -0
  3. data/README.rdoc +68 -0
  4. data/app/controllers/window_rails_controller.rb +32 -0
  5. data/files/javascripts/debug.js +137 -0
  6. data/files/javascripts/extended_debug.js +113 -0
  7. data/files/javascripts/tooltip.js +241 -0
  8. data/files/javascripts/window.js +1872 -0
  9. data/files/javascripts/window_effects.js +157 -0
  10. data/files/javascripts/window_ext.js +115 -0
  11. data/files/themes/alert.css +119 -0
  12. data/files/themes/alert/bottom.gif +0 -0
  13. data/files/themes/alert/bottom_left.gif +0 -0
  14. data/files/themes/alert/bottom_right.gif +0 -0
  15. data/files/themes/alert/left.gif +0 -0
  16. data/files/themes/alert/overlay.png +0 -0
  17. data/files/themes/alert/progress.gif +0 -0
  18. data/files/themes/alert/right.gif +0 -0
  19. data/files/themes/alert/top.gif +0 -0
  20. data/files/themes/alert/top_left.gif +0 -0
  21. data/files/themes/alert/top_right.gif +0 -0
  22. data/files/themes/alert_lite.css +88 -0
  23. data/files/themes/alphacube.css +150 -0
  24. data/files/themes/alphacube/bottom-left-c.gif +0 -0
  25. data/files/themes/alphacube/bottom-middle.gif +0 -0
  26. data/files/themes/alphacube/bottom-right-c.gif +0 -0
  27. data/files/themes/alphacube/button-close-focus.gif +0 -0
  28. data/files/themes/alphacube/button-max-focus.gif +0 -0
  29. data/files/themes/alphacube/button-min-focus.gif +0 -0
  30. data/files/themes/alphacube/frame-left.gif +0 -0
  31. data/files/themes/alphacube/frame-right.gif +0 -0
  32. data/files/themes/alphacube/left-top.gif +0 -0
  33. data/files/themes/alphacube/right-top.gif +0 -0
  34. data/files/themes/alphacube/top-middle.gif +0 -0
  35. data/files/themes/behavior.htc +51 -0
  36. data/files/themes/darkX.css +121 -0
  37. data/files/themes/darkX/button-close-focused.png +0 -0
  38. data/files/themes/darkX/button-maximize-focused.png +0 -0
  39. data/files/themes/darkX/button-minimize-focused.png +0 -0
  40. data/files/themes/darkX/frame-bottom-left-focused.png +0 -0
  41. data/files/themes/darkX/frame-bottom-mid-focused.png +0 -0
  42. data/files/themes/darkX/frame-bottom-right-focused.png +0 -0
  43. data/files/themes/darkX/frame-left-focused.png +0 -0
  44. data/files/themes/darkX/frame-right-focused.png +0 -0
  45. data/files/themes/darkX/titlebar-left-focused.png +0 -0
  46. data/files/themes/darkX/titlebar-mid-focused.png +0 -0
  47. data/files/themes/darkX/titlebar-right-focused.png +0 -0
  48. data/files/themes/debug.css +25 -0
  49. data/files/themes/default.css +155 -0
  50. data/files/themes/default/bottom_left.gif +0 -0
  51. data/files/themes/default/bottom_mid.gif +0 -0
  52. data/files/themes/default/bottom_right.gif +0 -0
  53. data/files/themes/default/bottom_right_resize.gif +0 -0
  54. data/files/themes/default/center_left.gif +0 -0
  55. data/files/themes/default/center_right.gif +0 -0
  56. data/files/themes/default/clear.gif +0 -0
  57. data/files/themes/default/close.gif +0 -0
  58. data/files/themes/default/inspect.gif +0 -0
  59. data/files/themes/default/maximize.gif +0 -0
  60. data/files/themes/default/minimize.gif +0 -0
  61. data/files/themes/default/overlay.png +0 -0
  62. data/files/themes/default/resize.gif +0 -0
  63. data/files/themes/default/sizer.gif +0 -0
  64. data/files/themes/default/top_left.gif +0 -0
  65. data/files/themes/default/top_mid.gif +0 -0
  66. data/files/themes/default/top_right.gif +0 -0
  67. data/files/themes/iefix/blank.gif +0 -0
  68. data/files/themes/iefix/iepngfix.css +3 -0
  69. data/files/themes/iefix/iepngfix.htc +54 -0
  70. data/files/themes/lighting.css +960 -0
  71. data/files/themes/lighting/background_buttons.gif +0 -0
  72. data/files/themes/lighting/bottom-left-blue.png +0 -0
  73. data/files/themes/lighting/bottom-left-darkblue.png +0 -0
  74. data/files/themes/lighting/bottom-left-green.png +0 -0
  75. data/files/themes/lighting/bottom-left-grey.png +0 -0
  76. data/files/themes/lighting/bottom-middle-blue.png +0 -0
  77. data/files/themes/lighting/bottom-middle-darkblue.png +0 -0
  78. data/files/themes/lighting/bottom-middle-green.png +0 -0
  79. data/files/themes/lighting/bottom-middle-grey.png +0 -0
  80. data/files/themes/lighting/bottom-right-blue.png +0 -0
  81. data/files/themes/lighting/bottom-right-darkblue.png +0 -0
  82. data/files/themes/lighting/bottom-right-green.png +0 -0
  83. data/files/themes/lighting/bottom-right-grey.png +0 -0
  84. data/files/themes/lighting/button-close-blue.png +0 -0
  85. data/files/themes/lighting/button-close-darkblue.png +0 -0
  86. data/files/themes/lighting/button-close-green.png +0 -0
  87. data/files/themes/lighting/button-close-grey.png +0 -0
  88. data/files/themes/lighting/button-maximize-blue.png +0 -0
  89. data/files/themes/lighting/button-maximize-darkblue.png +0 -0
  90. data/files/themes/lighting/button-maximize-green.png +0 -0
  91. data/files/themes/lighting/button-maximize-grey.png +0 -0
  92. data/files/themes/lighting/button-minimize-blue.png +0 -0
  93. data/files/themes/lighting/button-minimize-darkblue.png +0 -0
  94. data/files/themes/lighting/button-minimize-green.png +0 -0
  95. data/files/themes/lighting/button-minimize-grey.png +0 -0
  96. data/files/themes/lighting/left-blue.png +0 -0
  97. data/files/themes/lighting/left-darkblue.png +0 -0
  98. data/files/themes/lighting/left-green.png +0 -0
  99. data/files/themes/lighting/left-grey.png +0 -0
  100. data/files/themes/lighting/pngbehavior.htc +67 -0
  101. data/files/themes/lighting/right-blue.png +0 -0
  102. data/files/themes/lighting/right-darkblue.png +0 -0
  103. data/files/themes/lighting/right-green.png +0 -0
  104. data/files/themes/lighting/right-grey.png +0 -0
  105. data/files/themes/lighting/spinner.gif +0 -0
  106. data/files/themes/lighting/top-left-blue.png +0 -0
  107. data/files/themes/lighting/top-left-darkblue.png +0 -0
  108. data/files/themes/lighting/top-left-green.png +0 -0
  109. data/files/themes/lighting/top-left-grey.png +0 -0
  110. data/files/themes/lighting/top-middle-blue.png +0 -0
  111. data/files/themes/lighting/top-middle-darkblue.png +0 -0
  112. data/files/themes/lighting/top-middle-green.png +0 -0
  113. data/files/themes/lighting/top-middle-grey.png +0 -0
  114. data/files/themes/lighting/top-right-blue.png +0 -0
  115. data/files/themes/lighting/top-right-darkblue.png +0 -0
  116. data/files/themes/lighting/top-right-green.png +0 -0
  117. data/files/themes/lighting/top-right-grey.png +0 -0
  118. data/files/themes/mac_os_x.css +333 -0
  119. data/files/themes/mac_os_x/B.png +0 -0
  120. data/files/themes/mac_os_x/BL.png +0 -0
  121. data/files/themes/mac_os_x/BL_Main.png +0 -0
  122. data/files/themes/mac_os_x/BR.png +0 -0
  123. data/files/themes/mac_os_x/BR_Main.png +0 -0
  124. data/files/themes/mac_os_x/B_Main.png +0 -0
  125. data/files/themes/mac_os_x/L.png +0 -0
  126. data/files/themes/mac_os_x/L_Main.png +0 -0
  127. data/files/themes/mac_os_x/R.png +0 -0
  128. data/files/themes/mac_os_x/R_Main.png +0 -0
  129. data/files/themes/mac_os_x/T.png +0 -0
  130. data/files/themes/mac_os_x/TL.png +0 -0
  131. data/files/themes/mac_os_x/TL_Main.png +0 -0
  132. data/files/themes/mac_os_x/TR.png +0 -0
  133. data/files/themes/mac_os_x/TR_Main.png +0 -0
  134. data/files/themes/mac_os_x/T_Main.png +0 -0
  135. data/files/themes/mac_os_x/close.gif +0 -0
  136. data/files/themes/mac_os_x/maximize.gif +0 -0
  137. data/files/themes/mac_os_x/minimize.gif +0 -0
  138. data/files/themes/mac_os_x_dialog.css +160 -0
  139. data/files/themes/mac_os_x_dialog/B.png +0 -0
  140. data/files/themes/mac_os_x_dialog/BL.png +0 -0
  141. data/files/themes/mac_os_x_dialog/BR.png +0 -0
  142. data/files/themes/mac_os_x_dialog/L.png +0 -0
  143. data/files/themes/mac_os_x_dialog/R.png +0 -0
  144. data/files/themes/mac_os_x_dialog/T.png +0 -0
  145. data/files/themes/mac_os_x_dialog/TL.png +0 -0
  146. data/files/themes/mac_os_x_dialog/TR.png +0 -0
  147. data/files/themes/mac_os_x_dialog/bg.gif +0 -0
  148. data/files/themes/mac_os_x_dialog/close.gif +0 -0
  149. data/files/themes/mac_os_x_dialog/maximize.gif +0 -0
  150. data/files/themes/mac_os_x_dialog/minimize.gif +0 -0
  151. data/files/themes/nuncio.css +164 -0
  152. data/files/themes/nuncio/bottom_left.png +0 -0
  153. data/files/themes/nuncio/bottom_mid.png +0 -0
  154. data/files/themes/nuncio/bottom_right.png +0 -0
  155. data/files/themes/nuncio/center_left.png +0 -0
  156. data/files/themes/nuncio/center_right.png +0 -0
  157. data/files/themes/nuncio/close.png +0 -0
  158. data/files/themes/nuncio/minimize.png +0 -0
  159. data/files/themes/nuncio/overlay.png +0 -0
  160. data/files/themes/nuncio/top_left.png +0 -0
  161. data/files/themes/nuncio/top_mid.png +0 -0
  162. data/files/themes/nuncio/top_right.png +0 -0
  163. data/files/themes/spread.css +108 -0
  164. data/files/themes/spread/bottom-left-c.gif +0 -0
  165. data/files/themes/spread/bottom-middle.gif +0 -0
  166. data/files/themes/spread/bottom-right-c.gif +0 -0
  167. data/files/themes/spread/button-close-focus.gif +0 -0
  168. data/files/themes/spread/button-max-focus.gif +0 -0
  169. data/files/themes/spread/button-min-focus.gif +0 -0
  170. data/files/themes/spread/frame-left.gif +0 -0
  171. data/files/themes/spread/frame-right.gif +0 -0
  172. data/files/themes/spread/left-top.gif +0 -0
  173. data/files/themes/spread/right-top.gif +0 -0
  174. data/files/themes/spread/top-middle.gif +0 -0
  175. data/init.rb +1 -0
  176. data/install.rb +32 -0
  177. data/lib/window_rails.rb +164 -0
  178. data/lib/window_rails/version.rb +3 -0
  179. data/uninstall.rb +9 -0
  180. metadata +260 -0
@@ -0,0 +1,1872 @@
1
+ // Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining
4
+ // a copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to
8
+ // permit persons to whom the Software is furnished to do so, subject to
9
+ // the following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be
12
+ // included in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ //
22
+ // VERSION 1.3
23
+
24
+ var Window = Class.create();
25
+
26
+ Window.keepMultiModalWindow = false;
27
+ Window.hasEffectLib = (typeof Effect != 'undefined');
28
+ Window.resizeEffectDuration = 0.4;
29
+
30
+ Window.prototype = {
31
+ // Constructor
32
+ // Available parameters : className, blurClassName, title, minWidth, minHeight, maxWidth, maxHeight, width, height, top, left, bottom, right, resizable, zIndex, opacity, recenterAuto, wiredDrag
33
+ // hideEffect, showEffect, showEffectOptions, hideEffectOptions, effectOptions, url, draggable, closable, minimizable, maximizable, parent, onload
34
+ // add all callbacks (if you do not use an observer)
35
+ // onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBlur onBeforeShow onShow onHide onMinimize onMaximize onClose
36
+
37
+ initialize: function() {
38
+ var id;
39
+ var optionIndex = 0;
40
+ // For backward compatibility like win= new Window("id", {...}) instead of win = new Window({id: "id", ...})
41
+ if (arguments.length > 0) {
42
+ if (typeof arguments[0] == "string" ) {
43
+ id = arguments[0];
44
+ optionIndex = 1;
45
+ }
46
+ else
47
+ id = arguments[0] ? arguments[0].id : null;
48
+ }
49
+
50
+ // Generate unique ID if not specified
51
+ if (!id)
52
+ id = "window_" + new Date().getTime();
53
+
54
+ if ($(id))
55
+ alert("Window " + id + " is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");
56
+
57
+ this.options = Object.extend({
58
+ className: "dialog",
59
+ blurClassName: null,
60
+ minWidth: 100,
61
+ minHeight: 20,
62
+ resizable: true,
63
+ closable: true,
64
+ minimizable: true,
65
+ maximizable: true,
66
+ draggable: true,
67
+ userData: null,
68
+ showEffect: (Window.hasEffectLib ? Effect.Appear : Element.show),
69
+ hideEffect: (Window.hasEffectLib ? Effect.Fade : Element.hide),
70
+ showEffectOptions: {},
71
+ hideEffectOptions: {},
72
+ effectOptions: null,
73
+ parent: document.body,
74
+ title: " ",
75
+ url: null,
76
+ onload: Prototype.emptyFunction,
77
+ width: 200,
78
+ height: 300,
79
+ opacity: 1,
80
+ recenterAuto: true,
81
+ wiredDrag: false,
82
+ closeCallback: null,
83
+ destroyOnClose: false,
84
+ gridX: 1,
85
+ gridY: 1
86
+ }, arguments[optionIndex] || {});
87
+ if (this.options.blurClassName)
88
+ this.options.focusClassName = this.options.className;
89
+
90
+ if (typeof this.options.top == "undefined" && typeof this.options.bottom == "undefined")
91
+ this.options.top = this._round(Math.random()*500, this.options.gridY);
92
+ if (typeof this.options.left == "undefined" && typeof this.options.right == "undefined")
93
+ this.options.left = this._round(Math.random()*500, this.options.gridX);
94
+
95
+ if (this.options.effectOptions) {
96
+ Object.extend(this.options.hideEffectOptions, this.options.effectOptions);
97
+ Object.extend(this.options.showEffectOptions, this.options.effectOptions);
98
+ if (this.options.showEffect == Element.Appear)
99
+ this.options.showEffectOptions.to = this.options.opacity;
100
+ }
101
+ if (Window.hasEffectLib) {
102
+ if (this.options.showEffect == Effect.Appear)
103
+ this.options.showEffectOptions.to = this.options.opacity;
104
+
105
+ if (this.options.hideEffect == Effect.Fade)
106
+ this.options.hideEffectOptions.from = this.options.opacity;
107
+ }
108
+ if (this.options.hideEffect == Element.hide)
109
+ this.options.hideEffect = function(){ Element.hide(this.element); if (this.options.destroyOnClose) this.destroy(); }.bind(this)
110
+
111
+ if (this.options.parent != document.body)
112
+ this.options.parent = $(this.options.parent);
113
+
114
+ this.element = this._createWindow(id);
115
+ this.element.win = this;
116
+
117
+ // Bind event listener
118
+ this.eventMouseDown = this._initDrag.bindAsEventListener(this);
119
+ this.eventMouseUp = this._endDrag.bindAsEventListener(this);
120
+ this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
121
+ this.eventOnLoad = this._getWindowBorderSize.bindAsEventListener(this);
122
+ this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
123
+ this.eventResize = this._recenter.bindAsEventListener(this);
124
+
125
+ this.topbar = $(this.element.id + "_top");
126
+ this.bottombar = $(this.element.id + "_bottom");
127
+ this.content = $(this.element.id + "_content");
128
+
129
+ Event.observe(this.topbar, "mousedown", this.eventMouseDown);
130
+ Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
131
+ Event.observe(this.content, "mousedown", this.eventMouseDownContent);
132
+ Event.observe(window, "load", this.eventOnLoad);
133
+ Event.observe(window, "resize", this.eventResize);
134
+ Event.observe(window, "scroll", this.eventResize);
135
+ Event.observe(this.options.parent, "scroll", this.eventResize);
136
+
137
+ if (this.options.draggable) {
138
+ var that = this;
139
+ [this.topbar, this.topbar.up().previous(), this.topbar.up().next()].each(function(element) {
140
+ element.observe("mousedown", that.eventMouseDown);
141
+ element.addClassName("top_draggable");
142
+ });
143
+ [this.bottombar.up(), this.bottombar.up().previous(), this.bottombar.up().next()].each(function(element) {
144
+ element.observe("mousedown", that.eventMouseDown);
145
+ element.addClassName("bottom_draggable");
146
+ });
147
+
148
+ }
149
+
150
+ if (this.options.resizable) {
151
+ this.sizer = $(this.element.id + "_sizer");
152
+ Event.observe(this.sizer, "mousedown", this.eventMouseDown);
153
+ }
154
+
155
+ this.useLeft = null;
156
+ this.useTop = null;
157
+ if (typeof this.options.left != "undefined") {
158
+ this.element.setStyle({left: parseFloat(this.options.left) + 'px'});
159
+ this.useLeft = true;
160
+ }
161
+ else {
162
+ this.element.setStyle({right: parseFloat(this.options.right) + 'px'});
163
+ this.useLeft = false;
164
+ }
165
+
166
+ if (typeof this.options.top != "undefined") {
167
+ this.element.setStyle({top: parseFloat(this.options.top) + 'px'});
168
+ this.useTop = true;
169
+ }
170
+ else {
171
+ this.element.setStyle({bottom: parseFloat(this.options.bottom) + 'px'});
172
+ this.useTop = false;
173
+ }
174
+
175
+ this.storedLocation = null;
176
+
177
+ this.setOpacity(this.options.opacity);
178
+ if (this.options.zIndex)
179
+ this.setZIndex(this.options.zIndex)
180
+
181
+ if (this.options.destroyOnClose)
182
+ this.setDestroyOnClose(true);
183
+
184
+ this._getWindowBorderSize();
185
+ this.width = this.options.width;
186
+ this.height = this.options.height;
187
+ this.visible = false;
188
+
189
+ this.constraint = false;
190
+ this.constraintPad = {top: 0, left:0, bottom:0, right:0};
191
+
192
+ if (this.width && this.height)
193
+ this.setSize(this.options.width, this.options.height);
194
+ this.setTitle(this.options.title)
195
+ Windows.register(this);
196
+ },
197
+
198
+ // Destructor
199
+ destroy: function() {
200
+ this._notify("onDestroy");
201
+ Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
202
+ Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
203
+ Event.stopObserving(this.content, "mousedown", this.eventMouseDownContent);
204
+
205
+ Event.stopObserving(window, "load", this.eventOnLoad);
206
+ Event.stopObserving(window, "resize", this.eventResize);
207
+ Event.stopObserving(window, "scroll", this.eventResize);
208
+
209
+ Event.stopObserving(this.content, "load", this.options.onload);
210
+
211
+ if (this._oldParent) {
212
+ var content = this.getContent();
213
+ var originalContent = null;
214
+ for(var i = 0; i < content.childNodes.length; i++) {
215
+ originalContent = content.childNodes[i];
216
+ if (originalContent.nodeType == 1)
217
+ break;
218
+ originalContent = null;
219
+ }
220
+ if (originalContent)
221
+ this._oldParent.appendChild(originalContent);
222
+ this._oldParent = null;
223
+ }
224
+
225
+ if (this.sizer)
226
+ Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);
227
+
228
+ if (this.options.url)
229
+ this.content.src = null
230
+
231
+ if(this.iefix)
232
+ Element.remove(this.iefix);
233
+
234
+ Element.remove(this.element);
235
+ Windows.unregister(this);
236
+ },
237
+
238
+ // Sets close callback, if it sets, it should return true to be able to close the window.
239
+ setCloseCallback: function(callback) {
240
+ this.options.closeCallback = callback;
241
+ },
242
+
243
+ // Gets window content
244
+ getContent: function () {
245
+ return this.content;
246
+ },
247
+
248
+ // Sets the content with an element id
249
+ setContent: function(id, autoresize, autoposition) {
250
+ var element = $(id);
251
+ if (null == element) throw "Unable to find element '" + id + "' in DOM";
252
+ this._oldParent = element.parentNode;
253
+
254
+ var d = null;
255
+ var p = null;
256
+
257
+ if (autoresize)
258
+ d = Element.getDimensions(element);
259
+ if (autoposition)
260
+ p = Position.cumulativeOffset(element);
261
+
262
+ var content = this.getContent();
263
+ // Clear HTML (and even iframe)
264
+ this.setHTMLContent("");
265
+ content = this.getContent();
266
+
267
+ content.appendChild(element);
268
+ element.show();
269
+ if (autoresize)
270
+ this.setSize(d.width, d.height);
271
+ if (autoposition)
272
+ this.setLocation(p[1] - this.heightN, p[0] - this.widthW);
273
+ },
274
+
275
+ setHTMLContent: function(html) {
276
+ // It was an url (iframe), recreate a div content instead of iframe content
277
+ if (this.options.url) {
278
+ this.content.src = null;
279
+ this.options.url = null;
280
+
281
+ var content ="<div id=\"" + this.getId() + "_content\" class=\"" + this.options.className + "_content\"> </div>";
282
+ $(this.getId() +"_table_content").innerHTML = content;
283
+
284
+ this.content = $(this.element.id + "_content");
285
+ }
286
+ this.getContent().innerHTML = html;
287
+ },
288
+
289
+ setAjaxContent: function(url, options, showCentered, showModal) {
290
+ this.showFunction = showCentered ? "showCenter" : "show";
291
+ this.showModal = showModal || false;
292
+
293
+ options = options || {};
294
+
295
+ // Clear HTML (and even iframe)
296
+ this.setHTMLContent("");
297
+
298
+ this.onComplete = options.onComplete;
299
+ if (! this._onCompleteHandler)
300
+ this._onCompleteHandler = this._setAjaxContent.bind(this);
301
+ options.onComplete = this._onCompleteHandler;
302
+
303
+ new Ajax.Request(url, options);
304
+ options.onComplete = this.onComplete;
305
+ },
306
+
307
+ _setAjaxContent: function(originalRequest) {
308
+ Element.update(this.getContent(), originalRequest.responseText);
309
+ if (this.onComplete)
310
+ this.onComplete(originalRequest);
311
+ this.onComplete = null;
312
+ this[this.showFunction](this.showModal)
313
+ },
314
+
315
+ setURL: function(url) {
316
+ // Not an url content, change div to iframe
317
+ if (this.options.url)
318
+ this.content.src = null;
319
+ this.options.url = url;
320
+ var content= "<iframe frameborder='0' name='" + this.getId() + "_content' id='" + this.getId() + "_content' src='" + url + "' width='" + this.width + "' height='" + this.height + "'> </iframe>";
321
+ $(this.getId() +"_table_content").innerHTML = content;
322
+
323
+ this.content = $(this.element.id + "_content");
324
+ },
325
+
326
+ getURL: function() {
327
+ return this.options.url ? this.options.url : null;
328
+ },
329
+
330
+ refresh: function() {
331
+ if (this.options.url)
332
+ $(this.element.getAttribute('id') + '_content').src = this.options.url;
333
+ },
334
+
335
+ // Stores position/size in a cookie, by default named with window id
336
+ setCookie: function(name, expires, path, domain, secure) {
337
+ name = name || this.element.id;
338
+ this.cookie = [name, expires, path, domain, secure];
339
+
340
+ // Get cookie
341
+ var value = WindowUtilities.getCookie(name)
342
+ // If exists
343
+ if (value) {
344
+ var values = value.split(',');
345
+ var x = values[0].split(':');
346
+ var y = values[1].split(':');
347
+
348
+ var w = parseFloat(values[2]), h = parseFloat(values[3]);
349
+ var mini = values[4];
350
+ var maxi = values[5];
351
+
352
+ this.setSize(w, h);
353
+ if (mini == "true")
354
+ this.doMinimize = true; // Minimize will be done at onload window event
355
+ else if (maxi == "true")
356
+ this.doMaximize = true; // Maximize will be done at onload window event
357
+
358
+ this.useLeft = x[0] == "l";
359
+ this.useTop = y[0] == "t";
360
+
361
+ this.element.setStyle(this.useLeft ? {left: x[1]} : {right: x[1]});
362
+ this.element.setStyle(this.useTop ? {top: y[1]} : {bottom: y[1]});
363
+ }
364
+ },
365
+
366
+ // Gets window ID
367
+ getId: function() {
368
+ return this.element.id;
369
+ },
370
+
371
+ // Detroys itself when closing
372
+ setDestroyOnClose: function() {
373
+ this.options.destroyOnClose = true;
374
+ },
375
+
376
+ setConstraint: function(bool, padding) {
377
+ this.constraint = bool;
378
+ this.constraintPad = Object.extend(this.constraintPad, padding || {});
379
+ // Reset location to apply constraint
380
+ if (this.useTop && this.useLeft)
381
+ this.setLocation(parseFloat(this.element.style.top), parseFloat(this.element.style.left));
382
+ },
383
+
384
+ // initDrag event
385
+
386
+ _initDrag: function(event) {
387
+ // No resize on minimized window
388
+ if (Event.element(event) == this.sizer && this.isMinimized())
389
+ return;
390
+
391
+ // No move on maximzed window
392
+ if (Event.element(event) != this.sizer && this.isMaximized())
393
+ return;
394
+
395
+ if (Prototype.Browser.IE && this.heightN == 0)
396
+ this._getWindowBorderSize();
397
+
398
+ // Get pointer X,Y
399
+ this.pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
400
+ if (this.options.wiredDrag)
401
+ this.currentDrag = this._createWiredElement();
402
+ else
403
+ this.currentDrag = this.element;
404
+
405
+ // Resize
406
+ if (Event.element(event) == this.sizer) {
407
+ this.doResize = true;
408
+ this.widthOrg = this.width;
409
+ this.heightOrg = this.height;
410
+ this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
411
+ this.rightOrg = parseFloat(this.element.getStyle('right'));
412
+ this._notify("onStartResize");
413
+ }
414
+ else {
415
+ this.doResize = false;
416
+
417
+ // Check if click on close button,
418
+ var closeButton = $(this.getId() + '_close');
419
+ if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) {
420
+ this.currentDrag = null;
421
+ return;
422
+ }
423
+
424
+ this.toFront();
425
+
426
+ if (! this.options.draggable)
427
+ return;
428
+ this._notify("onStartMove");
429
+ }
430
+ // Register global event to capture mouseUp and mouseMove
431
+ Event.observe(document, "mouseup", this.eventMouseUp, false);
432
+ Event.observe(document, "mousemove", this.eventMouseMove, false);
433
+
434
+ // Add an invisible div to keep catching mouse event over iframes
435
+ WindowUtilities.disableScreen('__invisible__', '__invisible__', this.overlayOpacity);
436
+
437
+ // Stop selection while dragging
438
+ document.body.ondrag = function () { return false; };
439
+ document.body.onselectstart = function () { return false; };
440
+
441
+ this.currentDrag.show();
442
+ Event.stop(event);
443
+ },
444
+
445
+ _round: function(val, round) {
446
+ return round == 1 ? val : val = Math.floor(val / round) * round;
447
+ },
448
+
449
+ // updateDrag event
450
+ _updateDrag: function(event) {
451
+ var pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
452
+ var dx = pointer[0] - this.pointer[0];
453
+ var dy = pointer[1] - this.pointer[1];
454
+
455
+ // Resize case, update width/height
456
+ if (this.doResize) {
457
+ var w = this.widthOrg + dx;
458
+ var h = this.heightOrg + dy;
459
+
460
+ dx = this.width - this.widthOrg
461
+ dy = this.height - this.heightOrg
462
+
463
+ // Check if it's a right position, update it to keep upper-left corner at the same position
464
+ if (this.useLeft)
465
+ w = this._updateWidthConstraint(w)
466
+ else
467
+ this.currentDrag.setStyle({right: (this.rightOrg -dx) + 'px'});
468
+ // Check if it's a bottom position, update it to keep upper-left corner at the same position
469
+ if (this.useTop)
470
+ h = this._updateHeightConstraint(h)
471
+ else
472
+ this.currentDrag.setStyle({bottom: (this.bottomOrg -dy) + 'px'});
473
+
474
+ this.setSize(w , h);
475
+ this._notify("onResize");
476
+ }
477
+ // Move case, update top/left
478
+ else {
479
+ this.pointer = pointer;
480
+
481
+ if (this.useLeft) {
482
+ var left = parseFloat(this.currentDrag.getStyle('left')) + dx;
483
+ var newLeft = this._updateLeftConstraint(left);
484
+ // Keep mouse pointer correct
485
+ this.pointer[0] += newLeft-left;
486
+ this.currentDrag.setStyle({left: newLeft + 'px'});
487
+ }
488
+ else
489
+ this.currentDrag.setStyle({right: parseFloat(this.currentDrag.getStyle('right')) - dx + 'px'});
490
+
491
+ if (this.useTop) {
492
+ var top = parseFloat(this.currentDrag.getStyle('top')) + dy;
493
+ var newTop = this._updateTopConstraint(top);
494
+ // Keep mouse pointer correct
495
+ this.pointer[1] += newTop - top;
496
+ this.currentDrag.setStyle({top: newTop + 'px'});
497
+ }
498
+ else
499
+ this.currentDrag.setStyle({bottom: parseFloat(this.currentDrag.getStyle('bottom')) - dy + 'px'});
500
+
501
+ this._notify("onMove");
502
+ }
503
+ if (this.iefix)
504
+ this._fixIEOverlapping();
505
+
506
+ this._removeStoreLocation();
507
+ Event.stop(event);
508
+ },
509
+
510
+ // endDrag callback
511
+ _endDrag: function(event) {
512
+ // Remove temporary div over iframes
513
+ WindowUtilities.enableScreen('__invisible__');
514
+
515
+ if (this.doResize)
516
+ this._notify("onEndResize");
517
+ else
518
+ this._notify("onEndMove");
519
+
520
+ // Release event observing
521
+ Event.stopObserving(document, "mouseup", this.eventMouseUp,false);
522
+ Event.stopObserving(document, "mousemove", this.eventMouseMove, false);
523
+
524
+ Event.stop(event);
525
+
526
+ this._hideWiredElement();
527
+
528
+ // Store new location/size if need be
529
+ this._saveCookie()
530
+
531
+ // Restore selection
532
+ document.body.ondrag = null;
533
+ document.body.onselectstart = null;
534
+ },
535
+
536
+ _updateLeftConstraint: function(left) {
537
+ if (this.constraint && this.useLeft && this.useTop) {
538
+ var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
539
+
540
+ if (left < this.constraintPad.left)
541
+ left = this.constraintPad.left;
542
+ if (left + this.width + this.widthE + this.widthW > width - this.constraintPad.right)
543
+ left = width - this.constraintPad.right - this.width - this.widthE - this.widthW;
544
+ }
545
+ return left;
546
+ },
547
+
548
+ _updateTopConstraint: function(top) {
549
+ if (this.constraint && this.useLeft && this.useTop) {
550
+ var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
551
+
552
+ var h = this.height + this.heightN + this.heightS;
553
+
554
+ if (top < this.constraintPad.top)
555
+ top = this.constraintPad.top;
556
+ if (top + h > height - this.constraintPad.bottom)
557
+ top = height - this.constraintPad.bottom - h;
558
+ }
559
+ return top;
560
+ },
561
+
562
+ _updateWidthConstraint: function(w) {
563
+ if (this.constraint && this.useLeft && this.useTop) {
564
+ var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
565
+ var left = parseFloat(this.element.getStyle("left"));
566
+
567
+ if (left + w + this.widthE + this.widthW > width - this.constraintPad.right)
568
+ w = width - this.constraintPad.right - left - this.widthE - this.widthW;
569
+ }
570
+ return w;
571
+ },
572
+
573
+ _updateHeightConstraint: function(h) {
574
+ if (this.constraint && this.useLeft && this.useTop) {
575
+ var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
576
+ var top = parseFloat(this.element.getStyle("top"));
577
+
578
+ if (top + h + this.heightN + this.heightS > height - this.constraintPad.bottom)
579
+ h = height - this.constraintPad.bottom - top - this.heightN - this.heightS;
580
+ }
581
+ return h;
582
+ },
583
+
584
+
585
+ // Creates HTML window code
586
+ _createWindow: function(id) {
587
+ var className = this.options.className;
588
+ var win = document.createElement("div");
589
+ win.setAttribute('id', id);
590
+ win.className = "dialog";
591
+
592
+ var content;
593
+ if (this.options.url)
594
+ content= "<iframe frameborder=\"0\" name=\"" + id + "_content\" id=\"" + id + "_content\" src=\"" + this.options.url + "\"> </iframe>";
595
+ else
596
+ content ="<div id=\"" + id + "_content\" class=\"" +className + "_content\"> </div>";
597
+
598
+ var closeDiv = this.options.closable ? "<div class='"+ className +"_close' id='"+ id +"_close' onclick='Windows.close(\""+ id +"\", event)'> </div>" : "";
599
+ var minDiv = this.options.minimizable ? "<div class='"+ className + "_minimize' id='"+ id +"_minimize' onclick='Windows.minimize(\""+ id +"\", event)'> </div>" : "";
600
+ var maxDiv = this.options.maximizable ? "<div class='"+ className + "_maximize' id='"+ id +"_maximize' onclick='Windows.maximize(\""+ id +"\", event)'> </div>" : "";
601
+ var seAttributes = this.options.resizable ? "class='" + className + "_sizer' id='" + id + "_sizer'" : "class='" + className + "_se'";
602
+ var blank = "../themes/default/blank.gif";
603
+
604
+ win.innerHTML = closeDiv + minDiv + maxDiv + "\
605
+ <table id='"+ id +"_row1' class=\"top table_window\">\
606
+ <tr>\
607
+ <td class='"+ className +"_nw'></td>\
608
+ <td class='"+ className +"_n'><div id='"+ id +"_top' class='"+ className +"_title title_window'>"+ this.options.title +"</div></td>\
609
+ <td class='"+ className +"_ne'></td>\
610
+ </tr>\
611
+ </table>\
612
+ <table id='"+ id +"_row2' class=\"mid table_window\">\
613
+ <tr>\
614
+ <td class='"+ className +"_w'></td>\
615
+ <td id='"+ id +"_table_content' class='"+ className +"_content' valign='top'>" + content + "</td>\
616
+ <td class='"+ className +"_e'></td>\
617
+ </tr>\
618
+ </table>\
619
+ <table id='"+ id +"_row3' class=\"bot table_window\">\
620
+ <tr>\
621
+ <td class='"+ className +"_sw'></td>\
622
+ <td class='"+ className +"_s'><div id='"+ id +"_bottom' class='status_bar'><span style='float:left; width:1px; height:1px'></span></div></td>\
623
+ <td " + seAttributes + "></td>\
624
+ </tr>\
625
+ </table>\
626
+ ";
627
+ Element.hide(win);
628
+ this.options.parent.insertBefore(win, this.options.parent.firstChild);
629
+ Event.observe($(id + "_content"), "load", this.options.onload);
630
+ return win;
631
+ },
632
+
633
+
634
+ changeClassName: function(newClassName) {
635
+ var className = this.options.className;
636
+ var id = this.getId();
637
+ $A(["_close", "_minimize", "_maximize", "_sizer", "_content"]).each(function(value) { this._toggleClassName($(id + value), className + value, newClassName + value) }.bind(this));
638
+ this._toggleClassName($(id + "_top"), className + "_title", newClassName + "_title");
639
+ $$("#" + id + " td").each(function(td) {td.className = td.className.sub(className,newClassName); });
640
+ this.options.className = newClassName;
641
+ },
642
+
643
+ _toggleClassName: function(element, oldClassName, newClassName) {
644
+ if (element) {
645
+ element.removeClassName(oldClassName);
646
+ element.addClassName(newClassName);
647
+ }
648
+ },
649
+
650
+ // Sets window location
651
+ setLocation: function(top, left) {
652
+ top = this._updateTopConstraint(top);
653
+ left = this._updateLeftConstraint(left);
654
+
655
+ var e = this.currentDrag || this.element;
656
+ e.setStyle({top: top + 'px'});
657
+ e.setStyle({left: left + 'px'});
658
+
659
+ this.useLeft = true;
660
+ this.useTop = true;
661
+ },
662
+
663
+ getLocation: function() {
664
+ var location = {};
665
+ if (this.useTop)
666
+ location = Object.extend(location, {top: this.element.getStyle("top")});
667
+ else
668
+ location = Object.extend(location, {bottom: this.element.getStyle("bottom")});
669
+ if (this.useLeft)
670
+ location = Object.extend(location, {left: this.element.getStyle("left")});
671
+ else
672
+ location = Object.extend(location, {right: this.element.getStyle("right")});
673
+
674
+ return location;
675
+ },
676
+
677
+ // Gets window size
678
+ getSize: function() {
679
+ return {width: this.width, height: this.height};
680
+ },
681
+
682
+ // Sets window size
683
+ setSize: function(width, height, useEffect) {
684
+ width = parseFloat(width);
685
+ height = parseFloat(height);
686
+
687
+ // Check min and max size
688
+ if (!this.minimized && width < this.options.minWidth)
689
+ width = this.options.minWidth;
690
+
691
+ if (!this.minimized && height < this.options.minHeight)
692
+ height = this.options.minHeight;
693
+
694
+ if (this.options. maxHeight && height > this.options. maxHeight)
695
+ height = this.options. maxHeight;
696
+
697
+ if (this.options. maxWidth && width > this.options. maxWidth)
698
+ width = this.options. maxWidth;
699
+
700
+
701
+ if (this.useTop && this.useLeft && Window.hasEffectLib && Effect.ResizeWindow && useEffect) {
702
+ new Effect.ResizeWindow(this, null, null, width, height, {duration: Window.resizeEffectDuration});
703
+ } else {
704
+ this.width = width;
705
+ this.height = height;
706
+ var e = this.currentDrag ? this.currentDrag : this.element;
707
+
708
+ e.setStyle({width: width + this.widthW + this.widthE + "px"})
709
+ e.setStyle({height: height + this.heightN + this.heightS + "px"})
710
+
711
+ // Update content size
712
+ if (!this.currentDrag || this.currentDrag == this.element) {
713
+ var content = $(this.element.id + '_content');
714
+ content.setStyle({height: height + 'px'});
715
+ content.setStyle({width: width + 'px'});
716
+ }
717
+ }
718
+ },
719
+
720
+ updateHeight: function() {
721
+ this.setSize(this.width, this.content.scrollHeight, true);
722
+ },
723
+
724
+ updateWidth: function() {
725
+ this.setSize(this.content.scrollWidth, this.height, true);
726
+ },
727
+
728
+ // Brings window to front
729
+ toFront: function() {
730
+ if (this.element.style.zIndex < Windows.maxZIndex)
731
+ this.setZIndex(Windows.maxZIndex + 1);
732
+ if (this.iefix)
733
+ this._fixIEOverlapping();
734
+ },
735
+
736
+ getBounds: function(insideOnly) {
737
+ if (! this.width || !this.height || !this.visible)
738
+ this.computeBounds();
739
+ var w = this.width;
740
+ var h = this.height;
741
+
742
+ if (!insideOnly) {
743
+ w += this.widthW + this.widthE;
744
+ h += this.heightN + this.heightS;
745
+ }
746
+ var bounds = Object.extend(this.getLocation(), {width: w + "px", height: h + "px"});
747
+ return bounds;
748
+ },
749
+
750
+ computeBounds: function() {
751
+ if (! this.width || !this.height) {
752
+ var size = WindowUtilities._computeSize(this.content.innerHTML, this.content.id, this.width, this.height, 0, this.options.className)
753
+ if (this.height)
754
+ this.width = size + 5
755
+ else
756
+ this.height = size + 5
757
+ }
758
+
759
+ this.setSize(this.width, this.height);
760
+ if (this.centered)
761
+ this._center(this.centerTop, this.centerLeft);
762
+ },
763
+
764
+ // Displays window modal state or not
765
+ show: function(modal) {
766
+ this.visible = true;
767
+ if (modal) {
768
+ // Hack for Safari !!
769
+ if (typeof this.overlayOpacity == "undefined") {
770
+ var that = this;
771
+ setTimeout(function() {that.show(modal)}, 10);
772
+ return;
773
+ }
774
+ Windows.addModalWindow(this);
775
+
776
+ this.modal = true;
777
+ this.setZIndex(Windows.maxZIndex + 1);
778
+ Windows.unsetOverflow(this);
779
+ }
780
+ else
781
+ if (!this.element.style.zIndex)
782
+ this.setZIndex(Windows.maxZIndex + 1);
783
+
784
+ // To restore overflow if need be
785
+ if (this.oldStyle)
786
+ this.getContent().setStyle({overflow: this.oldStyle});
787
+
788
+ this.computeBounds();
789
+
790
+ this._notify("onBeforeShow");
791
+ if (this.options.showEffect != Element.show && this.options.showEffectOptions)
792
+ this.options.showEffect(this.element, this.options.showEffectOptions);
793
+ else
794
+ this.options.showEffect(this.element);
795
+
796
+ this._checkIEOverlapping();
797
+ WindowUtilities.focusedWindow = this
798
+ this._notify("onShow");
799
+ },
800
+
801
+ // Displays window modal state or not at the center of the page
802
+ showCenter: function(modal, top, left) {
803
+ this.centered = true;
804
+ this.centerTop = top;
805
+ this.centerLeft = left;
806
+
807
+ this.show(modal);
808
+ },
809
+
810
+ isVisible: function() {
811
+ return this.visible;
812
+ },
813
+
814
+ _center: function(top, left) {
815
+ var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
816
+ var pageSize = WindowUtilities.getPageSize(this.options.parent);
817
+ if (typeof top == "undefined")
818
+ top = (pageSize.windowHeight - (this.height + this.heightN + this.heightS))/2;
819
+ top += windowScroll.top
820
+
821
+ if (typeof left == "undefined")
822
+ left = (pageSize.windowWidth - (this.width + this.widthW + this.widthE))/2;
823
+ left += windowScroll.left
824
+ this.setLocation(top, left);
825
+ this.toFront();
826
+ },
827
+
828
+ _recenter: function(event) {
829
+ if (this.centered) {
830
+ var pageSize = WindowUtilities.getPageSize(this.options.parent);
831
+ var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
832
+
833
+ // Check for this stupid IE that sends dumb events
834
+ if (this.pageSize && this.pageSize.windowWidth == pageSize.windowWidth && this.pageSize.windowHeight == pageSize.windowHeight &&
835
+ this.windowScroll.left == windowScroll.left && this.windowScroll.top == windowScroll.top)
836
+ return;
837
+ this.pageSize = pageSize;
838
+ this.windowScroll = windowScroll;
839
+ // set height of Overlay to take up whole page and show
840
+ if ($('overlay_modal'))
841
+ $('overlay_modal').setStyle({height: (pageSize.pageHeight + 'px')});
842
+
843
+ if (this.options.recenterAuto)
844
+ this._center(this.centerTop, this.centerLeft);
845
+ }
846
+ },
847
+
848
+ // Hides window
849
+ hide: function() {
850
+ this.visible = false;
851
+ if (this.modal) {
852
+ Windows.removeModalWindow(this);
853
+ Windows.resetOverflow();
854
+ }
855
+ // To avoid bug on scrolling bar
856
+ this.oldStyle = this.getContent().getStyle('overflow') || "auto"
857
+ this.getContent().setStyle({overflow: "hidden"});
858
+
859
+ this.options.hideEffect(this.element, this.options.hideEffectOptions);
860
+
861
+ if(this.iefix)
862
+ this.iefix.hide();
863
+
864
+ if (!this.doNotNotifyHide)
865
+ this._notify("onHide");
866
+ },
867
+
868
+ close: function() {
869
+ // Asks closeCallback if exists
870
+ if (this.visible) {
871
+ if (this.options.closeCallback && ! this.options.closeCallback(this))
872
+ return;
873
+
874
+ if (this.options.destroyOnClose) {
875
+ var destroyFunc = this.destroy.bind(this);
876
+ if (this.options.hideEffectOptions.afterFinish) {
877
+ var func = this.options.hideEffectOptions.afterFinish;
878
+ this.options.hideEffectOptions.afterFinish = function() {func();destroyFunc() }
879
+ }
880
+ else
881
+ this.options.hideEffectOptions.afterFinish = function() {destroyFunc() }
882
+ }
883
+ Windows.updateFocusedWindow();
884
+
885
+ this.doNotNotifyHide = true;
886
+ this.hide();
887
+ this.doNotNotifyHide = false;
888
+ this._notify("onClose");
889
+ }
890
+ },
891
+
892
+ minimize: function() {
893
+ if (this.resizing)
894
+ return;
895
+
896
+ var r2 = $(this.getId() + "_row2");
897
+
898
+ if (!this.minimized) {
899
+ this.minimized = true;
900
+
901
+ var dh = r2.getDimensions().height;
902
+ this.r2Height = dh;
903
+ var h = this.element.getHeight() - dh;
904
+
905
+ if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
906
+ new Effect.ResizeWindow(this, null, null, null, this.height -dh, {duration: Window.resizeEffectDuration});
907
+ } else {
908
+ this.height -= dh;
909
+ this.element.setStyle({height: h + "px"});
910
+ r2.hide();
911
+ }
912
+
913
+ if (! this.useTop) {
914
+ var bottom = parseFloat(this.element.getStyle('bottom'));
915
+ this.element.setStyle({bottom: (bottom + dh) + 'px'});
916
+ }
917
+ }
918
+ else {
919
+ this.minimized = false;
920
+
921
+ var dh = this.r2Height;
922
+ this.r2Height = null;
923
+ if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
924
+ new Effect.ResizeWindow(this, null, null, null, this.height + dh, {duration: Window.resizeEffectDuration});
925
+ }
926
+ else {
927
+ var h = this.element.getHeight() + dh;
928
+ this.height += dh;
929
+ this.element.setStyle({height: h + "px"})
930
+ r2.show();
931
+ }
932
+ if (! this.useTop) {
933
+ var bottom = parseFloat(this.element.getStyle('bottom'));
934
+ this.element.setStyle({bottom: (bottom - dh) + 'px'});
935
+ }
936
+ this.toFront();
937
+ }
938
+ this._notify("onMinimize");
939
+
940
+ // Store new location/size if need be
941
+ this._saveCookie()
942
+ },
943
+
944
+ maximize: function() {
945
+ if (this.isMinimized() || this.resizing)
946
+ return;
947
+
948
+ if (Prototype.Browser.IE && this.heightN == 0)
949
+ this._getWindowBorderSize();
950
+
951
+ if (this.storedLocation != null) {
952
+ this._restoreLocation();
953
+ if(this.iefix)
954
+ this.iefix.hide();
955
+ }
956
+ else {
957
+ this._storeLocation();
958
+ Windows.unsetOverflow(this);
959
+
960
+ var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
961
+ var pageSize = WindowUtilities.getPageSize(this.options.parent);
962
+ var left = windowScroll.left;
963
+ var top = windowScroll.top;
964
+
965
+ if (this.options.parent != document.body) {
966
+ windowScroll = {top:0, left:0, bottom:0, right:0};
967
+ var dim = this.options.parent.getDimensions();
968
+ pageSize.windowWidth = dim.width;
969
+ pageSize.windowHeight = dim.height;
970
+ top = 0;
971
+ left = 0;
972
+ }
973
+
974
+ if (this.constraint) {
975
+ pageSize.windowWidth -= Math.max(0, this.constraintPad.left) + Math.max(0, this.constraintPad.right);
976
+ pageSize.windowHeight -= Math.max(0, this.constraintPad.top) + Math.max(0, this.constraintPad.bottom);
977
+ left += Math.max(0, this.constraintPad.left);
978
+ top += Math.max(0, this.constraintPad.top);
979
+ }
980
+
981
+ var width = pageSize.windowWidth - this.widthW - this.widthE;
982
+ var height= pageSize.windowHeight - this.heightN - this.heightS;
983
+
984
+ if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
985
+ new Effect.ResizeWindow(this, top, left, width, height, {duration: Window.resizeEffectDuration});
986
+ }
987
+ else {
988
+ this.setSize(width, height);
989
+ this.element.setStyle(this.useLeft ? {left: left} : {right: left});
990
+ this.element.setStyle(this.useTop ? {top: top} : {bottom: top});
991
+ }
992
+
993
+ this.toFront();
994
+ if (this.iefix)
995
+ this._fixIEOverlapping();
996
+ }
997
+ this._notify("onMaximize");
998
+
999
+ // Store new location/size if need be
1000
+ this._saveCookie()
1001
+ },
1002
+
1003
+ isMinimized: function() {
1004
+ return this.minimized;
1005
+ },
1006
+
1007
+ isMaximized: function() {
1008
+ return (this.storedLocation != null);
1009
+ },
1010
+
1011
+ setOpacity: function(opacity) {
1012
+ if (Element.setOpacity)
1013
+ Element.setOpacity(this.element, opacity);
1014
+ },
1015
+
1016
+ setZIndex: function(zindex) {
1017
+ this.element.setStyle({zIndex: zindex});
1018
+ Windows.updateZindex(zindex, this);
1019
+ },
1020
+
1021
+ setTitle: function(newTitle) {
1022
+ if (!newTitle || newTitle == "")
1023
+ newTitle = "&nbsp;";
1024
+
1025
+ Element.update(this.element.id + '_top', newTitle);
1026
+ },
1027
+
1028
+ getTitle: function() {
1029
+ return $(this.element.id + '_top').innerHTML;
1030
+ },
1031
+
1032
+ setStatusBar: function(element) {
1033
+ var statusBar = $(this.getId() + "_bottom");
1034
+
1035
+ if (typeof(element) == "object") {
1036
+ if (this.bottombar.firstChild)
1037
+ this.bottombar.replaceChild(element, this.bottombar.firstChild);
1038
+ else
1039
+ this.bottombar.appendChild(element);
1040
+ }
1041
+ else
1042
+ this.bottombar.innerHTML = element;
1043
+ },
1044
+
1045
+ _checkIEOverlapping: function() {
1046
+ if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && (navigator.userAgent.indexOf('Opera')<0) && (this.element.getStyle('position')=='absolute')) {
1047
+ new Insertion.After(this.element.id, '<iframe id="' + this.element.id + '_iefix" '+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' + 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
1048
+ this.iefix = $(this.element.id+'_iefix');
1049
+ }
1050
+ if(this.iefix)
1051
+ setTimeout(this._fixIEOverlapping.bind(this), 50);
1052
+ },
1053
+
1054
+ _fixIEOverlapping: function() {
1055
+ Position.clone(this.element, this.iefix);
1056
+ this.iefix.style.zIndex = this.element.style.zIndex - 1;
1057
+ this.iefix.show();
1058
+ },
1059
+
1060
+ _getWindowBorderSize: function(event) {
1061
+ // Hack to get real window border size!!
1062
+ var div = this._createHiddenDiv(this.options.className + "_n")
1063
+ this.heightN = Element.getDimensions(div).height;
1064
+ div.parentNode.removeChild(div)
1065
+
1066
+ var div = this._createHiddenDiv(this.options.className + "_s")
1067
+ this.heightS = Element.getDimensions(div).height;
1068
+ div.parentNode.removeChild(div)
1069
+
1070
+ var div = this._createHiddenDiv(this.options.className + "_e")
1071
+ this.widthE = Element.getDimensions(div).width;
1072
+ div.parentNode.removeChild(div)
1073
+
1074
+ var div = this._createHiddenDiv(this.options.className + "_w")
1075
+ this.widthW = Element.getDimensions(div).width;
1076
+ div.parentNode.removeChild(div);
1077
+
1078
+ var div = document.createElement("div");
1079
+ div.className = "overlay_" + this.options.className ;
1080
+ document.body.appendChild(div);
1081
+ //alert("no timeout:\nopacity: " + div.getStyle("opacity") + "\nwidth: " + document.defaultView.getComputedStyle(div, null).width);
1082
+ var that = this;
1083
+
1084
+ // Workaround for Safari!!
1085
+ setTimeout(function() {that.overlayOpacity = ($(div).getStyle("opacity")); div.parentNode.removeChild(div);}, 10);
1086
+
1087
+ // Workaround for IE!!
1088
+ if (Prototype.Browser.IE) {
1089
+ this.heightS = $(this.getId() +"_row3").getDimensions().height;
1090
+ this.heightN = $(this.getId() +"_row1").getDimensions().height;
1091
+ }
1092
+
1093
+ // Safari size fix
1094
+ if (Prototype.Browser.WebKit && Prototype.Browser.WebKitVersion < 420)
1095
+ this.setSize(this.width, this.height);
1096
+ if (this.doMaximize)
1097
+ this.maximize();
1098
+ if (this.doMinimize)
1099
+ this.minimize();
1100
+ },
1101
+
1102
+ _createHiddenDiv: function(className) {
1103
+ var objBody = document.body;
1104
+ var win = document.createElement("div");
1105
+ win.setAttribute('id', this.element.id+ "_tmp");
1106
+ win.className = className;
1107
+ win.style.display = 'none';
1108
+ win.innerHTML = '';
1109
+ objBody.insertBefore(win, objBody.firstChild);
1110
+ return win;
1111
+ },
1112
+
1113
+ _storeLocation: function() {
1114
+ if (this.storedLocation == null) {
1115
+ this.storedLocation = {useTop: this.useTop, useLeft: this.useLeft,
1116
+ top: this.element.getStyle('top'), bottom: this.element.getStyle('bottom'),
1117
+ left: this.element.getStyle('left'), right: this.element.getStyle('right'),
1118
+ width: this.width, height: this.height };
1119
+ }
1120
+ },
1121
+
1122
+ _restoreLocation: function() {
1123
+ if (this.storedLocation != null) {
1124
+ this.useLeft = this.storedLocation.useLeft;
1125
+ this.useTop = this.storedLocation.useTop;
1126
+
1127
+ if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow)
1128
+ new Effect.ResizeWindow(this, this.storedLocation.top, this.storedLocation.left, this.storedLocation.width, this.storedLocation.height, {duration: Window.resizeEffectDuration});
1129
+ else {
1130
+ this.element.setStyle(this.useLeft ? {left: this.storedLocation.left} : {right: this.storedLocation.right});
1131
+ this.element.setStyle(this.useTop ? {top: this.storedLocation.top} : {bottom: this.storedLocation.bottom});
1132
+ this.setSize(this.storedLocation.width, this.storedLocation.height);
1133
+ }
1134
+
1135
+ Windows.resetOverflow();
1136
+ this._removeStoreLocation();
1137
+ }
1138
+ },
1139
+
1140
+ _removeStoreLocation: function() {
1141
+ this.storedLocation = null;
1142
+ },
1143
+
1144
+ _saveCookie: function() {
1145
+ if (this.cookie) {
1146
+ var value = "";
1147
+ if (this.useLeft)
1148
+ value += "l:" + (this.storedLocation ? this.storedLocation.left : this.element.getStyle('left'))
1149
+ else
1150
+ value += "r:" + (this.storedLocation ? this.storedLocation.right : this.element.getStyle('right'))
1151
+ if (this.useTop)
1152
+ value += ",t:" + (this.storedLocation ? this.storedLocation.top : this.element.getStyle('top'))
1153
+ else
1154
+ value += ",b:" + (this.storedLocation ? this.storedLocation.bottom :this.element.getStyle('bottom'))
1155
+
1156
+ value += "," + (this.storedLocation ? this.storedLocation.width : this.width);
1157
+ value += "," + (this.storedLocation ? this.storedLocation.height : this.height);
1158
+ value += "," + this.isMinimized();
1159
+ value += "," + this.isMaximized();
1160
+ WindowUtilities.setCookie(value, this.cookie)
1161
+ }
1162
+ },
1163
+
1164
+ _createWiredElement: function() {
1165
+ if (! this.wiredElement) {
1166
+ if (Prototype.Browser.IE)
1167
+ this._getWindowBorderSize();
1168
+ var div = document.createElement("div");
1169
+ div.className = "wired_frame " + this.options.className + "_wired_frame";
1170
+
1171
+ div.style.position = 'absolute';
1172
+ this.options.parent.insertBefore(div, this.options.parent.firstChild);
1173
+ this.wiredElement = $(div);
1174
+ }
1175
+ if (this.useLeft)
1176
+ this.wiredElement.setStyle({left: this.element.getStyle('left')});
1177
+ else
1178
+ this.wiredElement.setStyle({right: this.element.getStyle('right')});
1179
+
1180
+ if (this.useTop)
1181
+ this.wiredElement.setStyle({top: this.element.getStyle('top')});
1182
+ else
1183
+ this.wiredElement.setStyle({bottom: this.element.getStyle('bottom')});
1184
+
1185
+ var dim = this.element.getDimensions();
1186
+ this.wiredElement.setStyle({width: dim.width + "px", height: dim.height +"px"});
1187
+
1188
+ this.wiredElement.setStyle({zIndex: Windows.maxZIndex+30});
1189
+ return this.wiredElement;
1190
+ },
1191
+
1192
+ _hideWiredElement: function() {
1193
+ if (! this.wiredElement || ! this.currentDrag)
1194
+ return;
1195
+ if (this.currentDrag == this.element)
1196
+ this.currentDrag = null;
1197
+ else {
1198
+ if (this.useLeft)
1199
+ this.element.setStyle({left: this.currentDrag.getStyle('left')});
1200
+ else
1201
+ this.element.setStyle({right: this.currentDrag.getStyle('right')});
1202
+
1203
+ if (this.useTop)
1204
+ this.element.setStyle({top: this.currentDrag.getStyle('top')});
1205
+ else
1206
+ this.element.setStyle({bottom: this.currentDrag.getStyle('bottom')});
1207
+
1208
+ this.currentDrag.hide();
1209
+ this.currentDrag = null;
1210
+ if (this.doResize)
1211
+ this.setSize(this.width, this.height);
1212
+ }
1213
+ },
1214
+
1215
+ _notify: function(eventName) {
1216
+ if (this.options[eventName])
1217
+ this.options[eventName](this);
1218
+ else
1219
+ Windows.notify(eventName, this);
1220
+ }
1221
+ };
1222
+
1223
+ // Windows containers, register all page windows
1224
+ var Windows = {
1225
+ windows: new Hash(),
1226
+ windowsByName: new Hash(),
1227
+ modalWindows: [],
1228
+ observers: [],
1229
+ focusedWindow: null,
1230
+ maxZIndex: 0,
1231
+ overlayShowEffectOptions: {duration: 0.5},
1232
+ overlayHideEffectOptions: {duration: 0.5},
1233
+
1234
+ addObserver: function(observer) {
1235
+ this.removeObserver(observer);
1236
+ this.observers.push(observer);
1237
+ },
1238
+
1239
+ removeObserver: function(observer) {
1240
+ this.observers = this.observers.reject( function(o) { return o==observer });
1241
+ },
1242
+
1243
+ // onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBlur onBeforeShow onShow onHide onMinimize onMaximize onClose
1244
+ notify: function(eventName, win) {
1245
+ this.observers.each( function(o) {if(o[eventName]) o[eventName](eventName, win);});
1246
+ },
1247
+
1248
+ // Gets window from its id
1249
+ getWindow: function(id) {
1250
+ return this.windows.get(id);
1251
+ },
1252
+
1253
+ // Gets the last focused window
1254
+ getFocusedWindow: function() {
1255
+ return this.focusedWindow;
1256
+ },
1257
+
1258
+ updateFocusedWindow: function() {
1259
+ this.focusedWindow = this.windows.values().length >=2 ? this.windows.values()[this.windows.values().length-2] : null;
1260
+ },
1261
+
1262
+ // Add a modal window in the stack
1263
+ addModalWindow: function(win) {
1264
+ // Disable screen if first modal window
1265
+ if (this.modalWindows.length == 0) {
1266
+ WindowUtilities.disableScreen(win.options.className, 'overlay_modal', win.overlayOpacity, win.getId(), win.options.parent);
1267
+ }
1268
+ else {
1269
+ // Move overlay over all windows
1270
+ if (Window.keepMultiModalWindow) {
1271
+ $('overlay_modal').style.zIndex = Windows.maxZIndex + 1;
1272
+ Windows.maxZIndex += 1;
1273
+ WindowUtilities._hideSelect(this.modalWindows.last().getId());
1274
+ }
1275
+ // Hide current modal window
1276
+ else
1277
+ this.modalWindows.last().element.hide();
1278
+ // Fucking IE select issue
1279
+ WindowUtilities._showSelect(win.getId());
1280
+ }
1281
+ this.modalWindows.push(win);
1282
+ },
1283
+
1284
+ removeModalWindow: function(win) {
1285
+ this.modalWindows.pop();
1286
+
1287
+ // No more modal windows
1288
+ if (this.modalWindows.length == 0)
1289
+ WindowUtilities.enableScreen();
1290
+ else {
1291
+ if (Window.keepMultiModalWindow) {
1292
+ this.modalWindows.last().toFront();
1293
+ WindowUtilities._showSelect(this.modalWindows.last().getId());
1294
+ }
1295
+ else
1296
+ this.modalWindows.last().element.show();
1297
+ }
1298
+ },
1299
+
1300
+ registerByName: function(name, win) {
1301
+ this.windowsByName.set(name, win);
1302
+ },
1303
+
1304
+ unregisterByName: function(name) {
1305
+ this.windowsByName.unset(name);
1306
+ },
1307
+
1308
+ removeWindowFromByName: function(win) {
1309
+ key = this.findNameFromWindow(win);
1310
+ if(key) {
1311
+ this.unregisterByName(key);
1312
+ }
1313
+ },
1314
+
1315
+ findNameFromWindow: function(win) {
1316
+ return this.windowsByName.collect(function(e){ return e.last() == win ? e.first() : null; }).compact().first();
1317
+ },
1318
+
1319
+ closeByName: function(name) {
1320
+ if(this.windowsByName.get(name)) {
1321
+ this.windowsByName.get(name).close();
1322
+ }
1323
+ },
1324
+
1325
+ existsByName: function(name) {
1326
+ return this.windowsByName.get(name) ? true : false;
1327
+ },
1328
+
1329
+ getWindowByName: function(name) {
1330
+ return this.windowsByName.get(name);
1331
+ },
1332
+
1333
+ // Registers a new window (called by Windows constructor)
1334
+ register: function(win) {
1335
+ this.windows.set(win.getId(), win);
1336
+ },
1337
+
1338
+ // Unregisters a window (called by Windows destructor)
1339
+ unregister: function(win) {
1340
+ this.windows.unset(win.getId());
1341
+ this.removeWindowFromByName(win);
1342
+ },
1343
+
1344
+ // Closes all windows
1345
+ closeAll: function() {
1346
+ this.windows.values().each( function(w) {Windows.close(w.getId())} );
1347
+ },
1348
+
1349
+ closeAllModalWindows: function() {
1350
+ WindowUtilities.enableScreen();
1351
+ this.modalWindows.each( function(win) {if (win) win.close()});
1352
+ },
1353
+
1354
+ // Minimizes a window with its id
1355
+ minimize: function(id, event) {
1356
+ var win = this.getWindow(id)
1357
+ if (win && win.visible)
1358
+ win.minimize();
1359
+ Event.stop(event);
1360
+ },
1361
+
1362
+ // Maximizes a window with its id
1363
+ maximize: function(id, event) {
1364
+ var win = this.getWindow(id)
1365
+ if (win && win.visible)
1366
+ win.maximize();
1367
+ Event.stop(event);
1368
+ },
1369
+
1370
+ // Closes a window with its id
1371
+ close: function(id, event) {
1372
+ var win = this.getWindow(id);
1373
+ if (win)
1374
+ win.close();
1375
+ if (event)
1376
+ Event.stop(event);
1377
+ },
1378
+
1379
+ blur: function(id) {
1380
+ var win = this.getWindow(id);
1381
+ if (!win)
1382
+ return;
1383
+ if (win.options.blurClassName)
1384
+ win.changeClassName(win.options.blurClassName);
1385
+ if (this.focusedWindow == win)
1386
+ this.focusedWindow = null;
1387
+ win._notify("onBlur");
1388
+ },
1389
+
1390
+ focus: function(id) {
1391
+ var win = this.getWindow(id);
1392
+ if (!win)
1393
+ return;
1394
+ if (this.focusedWindow)
1395
+ this.blur(this.focusedWindow.getId())
1396
+
1397
+ if (win.options.focusClassName)
1398
+ win.changeClassName(win.options.focusClassName);
1399
+ this.focusedWindow = win;
1400
+ win._notify("onFocus");
1401
+ },
1402
+
1403
+ unsetOverflow: function(except) {
1404
+ this.windows.values().each(function(d) { d.oldOverflow = d.getContent().getStyle("overflow") || "auto" ; d.getContent().setStyle({overflow: "hidden"}) });
1405
+ if (except && except.oldOverflow)
1406
+ except.getContent().setStyle({overflow: except.oldOverflow});
1407
+ },
1408
+
1409
+ resetOverflow: function() {
1410
+ this.windows.values().each(function(d) { if (d.oldOverflow) d.getContent().setStyle({overflow: d.oldOverflow}) });
1411
+ },
1412
+
1413
+ updateZindex: function(zindex, win) {
1414
+ if (zindex > this.maxZIndex) {
1415
+ this.maxZIndex = zindex;
1416
+ if (this.focusedWindow)
1417
+ this.blur(this.focusedWindow.getId())
1418
+ }
1419
+ this.focusedWindow = win;
1420
+ if (this.focusedWindow)
1421
+ this.focus(this.focusedWindow.getId())
1422
+ }
1423
+ };
1424
+
1425
+ var Dialog = {
1426
+ dialogId: null,
1427
+ onCompleteFunc: null,
1428
+ callFunc: null,
1429
+ parameters: null,
1430
+
1431
+ confirm: function(content, parameters) {
1432
+ // Get Ajax return before
1433
+ if (content && typeof content != "string") {
1434
+ Dialog._runAjaxRequest(content, parameters, Dialog.confirm);
1435
+ return
1436
+ }
1437
+ content = content || "";
1438
+
1439
+ parameters = parameters || {};
1440
+ var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
1441
+ var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel";
1442
+
1443
+ // Backward compatibility
1444
+ parameters = Object.extend(parameters, parameters.windowParameters || {});
1445
+ parameters.windowParameters = parameters.windowParameters || {};
1446
+
1447
+ parameters.className = parameters.className || "alert";
1448
+
1449
+ var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'"
1450
+ var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " cancel_button'"
1451
+ var content = "\
1452
+ <div class='" + parameters.className + "_message'>" + content + "</div>\
1453
+ <div class='" + parameters.className + "_buttons'>\
1454
+ <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\
1455
+ <input type='button' value='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "/>\
1456
+ </div>\
1457
+ ";
1458
+ return this._openDialog(content, parameters)
1459
+ },
1460
+
1461
+ alert: function(content, parameters) {
1462
+ // Get Ajax return before
1463
+ if (content && typeof content != "string") {
1464
+ Dialog._runAjaxRequest(content, parameters, Dialog.alert);
1465
+ return
1466
+ }
1467
+ content = content || "";
1468
+
1469
+ parameters = parameters || {};
1470
+ var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
1471
+
1472
+ // Backward compatibility
1473
+ parameters = Object.extend(parameters, parameters.windowParameters || {});
1474
+ parameters.windowParameters = parameters.windowParameters || {};
1475
+
1476
+ parameters.className = parameters.className || "alert";
1477
+
1478
+ var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'"
1479
+ var content = "\
1480
+ <div class='" + parameters.className + "_message'>" + content + "</div>\
1481
+ <div class='" + parameters.className + "_buttons'>\
1482
+ <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\
1483
+ </div>";
1484
+ return this._openDialog(content, parameters)
1485
+ },
1486
+
1487
+ info: function(content, parameters) {
1488
+ // Get Ajax return before
1489
+ if (content && typeof content != "string") {
1490
+ Dialog._runAjaxRequest(content, parameters, Dialog.info);
1491
+ return
1492
+ }
1493
+ content = content || "";
1494
+
1495
+ // Backward compatibility
1496
+ parameters = parameters || {};
1497
+ parameters = Object.extend(parameters, parameters.windowParameters || {});
1498
+ parameters.windowParameters = parameters.windowParameters || {};
1499
+
1500
+ parameters.className = parameters.className || "alert";
1501
+
1502
+ var content = "<div id='modal_dialog_message' class='" + parameters.className + "_message'>" + content + "</div>";
1503
+ if (parameters.showProgress)
1504
+ content += "<div id='modal_dialog_progress' class='" + parameters.className + "_progress'> </div>";
1505
+
1506
+ parameters.ok = null;
1507
+ parameters.cancel = null;
1508
+
1509
+ return this._openDialog(content, parameters)
1510
+ },
1511
+
1512
+ setInfoMessage: function(message) {
1513
+ $('modal_dialog_message').update(message);
1514
+ },
1515
+
1516
+ closeInfo: function() {
1517
+ Windows.close(this.dialogId);
1518
+ },
1519
+
1520
+ _openDialog: function(content, parameters) {
1521
+ var className = parameters.className;
1522
+
1523
+ if (! parameters.height && ! parameters.width) {
1524
+ parameters.width = WindowUtilities.getPageSize(parameters.options.parent || document.body).pageWidth / 2;
1525
+ }
1526
+ if (parameters.id)
1527
+ this.dialogId = parameters.id;
1528
+ else {
1529
+ var t = new Date();
1530
+ this.dialogId = 'modal_dialog_' + t.getTime();
1531
+ parameters.id = this.dialogId;
1532
+ }
1533
+
1534
+ // compute height or width if need be
1535
+ if (! parameters.height || ! parameters.width) {
1536
+ var size = WindowUtilities._computeSize(content, this.dialogId, parameters.width, parameters.height, 5, className)
1537
+ if (parameters.height)
1538
+ parameters.width = size + 5
1539
+ else
1540
+ parameters.height = size + 5
1541
+ }
1542
+ parameters.effectOptions = parameters.effectOptions ;
1543
+ parameters.resizable = parameters.resizable || false;
1544
+ parameters.minimizable = parameters.minimizable || false;
1545
+ parameters.maximizable = parameters.maximizable || false;
1546
+ parameters.draggable = parameters.draggable || false;
1547
+ parameters.closable = parameters.closable || false;
1548
+
1549
+ var win = new Window(parameters);
1550
+ win.getContent().innerHTML = content;
1551
+
1552
+ win.showCenter(true, parameters.top, parameters.left);
1553
+ win.setDestroyOnClose();
1554
+
1555
+ win.cancelCallback = parameters.onCancel || parameters.cancel;
1556
+ win.okCallback = parameters.onOk || parameters.ok;
1557
+
1558
+ return win;
1559
+ },
1560
+
1561
+ _getAjaxContent: function(originalRequest) {
1562
+ Dialog.callFunc(originalRequest.responseText, Dialog.parameters)
1563
+ },
1564
+
1565
+ _runAjaxRequest: function(message, parameters, callFunc) {
1566
+ if (message.options == null)
1567
+ message.options = {}
1568
+ Dialog.onCompleteFunc = message.options.onComplete;
1569
+ Dialog.parameters = parameters;
1570
+ Dialog.callFunc = callFunc;
1571
+
1572
+ message.options.onComplete = Dialog._getAjaxContent;
1573
+ new Ajax.Request(message.url, message.options);
1574
+ },
1575
+
1576
+ okCallback: function() {
1577
+ var win = Windows.focusedWindow;
1578
+ if (!win.okCallback || win.okCallback(win)) {
1579
+ // Remove onclick on button
1580
+ $$("#" + win.getId()+" input").each(function(element) {element.onclick=null;})
1581
+ win.close();
1582
+ }
1583
+ },
1584
+
1585
+ cancelCallback: function() {
1586
+ var win = Windows.focusedWindow;
1587
+ // Remove onclick on button
1588
+ $$("#" + win.getId()+" input").each(function(element) {element.onclick=null})
1589
+ win.close();
1590
+ if (win.cancelCallback)
1591
+ win.cancelCallback(win);
1592
+ }
1593
+ }
1594
+ /*
1595
+ Based on Lightbox JS: Fullsize Image Overlays
1596
+ by Lokesh Dhakar - http://www.huddletogether.com
1597
+
1598
+ For more information on this script, visit:
1599
+ http://huddletogether.com/projects/lightbox/
1600
+
1601
+ Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
1602
+ (basically, do anything you want, just leave my name and link)
1603
+ */
1604
+
1605
+ if (Prototype.Browser.WebKit) {
1606
+ var array = navigator.userAgent.match(new RegExp(/AppleWebKit\/([\d\.\+]*)/));
1607
+ Prototype.Browser.WebKitVersion = parseFloat(array[1]);
1608
+ }
1609
+
1610
+ var WindowUtilities = {
1611
+ // From dragdrop.js
1612
+ getWindowScroll: function(parent) {
1613
+ var T, L, W, H;
1614
+ parent = parent || document.body;
1615
+ if (parent != document.body) {
1616
+ T = parent.scrollTop;
1617
+ L = parent.scrollLeft;
1618
+ W = parent.scrollWidth;
1619
+ H = parent.scrollHeight;
1620
+ }
1621
+ else {
1622
+ var w = window;
1623
+ with (w.document) {
1624
+ if (w.document.documentElement && documentElement.scrollTop) {
1625
+ T = documentElement.scrollTop;
1626
+ L = documentElement.scrollLeft;
1627
+ } else if (w.document.body) {
1628
+ T = body.scrollTop;
1629
+ L = body.scrollLeft;
1630
+ }
1631
+ if (w.innerWidth) {
1632
+ W = w.innerWidth;
1633
+ H = w.innerHeight;
1634
+ } else if (w.document.documentElement && documentElement.clientWidth) {
1635
+ W = documentElement.clientWidth;
1636
+ H = documentElement.clientHeight;
1637
+ } else {
1638
+ W = body.offsetWidth;
1639
+ H = body.offsetHeight
1640
+ }
1641
+ }
1642
+ }
1643
+ return { top: T, left: L, width: W, height: H };
1644
+ },
1645
+ //
1646
+ // getPageSize()
1647
+ // Returns array with page width, height and window width, height
1648
+ // Core code from - quirksmode.org
1649
+ // Edit for Firefox by pHaez
1650
+ //
1651
+ getPageSize: function(parent){
1652
+ parent = parent || document.body;
1653
+ var windowWidth, windowHeight;
1654
+ var pageHeight, pageWidth;
1655
+ if (parent != document.body) {
1656
+ windowWidth = parent.getWidth();
1657
+ windowHeight = parent.getHeight();
1658
+ pageWidth = parent.scrollWidth;
1659
+ pageHeight = parent.scrollHeight;
1660
+ }
1661
+ else {
1662
+ var xScroll, yScroll;
1663
+
1664
+ if (window.innerHeight && window.scrollMaxY) {
1665
+ xScroll = document.body.scrollWidth;
1666
+ yScroll = window.innerHeight + window.scrollMaxY;
1667
+ } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
1668
+ xScroll = document.body.scrollWidth;
1669
+ yScroll = document.body.scrollHeight;
1670
+ } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
1671
+ xScroll = document.body.offsetWidth;
1672
+ yScroll = document.body.offsetHeight;
1673
+ }
1674
+
1675
+
1676
+ if (self.innerHeight) { // all except Explorer
1677
+ windowWidth = self.innerWidth;
1678
+ windowHeight = self.innerHeight;
1679
+ } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
1680
+ windowWidth = document.documentElement.clientWidth;
1681
+ windowHeight = document.documentElement.clientHeight;
1682
+ } else if (document.body) { // other Explorers
1683
+ windowWidth = document.body.clientWidth;
1684
+ windowHeight = document.body.clientHeight;
1685
+ }
1686
+
1687
+ // for small pages with total height less then height of the viewport
1688
+ if(yScroll < windowHeight){
1689
+ pageHeight = windowHeight;
1690
+ } else {
1691
+ pageHeight = yScroll;
1692
+ }
1693
+
1694
+ // for small pages with total width less then width of the viewport
1695
+ if(xScroll < windowWidth){
1696
+ pageWidth = windowWidth;
1697
+ } else {
1698
+ pageWidth = xScroll;
1699
+ }
1700
+ }
1701
+ return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
1702
+ },
1703
+
1704
+ disableScreen: function(className, overlayId, overlayOpacity, contentId, parent) {
1705
+ WindowUtilities.initLightbox(overlayId, className, function() {this._disableScreen(className, overlayId, overlayOpacity, contentId)}.bind(this), parent || document.body);
1706
+ },
1707
+
1708
+ _disableScreen: function(className, overlayId, overlayOpacity, contentId) {
1709
+ // prep objects
1710
+ var objOverlay = $(overlayId);
1711
+
1712
+ var pageSize = WindowUtilities.getPageSize(objOverlay.parentNode);
1713
+
1714
+ // Hide select boxes as they will 'peek' through the image in IE, store old value
1715
+ if (contentId && Prototype.Browser.IE) {
1716
+ WindowUtilities._hideSelect();
1717
+ WindowUtilities._showSelect(contentId);
1718
+ }
1719
+
1720
+ // set height of Overlay to take up whole page and show
1721
+ objOverlay.style.height = (pageSize.pageHeight + 'px');
1722
+ objOverlay.style.display = 'none';
1723
+ if (overlayId == "overlay_modal" && Window.hasEffectLib && Windows.overlayShowEffectOptions) {
1724
+ objOverlay.overlayOpacity = overlayOpacity;
1725
+ new Effect.Appear(objOverlay, Object.extend({from: 0, to: overlayOpacity}, Windows.overlayShowEffectOptions));
1726
+ }
1727
+ else
1728
+ objOverlay.style.display = "block";
1729
+ },
1730
+
1731
+ enableScreen: function(id) {
1732
+ id = id || 'overlay_modal';
1733
+ var objOverlay = $(id);
1734
+ if (objOverlay) {
1735
+ // hide lightbox and overlay
1736
+ if (id == "overlay_modal" && Window.hasEffectLib && Windows.overlayHideEffectOptions)
1737
+ new Effect.Fade(objOverlay, Object.extend({from: objOverlay.overlayOpacity, to:0}, Windows.overlayHideEffectOptions));
1738
+ else {
1739
+ objOverlay.style.display = 'none';
1740
+ objOverlay.parentNode.removeChild(objOverlay);
1741
+ }
1742
+
1743
+ // make select boxes visible using old value
1744
+ if (id != "__invisible__")
1745
+ WindowUtilities._showSelect();
1746
+ }
1747
+ },
1748
+
1749
+ _hideSelect: function(id) {
1750
+ if (Prototype.Browser.IE) {
1751
+ id = id == null ? "" : "#" + id + " ";
1752
+ $$(id + 'select').each(function(element) {
1753
+ if (! WindowUtilities.isDefined(element.oldVisibility)) {
1754
+ element.oldVisibility = element.style.visibility ? element.style.visibility : "visible";
1755
+ element.style.visibility = "hidden";
1756
+ }
1757
+ });
1758
+ }
1759
+ },
1760
+
1761
+ _showSelect: function(id) {
1762
+ if (Prototype.Browser.IE) {
1763
+ id = id == null ? "" : "#" + id + " ";
1764
+ $$(id + 'select').each(function(element) {
1765
+ if (WindowUtilities.isDefined(element.oldVisibility)) {
1766
+ // Why?? Ask IE
1767
+ try {
1768
+ element.style.visibility = element.oldVisibility;
1769
+ } catch(e) {
1770
+ element.style.visibility = "visible";
1771
+ }
1772
+ element.oldVisibility = null;
1773
+ }
1774
+ else {
1775
+ if (element.style.visibility)
1776
+ element.style.visibility = "visible";
1777
+ }
1778
+ });
1779
+ }
1780
+ },
1781
+
1782
+ isDefined: function(object) {
1783
+ return typeof(object) != "undefined" && object != null;
1784
+ },
1785
+
1786
+ // initLightbox()
1787
+ // Function runs on window load, going through link tags looking for rel="lightbox".
1788
+ // These links receive onclick events that enable the lightbox display for their targets.
1789
+ // The function also inserts html markup at the top of the page which will be used as a
1790
+ // container for the overlay pattern and the inline image.
1791
+ initLightbox: function(id, className, doneHandler, parent) {
1792
+ // Already done, just update zIndex
1793
+ if ($(id)) {
1794
+ Element.setStyle(id, {zIndex: Windows.maxZIndex + 1});
1795
+ Windows.maxZIndex++;
1796
+ doneHandler();
1797
+ }
1798
+ // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
1799
+ else {
1800
+ var objOverlay = document.createElement("div");
1801
+ objOverlay.setAttribute('id', id);
1802
+ objOverlay.className = "overlay_" + className
1803
+ objOverlay.style.display = 'none';
1804
+ objOverlay.style.position = 'absolute';
1805
+ objOverlay.style.top = '0';
1806
+ objOverlay.style.left = '0';
1807
+ objOverlay.style.zIndex = Windows.maxZIndex + 1;
1808
+ Windows.maxZIndex++;
1809
+ objOverlay.style.width = '100%';
1810
+ parent.insertBefore(objOverlay, parent.firstChild);
1811
+ if (Prototype.Browser.WebKit && id == "overlay_modal") {
1812
+ setTimeout(function() {doneHandler()}, 10);
1813
+ }
1814
+ else
1815
+ doneHandler();
1816
+ }
1817
+ },
1818
+
1819
+ setCookie: function(value, parameters) {
1820
+ document.cookie= parameters[0] + "=" + escape(value) +
1821
+ ((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") +
1822
+ ((parameters[2]) ? "; path=" + parameters[2] : "") +
1823
+ ((parameters[3]) ? "; domain=" + parameters[3] : "") +
1824
+ ((parameters[4]) ? "; secure" : "");
1825
+ },
1826
+
1827
+ getCookie: function(name) {
1828
+ var dc = document.cookie;
1829
+ var prefix = name + "=";
1830
+ var begin = dc.indexOf("; " + prefix);
1831
+ if (begin == -1) {
1832
+ begin = dc.indexOf(prefix);
1833
+ if (begin != 0) return null;
1834
+ } else {
1835
+ begin += 2;
1836
+ }
1837
+ var end = document.cookie.indexOf(";", begin);
1838
+ if (end == -1) {
1839
+ end = dc.length;
1840
+ }
1841
+ return unescape(dc.substring(begin + prefix.length, end));
1842
+ },
1843
+
1844
+ _computeSize: function(content, id, width, height, margin, className) {
1845
+ var objBody = document.body;
1846
+ var tmpObj = document.createElement("div");
1847
+ tmpObj.setAttribute('id', id);
1848
+ tmpObj.className = className + "_content";
1849
+
1850
+ if (height)
1851
+ tmpObj.style.height = height + "px"
1852
+ else
1853
+ tmpObj.style.width = width + "px"
1854
+
1855
+ tmpObj.style.position = 'absolute';
1856
+ tmpObj.style.top = '0';
1857
+ tmpObj.style.left = '0';
1858
+ tmpObj.style.display = 'none';
1859
+
1860
+ tmpObj.innerHTML = content;
1861
+ objBody.insertBefore(tmpObj, objBody.firstChild);
1862
+
1863
+ var size;
1864
+ if (height)
1865
+ size = $(tmpObj).getDimensions().width + margin;
1866
+ else
1867
+ size = $(tmpObj).getDimensions().height + margin;
1868
+ objBody.removeChild(tmpObj);
1869
+ return size;
1870
+ }
1871
+ }
1872
+