window_rails 0.1.5 → 0.2.0

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