1// Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
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:
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
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.
24var Window = Class.create();
26Window.keepMultiModalWindow = false;
27Window.hasEffectLib = (typeof Effect != 'undefined');
28Window.resizeEffectDuration = 0.4;
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
37 initialize: function() {
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" ) {
47 id = arguments[0] ? arguments[0].id : null;
50 // Generate unique ID if not specified
52 id = "window_" + new Date().getTime();
55 alert("Window " + id + " is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");
57 this.options = Object.extend({
68 showEffect: (Window.hasEffectLib ? Effect.Appear : Element.show),
69 hideEffect: (Window.hasEffectLib ? Effect.Fade : Element.hide),
70 showEffectOptions: {},
71 hideEffectOptions: {},
73 parent: document.body,
76 onload: Prototype.emptyFunction,
83 destroyOnClose: false,
86 }, arguments[optionIndex] || {});
87 if (this.options.blurClassName)
88 this.options.focusClassName = this.options.className;
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);
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;
101 if (Window.hasEffectLib) {
102 if (this.options.showEffect == Effect.Appear)
103 this.options.showEffectOptions.to = this.options.opacity;
105 if (this.options.hideEffect == Effect.Fade)
106 this.options.hideEffectOptions.from = this.options.opacity;
108 if (this.options.hideEffect == Element.hide)
109 this.options.hideEffect = function(){ Element.hide(this.element); if (this.options.destroyOnClose) this.destroy(); }.bind(this)
111 if (this.options.parent != document.body)
112 this.options.parent = $(this.options.parent);
114 this.element = this._createWindow(id);
115 this.element.win = this;
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);
125 this.topbar = $(this.element.id + "_top");
126 this.bottombar = $(this.element.id + "_bottom");
127 this.content = $(this.element.id + "_content");
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);
137 if (this.options.draggable) {
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");
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");
150 if (this.options.resizable) {
151 this.sizer = $(this.element.id + "_sizer");
152 Event.observe(this.sizer, "mousedown", this.eventMouseDown);
157 if (typeof this.options.left != "undefined") {
158 this.element.setStyle({left: parseFloat(this.options.left) + 'px'});
162 this.element.setStyle({right: parseFloat(this.options.right) + 'px'});
163 this.useLeft = false;
166 if (typeof this.options.top != "undefined") {
167 this.element.setStyle({top: parseFloat(this.options.top) + 'px'});
171 this.element.setStyle({bottom: parseFloat(this.options.bottom) + 'px'});
175 this.storedLocation = null;
177 this.setOpacity(this.options.opacity);
178 if (this.options.zIndex)
179 this.setZIndex(this.options.zIndex)
181 if (this.options.destroyOnClose)
182 this.setDestroyOnClose(true);
184 this._getWindowBorderSize();
185 this.width = this.options.width;
186 this.height = this.options.height;
187 this.visible = false;
189 this.constraint = false;
190 this.constraintPad = {top: 0, left:0, bottom:0, right:0};
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);
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);
205 Event.stopObserving(window, "load", this.eventOnLoad);
206 Event.stopObserving(window, "resize", this.eventResize);
207 Event.stopObserving(window, "scroll", this.eventResize);
209 Event.stopObserving(this.content, "load", this.options.onload);
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)
218 originalContent = null;
221 this._oldParent.appendChild(originalContent);
222 this._oldParent = null;
226 Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);
228 if (this.options.url)
229 this.content.src = null
232 Element.remove(this.iefix);
234 Element.remove(this.element);
235 Windows.unregister(this);
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;
243 // Gets window content
244 getContent: function () {
248 // Sets the content with an element id
249 setContent: function(id, autoresize, autoposition) {
251 if (null == element) throw "Unable to find element '" + id + "' in DOM";
252 this._oldParent = element.parentNode;
258 d = Element.getDimensions(element);
260 p = Position.cumulativeOffset(element);
262 var content = this.getContent();
263 // Clear HTML (and even iframe)
264 this.setHTMLContent("");
265 content = this.getContent();
267 content.appendChild(element);
270 this.setSize(d.width, d.height);
272 this.setLocation(p[1] - this.heightN, p[0] - this.widthW);
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;
281 var content ="<div id=\"" + this.getId() + "_content\" class=\"" + this.options.className + "_content\"> </div>";
282 $(this.getId() +"_table_content").innerHTML = content;
284 this.content = $(this.element.id + "_content");
287 this.getContent().innerHTML = html;
290 setAjaxContent: function(url, options, showCentered, showModal) {
291 this.showFunction = showCentered ? "showCenter" : "show";
292 this.showModal = showModal || false;
294 options = options || {};
296 // Clear HTML (and even iframe)
297 this.setHTMLContent("");
299 this.onComplete = options.onComplete;
300 if (! this._onCompleteHandler)
301 this._onCompleteHandler = this._setAjaxContent.bind(this);
302 options.onComplete = this._onCompleteHandler;
304 new Ajax.Request(url, options);
305 options.onComplete = this.onComplete;
308 _setAjaxContent: function(originalRequest) {
309 Element.update(this.getContent(), originalRequest.responseText);
311 this.onComplete(originalRequest);
312 this.onComplete = null;
313 this[this.showFunction](this.showModal)
316 setURL: function(url) {
317 // Not an url content, change div to iframe
318 if (this.options.url)
319 this.content.src = null;
320 this.options.url = url;
321 var content= "<iframe frameborder='0' name='" + this.getId() + "_content' id='" + this.getId() + "_content' src='" + url + "' width='" + this.width + "' height='" + this.height + "'> </iframe>";
322 $(this.getId() +"_table_content").innerHTML = content;
324 this.content = $(this.element.id + "_content");
328 return this.options.url ? this.options.url : null;
331 refresh: function() {
332 if (this.options.url)
333 $(this.element.getAttribute('id') + '_content').src = this.options.url;
336 // Stores position/size in a cookie, by default named with window id
337 setCookie: function(name, expires, path, domain, secure) {
338 name = name || this.element.id;
339 this.cookie = [name, expires, path, domain, secure];
342 var value = WindowUtilities.getCookie(name)
345 var values = value.split(',');
346 var x = values[0].split(':');
347 var y = values[1].split(':');
349 var w = parseFloat(values[2]), h = parseFloat(values[3]);
350 var mini = values[4];
351 var maxi = values[5];
355 this.doMinimize = true; // Minimize will be done at onload window event
356 else if (maxi == "true")
357 this.doMaximize = true; // Maximize will be done at onload window event
359 this.useLeft = x[0] == "l";
360 this.useTop = y[0] == "t";
362 this.element.setStyle(this.useLeft ? {left: x[1]} : {right: x[1]});
363 this.element.setStyle(this.useTop ? {top: y[1]} : {bottom: y[1]});
369 return this.element.id;
372 // Detroys itself when closing
373 setDestroyOnClose: function() {
374 this.options.destroyOnClose = true;
377 setConstraint: function(bool, padding) {
378 this.constraint = bool;
379 this.constraintPad = Object.extend(this.constraintPad, padding || {});
380 // Reset location to apply constraint
381 if (this.useTop && this.useLeft)
382 this.setLocation(parseFloat(this.element.style.top), parseFloat(this.element.style.left));
387 _initDrag: function(event) {
388 // No resize on minimized window
389 if (Event.element(event) == this.sizer && this.isMinimized())
392 // No move on maximzed window
393 if (Event.element(event) != this.sizer && this.isMaximized())
396 if (Prototype.Browser.IE && this.heightN == 0)
397 this._getWindowBorderSize();
400 this.pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
401 if (this.options.wiredDrag)
402 this.currentDrag = this._createWiredElement();
404 this.currentDrag = this.element;
407 if (Event.element(event) == this.sizer) {
408 this.doResize = true;
409 this.widthOrg = this.width;
410 this.heightOrg = this.height;
411 this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
412 this.rightOrg = parseFloat(this.element.getStyle('right'));
413 this._notify("onStartResize");
416 this.doResize = false;
418 // Check if click on close button,
419 var closeButton = $(this.getId() + '_close');
420 if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) {
421 this.currentDrag = null;
427 if (! this.options.draggable)
429 this._notify("onStartMove");
431 // Register global event to capture mouseUp and mouseMove
432 Event.observe(document, "mouseup", this.eventMouseUp, false);
433 Event.observe(document, "mousemove", this.eventMouseMove, false);
435 // Add an invisible div to keep catching mouse event over iframes
436 WindowUtilities.disableScreen('__invisible__', '__invisible__', this.overlayOpacity);
438 // Stop selection while dragging
439 document.body.ondrag = function () { return false; };
440 document.body.onselectstart = function () { return false; };
442 this.currentDrag.show();
446 _round: function(val, round) {
447 return round == 1 ? val : val = Math.floor(val / round) * round;
451 _updateDrag: function(event) {
452 var pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
453 var dx = pointer[0] - this.pointer[0];
454 var dy = pointer[1] - this.pointer[1];
456 // Resize case, update width/height
458 var w = this.widthOrg + dx;
459 var h = this.heightOrg + dy;
461 dx = this.width - this.widthOrg
462 dy = this.height - this.heightOrg
464 // Check if it's a right position, update it to keep upper-left corner at the same position
466 w = this._updateWidthConstraint(w)
468 this.currentDrag.setStyle({right: (this.rightOrg -dx) + 'px'});
469 // Check if it's a bottom position, update it to keep upper-left corner at the same position
471 h = this._updateHeightConstraint(h)
473 this.currentDrag.setStyle({bottom: (this.bottomOrg -dy) + 'px'});
476 this._notify("onResize");
478 // Move case, update top/left
480 this.pointer = pointer;
483 var left = parseFloat(this.currentDrag.getStyle('left')) + dx;
484 var newLeft = this._updateLeftConstraint(left);
485 // Keep mouse pointer correct
486 this.pointer[0] += newLeft-left;
487 this.currentDrag.setStyle({left: newLeft + 'px'});
490 this.currentDrag.setStyle({right: parseFloat(this.currentDrag.getStyle('right')) - dx + 'px'});
493 var top = parseFloat(this.currentDrag.getStyle('top')) + dy;
494 var newTop = this._updateTopConstraint(top);
495 // Keep mouse pointer correct
496 this.pointer[1] += newTop - top;
497 this.currentDrag.setStyle({top: newTop + 'px'});
500 this.currentDrag.setStyle({bottom: parseFloat(this.currentDrag.getStyle('bottom')) - dy + 'px'});
502 this._notify("onMove");
505 this._fixIEOverlapping();
507 this._removeStoreLocation();
512 _endDrag: function(event) {
513 // Remove temporary div over iframes
514 WindowUtilities.enableScreen('__invisible__');
517 this._notify("onEndResize");
519 this._notify("onEndMove");
521 // Release event observing
522 Event.stopObserving(document, "mouseup", this.eventMouseUp,false);
523 Event.stopObserving(document, "mousemove", this.eventMouseMove, false);
527 this._hideWiredElement();
529 // Store new location/size if need be
533 document.body.ondrag = null;
534 document.body.onselectstart = null;
537 _updateLeftConstraint: function(left) {
538 if (this.constraint && this.useLeft && this.useTop) {
539 var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
541 if (left < this.constraintPad.left)
542 left = this.constraintPad.left;
543 if (left + this.width + this.widthE + this.widthW > width - this.constraintPad.right)
544 left = width - this.constraintPad.right - this.width - this.widthE - this.widthW;
549 _updateTopConstraint: function(top) {
550 if (this.constraint && this.useLeft && this.useTop) {
551 var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
553 var h = this.height + this.heightN + this.heightS;
555 if (top < this.constraintPad.top)
556 top = this.constraintPad.top;
557 if (top + h > height - this.constraintPad.bottom)
558 top = height - this.constraintPad.bottom - h;
563 _updateWidthConstraint: function(w) {
564 if (this.constraint && this.useLeft && this.useTop) {
565 var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
566 var left = parseFloat(this.element.getStyle("left"));
568 if (left + w + this.widthE + this.widthW > width - this.constraintPad.right)
569 w = width - this.constraintPad.right - left - this.widthE - this.widthW;
574 _updateHeightConstraint: function(h) {
575 if (this.constraint && this.useLeft && this.useTop) {
576 var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
577 var top = parseFloat(this.element.getStyle("top"));
579 if (top + h + this.heightN + this.heightS > height - this.constraintPad.bottom)
580 h = height - this.constraintPad.bottom - top - this.heightN - this.heightS;
586 // Creates HTML window code
587 _createWindow: function(id) {
588 var className = this.options.className;
589 var win = document.createElement("div");
590 win.setAttribute('id', id);
591 win.className = "dialog";
594 if (this.options.url)
595 content= "<iframe frameborder=\"0\" name=\"" + id + "_content\" id=\"" + id + "_content\" src=\"" + this.options.url + "\"> </iframe>";
597 content ="<div id=\"" + id + "_content\" class=\"" +className + "_content\"> </div>";
599 var closeDiv = this.options.closable ? "<div class='"+ className +"_close' id='"+ id +"_close' onclick='Windows.close(\""+ id +"\", event)'> </div>" : "";
600 var minDiv = this.options.minimizable ? "<div class='"+ className + "_minimize' id='"+ id +"_minimize' onclick='Windows.minimize(\""+ id +"\", event)'> </div>" : "";
601 var maxDiv = this.options.maximizable ? "<div class='"+ className + "_maximize' id='"+ id +"_maximize' onclick='Windows.maximize(\""+ id +"\", event)'> </div>" : "";
602 var seAttributes = this.options.resizable ? "class='" + className + "_sizer' id='" + id + "_sizer'" : "class='" + className + "_se'";
603 var blank = "../themes/default/blank.gif";
605 win.innerHTML = closeDiv + minDiv + maxDiv + "\
606 <table id='"+ id +"_row1' class=\"top table_window\">\
608 <td class='"+ className +"_nw'></td>\
609 <td class='"+ className +"_n'><div id='"+ id +"_top' class='"+ className +"_title title_window'>"+ this.options.title +"</div></td>\
610 <td class='"+ className +"_ne'></td>\
613 <table id='"+ id +"_row2' class=\"mid table_window\">\
615 <td class='"+ className +"_w'></td>\
616 <td id='"+ id +"_table_content' class='"+ className +"_content' valign='top'>" + content + "</td>\
617 <td class='"+ className +"_e'></td>\
620 <table id='"+ id +"_row3' class=\"bot table_window\">\
622 <td class='"+ className +"_sw'></td>\
623 <td class='"+ className +"_s'><div id='"+ id +"_bottom' class='status_bar'><span style='float:left; width:1px; height:1px'></span></div></td>\
624 <td " + seAttributes + "></td>\
629 this.options.parent.insertBefore(win, this.options.parent.firstChild);
630 Event.observe($(id + "_content"), "load", this.options.onload);
635 changeClassName: function(newClassName) {
636 var className = this.options.className;
637 var id = this.getId();
638 $A(["_close", "_minimize", "_maximize", "_sizer", "_content"]).each(function(value) { this._toggleClassName($(id + value), className + value, newClassName + value) }.bind(this));
639 this._toggleClassName($(id + "_top"), className + "_title", newClassName + "_title");
640 $$("#" + id + " td").each(function(td) {td.className = td.className.sub(className,newClassName); });
641 this.options.className = newClassName;
644 _toggleClassName: function(element, oldClassName, newClassName) {
646 element.removeClassName(oldClassName);
647 element.addClassName(newClassName);
651 // Sets window location
652 setLocation: function(top, left) {
653 top = this._updateTopConstraint(top);
654 left = this._updateLeftConstraint(left);
656 var e = this.currentDrag || this.element;
657 e.setStyle({top: top + 'px'});
658 e.setStyle({left: left + 'px'});
664 getLocation: function() {
667 location = Object.extend(location, {top: this.element.getStyle("top")});
669 location = Object.extend(location, {bottom: this.element.getStyle("bottom")});
671 location = Object.extend(location, {left: this.element.getStyle("left")});
673 location = Object.extend(location, {right: this.element.getStyle("right")});
679 getSize: function() {
680 return {width: this.width, height: this.height};
684 setSize: function(width, height, useEffect) {
685 width = parseFloat(width);
686 height = parseFloat(height);
688 // Check min and max size
689 if (!this.minimized && width < this.options.minWidth)
690 width = this.options.minWidth;
692 if (!this.minimized && height < this.options.minHeight)
693 height = this.options.minHeight;
695 if (this.options. maxHeight && height > this.options. maxHeight)
696 height = this.options. maxHeight;
698 if (this.options. maxWidth && width > this.options. maxWidth)
699 width = this.options. maxWidth;
702 if (this.useTop && this.useLeft && Window.hasEffectLib && Effect.ResizeWindow && useEffect) {
703 new Effect.ResizeWindow(this, null, null, width, height, {duration: Window.resizeEffectDuration});
706 this.height = height;
707 var e = this.currentDrag ? this.currentDrag : this.element;
709 e.setStyle({width: width + this.widthW + this.widthE + "px"})
710 e.setStyle({height: height + this.heightN + this.heightS + "px"})
712 // Update content size
713 if (!this.currentDrag || this.currentDrag == this.element) {
714 var content = $(this.element.id + '_content');
715 content.setStyle({height: height + 'px'});
716 content.setStyle({width: width + 'px'});
721 updateHeight: function() {
722 this.setSize(this.width, this.content.scrollHeight, true);
725 updateWidth: function() {
726 this.setSize(this.content.scrollWidth, this.height, true);
729 // Brings window to front
730 toFront: function() {
731 if (this.element.style.zIndex < Windows.maxZIndex)
732 this.setZIndex(Windows.maxZIndex + 1);
734 this._fixIEOverlapping();
737 getBounds: function(insideOnly) {
738 if (! this.width || !this.height || !this.visible)
739 this.computeBounds();
744 w += this.widthW + this.widthE;
745 h += this.heightN + this.heightS;
747 var bounds = Object.extend(this.getLocation(), {width: w + "px", height: h + "px"});
751 computeBounds: function() {
752 if (! this.width || !this.height) {
753 var size = WindowUtilities._computeSize(this.content.innerHTML, this.content.id, this.width, this.height, 0, this.options.className)
755 this.width = size + 5
757 this.height = size + 5
760 this.setSize(this.width, this.height);
762 this._center(this.centerTop, this.centerLeft);
765 // Displays window modal state or not
766 show: function(modal) {
769 // Hack for Safari !!
770 if (typeof this.overlayOpacity == "undefined") {
772 setTimeout(function() {that.show(modal)}, 10);
775 Windows.addModalWindow(this);
778 this.setZIndex(Windows.maxZIndex + 1);
779 Windows.unsetOverflow(this);
782 if (!this.element.style.zIndex)
783 this.setZIndex(Windows.maxZIndex + 1);
785 // To restore overflow if need be
787 this.getContent().setStyle({overflow: this.oldStyle});
789 this.computeBounds();
791 this._notify("onBeforeShow");
792 if (this.options.showEffect != Element.show && this.options.showEffectOptions)
793 this.options.showEffect(this.element, this.options.showEffectOptions);
795 this.options.showEffect(this.element);
797 this._checkIEOverlapping();
798 WindowUtilities.focusedWindow = this
799 this._notify("onShow");
802 // Displays window modal state or not at the center of the page
803 showCenter: function(modal, top, left) {
804 this.centered = true;
805 this.centerTop = top;
806 this.centerLeft = left;
811 isVisible: function() {
815 _center: function(top, left) {
816 var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
817 var pageSize = WindowUtilities.getPageSize(this.options.parent);
818 if (typeof top == "undefined")
819 top = (pageSize.windowHeight - (this.height + this.heightN + this.heightS))/2;
820 top += windowScroll.top
822 if (typeof left == "undefined")
823 left = (pageSize.windowWidth - (this.width + this.widthW + this.widthE))/2;
824 left += windowScroll.left
825 this.setLocation(top, left);
829 _recenter: function(event) {
831 var pageSize = WindowUtilities.getPageSize(this.options.parent);
832 var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
834 // Check for this stupid IE that sends dumb events
835 if (this.pageSize && this.pageSize.windowWidth == pageSize.windowWidth && this.pageSize.windowHeight == pageSize.windowHeight &&
836 this.windowScroll.left == windowScroll.left && this.windowScroll.top == windowScroll.top)
838 this.pageSize = pageSize;
839 this.windowScroll = windowScroll;
840 // set height of Overlay to take up whole page and show
841 if ($('overlay_modal'))
842 $('overlay_modal').setStyle({height: (pageSize.pageHeight + 'px')});
844 if (this.options.recenterAuto)
845 this._center(this.centerTop, this.centerLeft);
851 this.visible = false;
853 Windows.removeModalWindow(this);
854 Windows.resetOverflow();
856 // To avoid bug on scrolling bar
857 this.oldStyle = this.getContent().getStyle('overflow') || "auto"
858 this.getContent().setStyle({overflow: "hidden"});
860 this.options.hideEffect(this.element, this.options.hideEffectOptions);
865 if (!this.doNotNotifyHide)
866 this._notify("onHide");
870 // Asks closeCallback if exists
872 if (this.options.closeCallback && ! this.options.closeCallback(this))
875 if (this.options.destroyOnClose) {
876 var destroyFunc = this.destroy.bind(this);
877 if (this.options.hideEffectOptions.afterFinish) {
878 var func = this.options.hideEffectOptions.afterFinish;
879 this.options.hideEffectOptions.afterFinish = function() {func();destroyFunc() }
882 this.options.hideEffectOptions.afterFinish = function() {destroyFunc() }
884 Windows.updateFocusedWindow();
886 this.doNotNotifyHide = true;
888 this.doNotNotifyHide = false;
889 this._notify("onClose");
893 minimize: function() {
897 var r2 = $(this.getId() + "_row2");
899 if (!this.minimized) {
900 this.minimized = true;
902 var dh = r2.getDimensions().height;
904 var h = this.element.getHeight() - dh;
906 if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
907 new Effect.ResizeWindow(this, null, null, null, this.height -dh, {duration: Window.resizeEffectDuration});
910 this.element.setStyle({height: h + "px"});
915 var bottom = parseFloat(this.element.getStyle('bottom'));
916 this.element.setStyle({bottom: (bottom + dh) + 'px'});
920 this.minimized = false;
922 var dh = this.r2Height;
923 this.r2Height = null;
924 if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
925 new Effect.ResizeWindow(this, null, null, null, this.height + dh, {duration: Window.resizeEffectDuration});
928 var h = this.element.getHeight() + dh;
930 this.element.setStyle({height: h + "px"})
934 var bottom = parseFloat(this.element.getStyle('bottom'));
935 this.element.setStyle({bottom: (bottom - dh) + 'px'});
939 this._notify("onMinimize");
941 // Store new location/size if need be
945 maximize: function() {
946 if (this.isMinimized() || this.resizing)
949 if (Prototype.Browser.IE && this.heightN == 0)
950 this._getWindowBorderSize();
952 if (this.storedLocation != null) {
953 this._restoreLocation();
958 this._storeLocation();
959 Windows.unsetOverflow(this);
961 var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
962 var pageSize = WindowUtilities.getPageSize(this.options.parent);
963 var left = windowScroll.left;
964 var top = windowScroll.top;
966 if (this.options.parent != document.body) {
967 windowScroll = {top:0, left:0, bottom:0, right:0};
968 var dim = this.options.parent.getDimensions();
969 pageSize.windowWidth = dim.width;
970 pageSize.windowHeight = dim.height;
975 if (this.constraint) {
976 pageSize.windowWidth -= Math.max(0, this.constraintPad.left) + Math.max(0, this.constraintPad.right);
977 pageSize.windowHeight -= Math.max(0, this.constraintPad.top) + Math.max(0, this.constraintPad.bottom);
978 left += Math.max(0, this.constraintPad.left);
979 top += Math.max(0, this.constraintPad.top);
982 var width = pageSize.windowWidth - this.widthW - this.widthE;
983 var height= pageSize.windowHeight - this.heightN - this.heightS;
985 if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
986 new Effect.ResizeWindow(this, top, left, width, height, {duration: Window.resizeEffectDuration});
989 this.setSize(width, height);
990 this.element.setStyle(this.useLeft ? {left: left} : {right: left});
991 this.element.setStyle(this.useTop ? {top: top} : {bottom: top});
996 this._fixIEOverlapping();
998 this._notify("onMaximize");
1000 // Store new location/size if need be
1004 isMinimized: function() {
1005 return this.minimized;
1008 isMaximized: function() {
1009 return (this.storedLocation != null);
1012 setOpacity: function(opacity) {
1013 if (Element.setOpacity)
1014 Element.setOpacity(this.element, opacity);
1017 setZIndex: function(zindex) {
1018 this.element.setStyle({zIndex: zindex});
1019 Windows.updateZindex(zindex, this);
1022 setTitle: function(newTitle) {
1023 if (!newTitle || newTitle == "")
1024 newTitle = " ";
1026 Element.update(this.element.id + '_top', newTitle);
1029 getTitle: function() {
1030 return $(this.element.id + '_top').innerHTML;
1033 setStatusBar: function(element) {
1034 var statusBar = $(this.getId() + "_bottom");
1036 if (typeof(element) == "object") {
1037 if (this.bottombar.firstChild)
1038 this.bottombar.replaceChild(element, this.bottombar.firstChild);
1040 this.bottombar.appendChild(element);
1043 this.bottombar.innerHTML = element;
1046 _checkIEOverlapping: function() {
1047 if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && (navigator.userAgent.indexOf('Opera')<0) && (this.element.getStyle('position')=='absolute')) {
1048 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>');
1049 this.iefix = $(this.element.id+'_iefix');
1052 setTimeout(this._fixIEOverlapping.bind(this), 50);
1055 _fixIEOverlapping: function() {
1056 Position.clone(this.element, this.iefix);
1057 this.iefix.style.zIndex = this.element.style.zIndex - 1;
1061 _getWindowBorderSize: function(event) {
1062 // Hack to get real window border size!!
1063 var div = this._createHiddenDiv(this.options.className + "_n")
1064 this.heightN = Element.getDimensions(div).height;
1065 div.parentNode.removeChild(div)
1067 var div = this._createHiddenDiv(this.options.className + "_s")
1068 this.heightS = Element.getDimensions(div).height;
1069 div.parentNode.removeChild(div)
1071 var div = this._createHiddenDiv(this.options.className + "_e")
1072 this.widthE = Element.getDimensions(div).width;
1073 div.parentNode.removeChild(div)
1075 var div = this._createHiddenDiv(this.options.className + "_w")
1076 this.widthW = Element.getDimensions(div).width;
1077 div.parentNode.removeChild(div);
1079 var div = document.createElement("div");
1080 div.className = "overlay_" + this.options.className ;
1081 document.body.appendChild(div);
1082 //alert("no timeout:\nopacity: " + div.getStyle("opacity") + "\nwidth: " + document.defaultView.getComputedStyle(div, null).width);
1085 // Workaround for Safari!!
1086 setTimeout(function() {that.overlayOpacity = ($(div).getStyle("opacity")); div.parentNode.removeChild(div);}, 10);
1088 // Workaround for IE!!
1089 if (Prototype.Browser.IE) {
1090 this.heightS = $(this.getId() +"_row3").getDimensions().height;
1091 this.heightN = $(this.getId() +"_row1").getDimensions().height;
1095 if (Prototype.Browser.WebKit && Prototype.Browser.WebKitVersion < 420)
1096 this.setSize(this.width, this.height);
1097 if (this.doMaximize)
1099 if (this.doMinimize)
1103 _createHiddenDiv: function(className) {
1104 var objBody = document.body;
1105 var win = document.createElement("div");
1106 win.setAttribute('id', this.element.id+ "_tmp");
1107 win.className = className;
1108 win.style.display = 'none';
1110 objBody.insertBefore(win, objBody.firstChild);
1114 _storeLocation: function() {
1115 if (this.storedLocation == null) {
1116 this.storedLocation = {useTop: this.useTop, useLeft: this.useLeft,
1117 top: this.element.getStyle('top'), bottom: this.element.getStyle('bottom'),
1118 left: this.element.getStyle('left'), right: this.element.getStyle('right'),
1119 width: this.width, height: this.height };
1123 _restoreLocation: function() {
1124 if (this.storedLocation != null) {
1125 this.useLeft = this.storedLocation.useLeft;
1126 this.useTop = this.storedLocation.useTop;
1128 if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow)
1129 new Effect.ResizeWindow(this, this.storedLocation.top, this.storedLocation.left, this.storedLocation.width, this.storedLocation.height, {duration: Window.resizeEffectDuration});
1131 this.element.setStyle(this.useLeft ? {left: this.storedLocation.left} : {right: this.storedLocation.right});
1132 this.element.setStyle(this.useTop ? {top: this.storedLocation.top} : {bottom: this.storedLocation.bottom});
1133 this.setSize(this.storedLocation.width, this.storedLocation.height);
1136 Windows.resetOverflow();
1137 this._removeStoreLocation();
1141 _removeStoreLocation: function() {
1142 this.storedLocation = null;
1145 _saveCookie: function() {
1149 value += "l:" + (this.storedLocation ? this.storedLocation.left : this.element.getStyle('left'))
1151 value += "r:" + (this.storedLocation ? this.storedLocation.right : this.element.getStyle('right'))
1153 value += ",t:" + (this.storedLocation ? this.storedLocation.top : this.element.getStyle('top'))
1155 value += ",b:" + (this.storedLocation ? this.storedLocation.bottom :this.element.getStyle('bottom'))
1157 value += "," + (this.storedLocation ? this.storedLocation.width : this.width);
1158 value += "," + (this.storedLocation ? this.storedLocation.height : this.height);
1159 value += "," + this.isMinimized();
1160 value += "," + this.isMaximized();
1161 WindowUtilities.setCookie(value, this.cookie)
1165 _createWiredElement: function() {
1166 if (! this.wiredElement) {
1167 if (Prototype.Browser.IE)
1168 this._getWindowBorderSize();
1169 var div = document.createElement("div");
1170 div.className = "wired_frame " + this.options.className + "_wired_frame";
1172 div.style.position = 'absolute';
1173 this.options.parent.insertBefore(div, this.options.parent.firstChild);
1174 this.wiredElement = $(div);
1177 this.wiredElement.setStyle({left: this.element.getStyle('left')});
1179 this.wiredElement.setStyle({right: this.element.getStyle('right')});
1182 this.wiredElement.setStyle({top: this.element.getStyle('top')});
1184 this.wiredElement.setStyle({bottom: this.element.getStyle('bottom')});
1186 var dim = this.element.getDimensions();
1187 this.wiredElement.setStyle({width: dim.width + "px", height: dim.height +"px"});
1189 this.wiredElement.setStyle({zIndex: Windows.maxZIndex+30});
1190 return this.wiredElement;
1193 _hideWiredElement: function() {
1194 if (! this.wiredElement || ! this.currentDrag)
1196 if (this.currentDrag == this.element)
1197 this.currentDrag = null;
1200 this.element.setStyle({left: this.currentDrag.getStyle('left')});
1202 this.element.setStyle({right: this.currentDrag.getStyle('right')});
1205 this.element.setStyle({top: this.currentDrag.getStyle('top')});
1207 this.element.setStyle({bottom: this.currentDrag.getStyle('bottom')});
1209 this.currentDrag.hide();
1210 this.currentDrag = null;
1212 this.setSize(this.width, this.height);
1216 _notify: function(eventName) {
1217 if (this.options[eventName])
1218 this.options[eventName](this);
1220 Windows.notify(eventName, this);
1224// Windows containers, register all page windows
1229 focusedWindow: null,
1231 overlayShowEffectOptions: {duration: 0.5},
1232 overlayHideEffectOptions: {duration: 0.5},
1234 addObserver: function(observer) {
1235 this.removeObserver(observer);
1236 this.observers.push(observer);
1239 removeObserver: function(observer) {
1240 this.observers = this.observers.reject( function(o) { return o==observer });
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);});
1248 // Gets window from its id
1249 getWindow: function(id) {
1250 return this.windows.detect(function(d) { return d.getId() ==id });
1253 // Gets the last focused window
1254 getFocusedWindow: function() {
1255 return this.focusedWindow;
1258 updateFocusedWindow: function() {
1259 this.focusedWindow = this.windows.length >=2 ? this.windows[this.windows.length-2] : null;
1262 // Registers a new window (called by Windows constructor)
1263 register: function(win) {
1264 this.windows.push(win);
1267 // Add a modal window in the stack
1268 addModalWindow: function(win) {
1269 // Disable screen if first modal window
1270 if (this.modalWindows.length == 0) {
1271 WindowUtilities.disableScreen(win.options.className, 'overlay_modal', win.overlayOpacity, win.getId(), win.options.parent);
1274 // Move overlay over all windows
1275 if (Window.keepMultiModalWindow) {
1276 $('overlay_modal').style.zIndex = Windows.maxZIndex + 1;
1277 Windows.maxZIndex += 1;
1278 WindowUtilities._hideSelect(this.modalWindows.last().getId());
1280 // Hide current modal window
1282 this.modalWindows.last().element.hide();
1283 // Fucking IE select issue
1284 WindowUtilities._showSelect(win.getId());
1286 this.modalWindows.push(win);
1289 removeModalWindow: function(win) {
1290 this.modalWindows.pop();
1292 // No more modal windows
1293 if (this.modalWindows.length == 0)
1294 WindowUtilities.enableScreen();
1296 if (Window.keepMultiModalWindow) {
1297 this.modalWindows.last().toFront();
1298 WindowUtilities._showSelect(this.modalWindows.last().getId());
1301 this.modalWindows.last().element.show();
1305 // Registers a new window (called by Windows constructor)
1306 register: function(win) {
1307 this.windows.push(win);
1310 // Unregisters a window (called by Windows destructor)
1311 unregister: function(win) {
1312 this.windows = this.windows.reject(function(d) { return d==win });
1315 // Closes all windows
1316 closeAll: function() {
1317 this.windows.each( function(w) {Windows.close(w.getId())} );
1320 closeAllModalWindows: function() {
1321 WindowUtilities.enableScreen();
1322 this.modalWindows.each( function(win) {if (win) win.close()});
1325 // Minimizes a window with its id
1326 minimize: function(id, event) {
1327 var win = this.getWindow(id)
1328 if (win && win.visible)
1333 // Maximizes a window with its id
1334 maximize: function(id, event) {
1335 var win = this.getWindow(id)
1336 if (win && win.visible)
1341 // Closes a window with its id
1342 close: function(id, event) {
1343 var win = this.getWindow(id);
1350 blur: function(id) {
1351 var win = this.getWindow(id);
1354 if (win.options.blurClassName)
1355 win.changeClassName(win.options.blurClassName);
1356 if (this.focusedWindow == win)
1357 this.focusedWindow = null;
1358 win._notify("onBlur");
1361 focus: function(id) {
1362 var win = this.getWindow(id);
1365 if (this.focusedWindow)
1366 this.blur(this.focusedWindow.getId())
1368 if (win.options.focusClassName)
1369 win.changeClassName(win.options.focusClassName);
1370 this.focusedWindow = win;
1371 win._notify("onFocus");
1374 unsetOverflow: function(except) {
1375 this.windows.each(function(d) { d.oldOverflow = d.getContent().getStyle("overflow") || "auto" ; d.getContent().setStyle({overflow: "hidden"}) });
1376 if (except && except.oldOverflow)
1377 except.getContent().setStyle({overflow: except.oldOverflow});
1380 resetOverflow: function() {
1381 this.windows.each(function(d) { if (d.oldOverflow) d.getContent().setStyle({overflow: d.oldOverflow}) });
1384 updateZindex: function(zindex, win) {
1385 if (zindex > this.maxZIndex) {
1386 this.maxZIndex = zindex;
1387 if (this.focusedWindow)
1388 this.blur(this.focusedWindow.getId())
1390 this.focusedWindow = win;
1391 if (this.focusedWindow)
1392 this.focus(this.focusedWindow.getId())
1398 onCompleteFunc: null,
1402 confirm: function(content, parameters) {
1403 // Get Ajax return before
1404 if (content && typeof content != "string") {
1405 Dialog._runAjaxRequest(content, parameters, Dialog.confirm);
1408 content = content || "";
1410 parameters = parameters || {};
1411 var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
1412 var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel";
1414 // Backward compatibility
1415 parameters = Object.extend(parameters, parameters.windowParameters || {});
1416 parameters.windowParameters = parameters.windowParameters || {};
1418 parameters.className = parameters.className || "alert";
1420 var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'"
1421 var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " cancel_button'"
1423 <div class='" + parameters.className + "_message'>" + content + "</div>\
1424 <div class='" + parameters.className + "_buttons'>\
1425 <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\
1426 <input type='button' value='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "/>\
1429 return this._openDialog(content, parameters)
1432 alert: function(content, parameters) {
1433 // Get Ajax return before
1434 if (content && typeof content != "string") {
1435 Dialog._runAjaxRequest(content, parameters, Dialog.alert);
1438 content = content || "";
1440 parameters = parameters || {};
1441 var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
1443 // Backward compatibility
1444 parameters = Object.extend(parameters, parameters.windowParameters || {});
1445 parameters.windowParameters = parameters.windowParameters || {};
1447 parameters.className = parameters.className || "alert";
1449 var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'"
1451 <div class='" + parameters.className + "_message'>" + content + "</div>\
1452 <div class='" + parameters.className + "_buttons'>\
1453 <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\
1455 return this._openDialog(content, parameters)
1458 info: function(content, parameters) {
1459 // Get Ajax return before
1460 if (content && typeof content != "string") {
1461 Dialog._runAjaxRequest(content, parameters, Dialog.info);
1464 content = content || "";
1466 // Backward compatibility
1467 parameters = parameters || {};
1468 parameters = Object.extend(parameters, parameters.windowParameters || {});
1469 parameters.windowParameters = parameters.windowParameters || {};
1471 parameters.className = parameters.className || "alert";
1473 var content = "<div id='modal_dialog_message' class='" + parameters.className + "_message'>" + content + "</div>";
1474 if (parameters.showProgress)
1475 content += "<div id='modal_dialog_progress' class='" + parameters.className + "_progress'> </div>";
1477 parameters.ok = null;
1478 parameters.cancel = null;
1480 return this._openDialog(content, parameters)
1483 setInfoMessage: function(message) {
1484 $('modal_dialog_message').update(message);
1487 closeInfo: function() {
1488 Windows.close(this.dialogId);
1491 _openDialog: function(content, parameters) {
1492 var className = parameters.className;
1494 if (! parameters.height && ! parameters.width) {
1495 parameters.width = WindowUtilities.getPageSize(parameters.options.parent || document.body).pageWidth / 2;
1498 this.dialogId = parameters.id;
1501 this.dialogId = 'modal_dialog_' + t.getTime();
1502 parameters.id = this.dialogId;
1505 // compute height or width if need be
1506 if (! parameters.height || ! parameters.width) {
1507 var size = WindowUtilities._computeSize(content, this.dialogId, parameters.width, parameters.height, 5, className)
1508 if (parameters.height)
1509 parameters.width = size + 5
1511 parameters.height = size + 5
1513 parameters.effectOptions = parameters.effectOptions ;
1514 parameters.resizable = parameters.resizable || false;
1515 parameters.minimizable = parameters.minimizable || false;
1516 parameters.maximizable = parameters.maximizable || false;
1517 parameters.draggable = parameters.draggable || false;
1518 parameters.closable = parameters.closable || false;
1520 var win = new Window(parameters);
1521 win.getContent().innerHTML = content;
1523 win.showCenter(true, parameters.top, parameters.left);
1524 win.setDestroyOnClose();
1526 win.cancelCallback = parameters.onCancel || parameters.cancel;
1527 win.okCallback = parameters.onOk || parameters.ok;
1532 _getAjaxContent: function(originalRequest) {
1533 Dialog.callFunc(originalRequest.responseText, Dialog.parameters)
1536 _runAjaxRequest: function(message, parameters, callFunc) {
1537 if (message.options == null)
1538 message.options = {}
1539 Dialog.onCompleteFunc = message.options.onComplete;
1540 Dialog.parameters = parameters;
1541 Dialog.callFunc = callFunc;
1543 message.options.onComplete = Dialog._getAjaxContent;
1544 new Ajax.Request(message.url, message.options);
1547 okCallback: function() {
1548 var win = Windows.focusedWindow;
1549 if (!win.okCallback || win.okCallback(win)) {
1550 // Remove onclick on button
1551 $$("#" + win.getId()+" input").each(function(element) {element.onclick=null;})
1556 cancelCallback: function() {
1557 var win = Windows.focusedWindow;
1558 // Remove onclick on button
1559 $$("#" + win.getId()+" input").each(function(element) {element.onclick=null})
1561 if (win.cancelCallback)
1562 win.cancelCallback(win);
1566 Based on Lightbox JS: Fullsize Image Overlays
1567 by Lokesh Dhakar - http://www.huddletogether.com
1569 For more information on this script, visit:
1570 http://huddletogether.com/projects/lightbox/
1572 Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
1573 (basically, do anything you want, just leave my name and link)
1576if (Prototype.Browser.WebKit) {
1577 var array = navigator.userAgent.match(new RegExp(/AppleWebKit\/([\d\.\+]*)/));
1578 Prototype.Browser.WebKitVersion = parseFloat(array[1]);
1581var WindowUtilities = {
1583 getWindowScroll: function(parent) {
1585 parent = parent || document.body;
1586 if (parent != document.body) {
1587 T = parent.scrollTop;
1588 L = parent.scrollLeft;
1589 W = parent.scrollWidth;
1590 H = parent.scrollHeight;
1595 if (w.document.documentElement && documentElement.scrollTop) {
1596 T = documentElement.scrollTop;
1597 L = documentElement.scrollLeft;
1598 } else if (w.document.body) {
1600 L = body.scrollLeft;
1605 } else if (w.document.documentElement && documentElement.clientWidth) {
1606 W = documentElement.clientWidth;
1607 H = documentElement.clientHeight;
1609 W = body.offsetWidth;
1610 H = body.offsetHeight
1614 return { top: T, left: L, width: W, height: H };
1618 // Returns array with page width, height and window width, height
1619 // Core code from - quirksmode.org
1620 // Edit for Firefox by pHaez
1622 getPageSize: function(parent){
1623 parent = parent || document.body;
1624 var windowWidth, windowHeight;
1625 var pageHeight, pageWidth;
1626 if (parent != document.body) {
1627 windowWidth = parent.getWidth();
1628 windowHeight = parent.getHeight();
1629 pageWidth = parent.scrollWidth;
1630 pageHeight = parent.scrollHeight;
1633 var xScroll, yScroll;
1635 if (window.innerHeight && window.scrollMaxY) {
1636 xScroll = document.body.scrollWidth;
1637 yScroll = window.innerHeight + window.scrollMaxY;
1638 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
1639 xScroll = document.body.scrollWidth;
1640 yScroll = document.body.scrollHeight;
1641 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
1642 xScroll = document.body.offsetWidth;
1643 yScroll = document.body.offsetHeight;
1647 if (self.innerHeight) { // all except Explorer
1648 windowWidth = self.innerWidth;
1649 windowHeight = self.innerHeight;
1650 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
1651 windowWidth = document.documentElement.clientWidth;
1652 windowHeight = document.documentElement.clientHeight;
1653 } else if (document.body) { // other Explorers
1654 windowWidth = document.body.clientWidth;
1655 windowHeight = document.body.clientHeight;
1658 // for small pages with total height less then height of the viewport
1659 if(yScroll < windowHeight){
1660 pageHeight = windowHeight;
1662 pageHeight = yScroll;
1665 // for small pages with total width less then width of the viewport
1666 if(xScroll < windowWidth){
1667 pageWidth = windowWidth;
1669 pageWidth = xScroll;
1672 return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
1675 disableScreen: function(className, overlayId, overlayOpacity, contentId, parent) {
1676 WindowUtilities.initLightbox(overlayId, className, function() {this._disableScreen(className, overlayId, overlayOpacity, contentId)}.bind(this), parent || document.body);
1679 _disableScreen: function(className, overlayId, overlayOpacity, contentId) {
1681 var objOverlay = $(overlayId);
1683 var pageSize = WindowUtilities.getPageSize(objOverlay.parentNode);
1685 // Hide select boxes as they will 'peek' through the image in IE, store old value
1686 if (contentId && Prototype.Browser.IE) {
1687 WindowUtilities._hideSelect();
1688 WindowUtilities._showSelect(contentId);
1691 // set height of Overlay to take up whole page and show
1692 objOverlay.style.height = (pageSize.pageHeight + 'px');
1693 objOverlay.style.display = 'none';
1694 if (overlayId == "overlay_modal" && Window.hasEffectLib && Windows.overlayShowEffectOptions) {
1695 objOverlay.overlayOpacity = overlayOpacity;
1696 new Effect.Appear(objOverlay, Object.extend({from: 0, to: overlayOpacity}, Windows.overlayShowEffectOptions));
1699 objOverlay.style.display = "block";
1702 enableScreen: function(id) {
1703 id = id || 'overlay_modal';
1704 var objOverlay = $(id);
1706 // hide lightbox and overlay
1707 if (id == "overlay_modal" && Window.hasEffectLib && Windows.overlayHideEffectOptions)
1708 new Effect.Fade(objOverlay, Object.extend({from: objOverlay.overlayOpacity, to:0}, Windows.overlayHideEffectOptions));
1710 objOverlay.style.display = 'none';
1711 objOverlay.parentNode.removeChild(objOverlay);
1714 // make select boxes visible using old value
1715 if (id != "__invisible__")
1716 WindowUtilities._showSelect();
1720 _hideSelect: function(id) {
1721 if (Prototype.Browser.IE) {
1722 id = id == null ? "" : "#" + id + " ";
1723 $$(id + 'select').each(function(element) {
1724 if (! WindowUtilities.isDefined(element.oldVisibility)) {
1725 element.oldVisibility = element.style.visibility ? element.style.visibility : "visible";
1726 element.style.visibility = "hidden";
1732 _showSelect: function(id) {
1733 if (Prototype.Browser.IE) {
1734 id = id == null ? "" : "#" + id + " ";
1735 $$(id + 'select').each(function(element) {
1736 if (WindowUtilities.isDefined(element.oldVisibility)) {
1739 element.style.visibility = element.oldVisibility;
1741 element.style.visibility = "visible";
1743 element.oldVisibility = null;
1746 if (element.style.visibility)
1747 element.style.visibility = "visible";
1753 isDefined: function(object) {
1754 return typeof(object) != "undefined" && object != null;
1758 // Function runs on window load, going through link tags looking for rel="lightbox".
1759 // These links receive onclick events that enable the lightbox display for their targets.
1760 // The function also inserts html markup at the top of the page which will be used as a
1761 // container for the overlay pattern and the inline image.
1762 initLightbox: function(id, className, doneHandler, parent) {
1763 // Already done, just update zIndex
1765 Element.setStyle(id, {zIndex: Windows.maxZIndex + 1});
1766 Windows.maxZIndex++;
1769 // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
1771 var objOverlay = document.createElement("div");
1772 objOverlay.setAttribute('id', id);
1773 objOverlay.className = "overlay_" + className
1774 objOverlay.style.display = 'none';
1775 objOverlay.style.position = 'absolute';
1776 objOverlay.style.top = '0';
1777 objOverlay.style.left = '0';
1778 objOverlay.style.zIndex = Windows.maxZIndex + 1;
1779 Windows.maxZIndex++;
1780 objOverlay.style.width = '100%';
1781 parent.insertBefore(objOverlay, parent.firstChild);
1782 if (Prototype.Browser.WebKit && id == "overlay_modal") {
1783 setTimeout(function() {doneHandler()}, 10);
1790 setCookie: function(value, parameters) {
1791 document.cookie= parameters[0] + "=" + escape(value) +
1792 ((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") +
1793 ((parameters[2]) ? "; path=" + parameters[2] : "") +
1794 ((parameters[3]) ? "; domain=" + parameters[3] : "") +
1795 ((parameters[4]) ? "; secure" : "");
1798 getCookie: function(name) {
1799 var dc = document.cookie;
1800 var prefix = name + "=";
1801 var begin = dc.indexOf("; " + prefix);
1803 begin = dc.indexOf(prefix);
1804 if (begin != 0) return null;
1808 var end = document.cookie.indexOf(";", begin);
1812 return unescape(dc.substring(begin + prefix.length, end));
1815 _computeSize: function(content, id, width, height, margin, className) {
1816 var objBody = document.body;
1817 var tmpObj = document.createElement("div");
1818 tmpObj.setAttribute('id', id);
1819 tmpObj.className = className + "_content";
1822 tmpObj.style.height = height + "px"
1824 tmpObj.style.width = width + "px"
1826 tmpObj.style.position = 'absolute';
1827 tmpObj.style.top = '0';
1828 tmpObj.style.left = '0';
1829 tmpObj.style.display = 'none';
1831 tmpObj.innerHTML = content;
1832 objBody.insertBefore(tmpObj, objBody.firstChild);
1836 size = $(tmpObj).getDimensions().width + margin;
1838 size = $(tmpObj).getDimensions().height + margin;
1839 objBody.removeChild(tmpObj);