// Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// VERSION 1.2
var Window = Class.create();
Window.keepMultiModalWindow = false;
Window.hasEffectLib = String.prototype.parseColor != null;
Window.resizeEffectDuration = 0.4;
Window.prototype = {
// Constructor
// Available parameters : className, title, minWidth, minHeight, maxWidth, maxHeight, width, height, top, left, bottom, right, resizable, zIndex, opacity, recenterAuto, wiredDrag
// hideEffect, showEffect, showEffectOptions, hideEffectOptions, effectOptions, url, draggable, closable, minimizable, maximizable, parent, onload
// add all callbacks (if you do not use an observer)
// onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBeforeShow onShow onHide onMinimize onMaximize onClose
initialize: function() {
var id;
var optionIndex = 0;
// For backward compatibility like win= new Window("id", {...}) instead of win = new Window({id: "id", ...})
if (arguments.length > 0) {
if (typeof arguments[0] == "string" ) {
id = arguments[0];
optionIndex = 1;
}
else
id = arguments[0] ? arguments[0].id : null;
}
// Generate unique ID if not specified
if (!id)
id = "window_" + new Date().getTime();
if ($(id))
alert("Window " + id + " is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");
this.options = Object.extend({
className: "dialog",
minWidth: 100,
minHeight: 20,
resizable: true,
closable: true,
minimizable: true,
maximizable: true,
draggable: true,
userData: null,
showEffect: (Window.hasEffectLib ? Effect.Appear : Element.show),
hideEffect: (Window.hasEffectLib ? Effect.Fade : Element.hide),
showEffectOptions: {},
hideEffectOptions: {},
effectOptions: null,
parent: document.body,
title: " ",
url: null,
onload: Prototype.emptyFunction,
width: 200,
height: 300,
opacity: 1,
recenterAuto: true,
wiredDrag: false,
closeCallback: null,
destroyOnClose: false,
gridX: 1,
gridY: 1
}, arguments[optionIndex] || {});
if (typeof this.options.top == "undefined" && typeof this.options.bottom == "undefined")
this.options.top = this._round(Math.random()*500, this.options.gridY);
if (typeof this.options.left == "undefined" && typeof this.options.right == "undefined")
this.options.left = this._round(Math.random()*500, this.options.gridX);
if (this.options.effectOptions) {
Object.extend(this.options.hideEffectOptions, this.options.effectOptions);
Object.extend(this.options.showEffectOptions, this.options.effectOptions);
if (this.options.showEffect == Element.Appear)
this.options.showEffectOptions.to = this.options.opacity;
}
if (Window.hasEffectLib) {
if (this.options.showEffect == Effect.Appear)
this.options.showEffectOptions.to = this.options.opacity;
if (this.options.hideEffect == Effect.Fade)
this.options.hideEffectOptions.from = this.options.opacity;
}
if (this.options.hideEffect == Element.hide)
this.options.hideEffect = function(){ Element.hide(this.element); if (this.options.destroyOnClose) this.destroy(); }.bind(this)
if (this.options.parent != document.body)
this.options.parent = $(this.options.parent);
this.element = this._createWindow(id);
// Bind event listener
this.eventMouseDown = this._initDrag.bindAsEventListener(this);
this.eventMouseUp = this._endDrag.bindAsEventListener(this);
this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
this.eventOnLoad = this._getWindowBorderSize.bindAsEventListener(this);
this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
this.eventResize = this._recenter.bindAsEventListener(this);
this.topbar = $(this.element.id + "_top");
this.bottombar = $(this.element.id + "_bottom");
this.content = $(this.element.id + "_content");
Event.observe(this.topbar, "mousedown", this.eventMouseDown);
Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
Event.observe(this.content, "mousedown", this.eventMouseDownContent);
Event.observe(window, "load", this.eventOnLoad);
Event.observe(window, "resize", this.eventResize);
Event.observe(window, "scroll", this.eventResize);
if (this.options.draggable) {
var that = this;
[this.topbar, this.topbar.up().previous(), this.topbar.up().next()].each(function(element) {
element.observe("mousedown", that.eventMouseDown);
element.addClassName("top_draggable");
});
[this.bottombar.up(), this.bottombar.up().previous(), this.bottombar.up().next()].each(function(element) {
element.observe("mousedown", that.eventMouseDown);
element.addClassName("bottom_draggable");
});
}
if (this.options.resizable) {
this.sizer = $(this.element.id + "_sizer");
Event.observe(this.sizer, "mousedown", this.eventMouseDown);
}
this.useLeft = null;
this.useTop = null;
if (typeof this.options.left != "undefined") {
this.element.setStyle({left: parseFloat(this.options.left) + 'px'});
this.useLeft = true;
}
else {
this.element.setStyle({right: parseFloat(this.options.right) + 'px'});
this.useLeft = false;
}
if (typeof this.options.top != "undefined") {
this.element.setStyle({top: parseFloat(this.options.top) + 'px'});
this.useTop = true;
}
else {
this.element.setStyle({bottom: parseFloat(this.options.bottom) + 'px'});
this.useTop = false;
}
this.storedLocation = null;
this.setOpacity(this.options.opacity);
if (this.options.zIndex)
this.setZIndex(this.options.zIndex)
if (this.options.destroyOnClose)
this.setDestroyOnClose(true);
this._getWindowBorderSize();
this.width = this.options.width;
this.height = this.options.height;
this.visible = false;
this.constraint = false;
this.constraintPad = {top: 0, left:0, bottom:0, right:0};
if (this.width && this.height)
this.setSize(this.options.width, this.options.height);
this.setTitle(this.options.title)
Windows.register(this);
},
// Destructor
destroy: function() {
this._notify("onDestroy");
Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
Event.stopObserving(this.content, "mousedown", this.eventMouseDownContent);
Event.stopObserving(window, "load", this.eventOnLoad);
Event.stopObserving(window, "resize", this.eventResize);
Event.stopObserving(window, "scroll", this.eventResize);
Event.stopObserving(this.content, "load", this.options.onload);
if (this._oldParent) {
var content = this.getContent();
var originalContent = null;
for(var i = 0; i < content.childNodes.length; i++) {
originalContent = content.childNodes[i];
if (originalContent.nodeType == 1)
break;
originalContent = null;
}
if (originalContent)
this._oldParent.appendChild(originalContent);
this._oldParent = null;
}
if (this.sizer)
Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);
if (this.options.url)
this.content.src = null
if(this.iefix)
Element.remove(this.iefix);
Element.remove(this.element);
Windows.unregister(this);
},
// Sets close callback, if it sets, it should return true to be able to close the window.
setCloseCallback: function(callback) {
this.options.closeCallback = callback;
},
// Gets window content
getContent: function () {
return this.content;
},
// Sets the content with an element id
setContent: function(id, autoresize, autoposition) {
var element = $(id);
if (null == element) throw "Unable to find element '" + id + "' in DOM";
this._oldParent = element.parentNode;
var d = null;
var p = null;
if (autoresize)
d = Element.getDimensions(element);
if (autoposition)
p = Position.cumulativeOffset(element);
var content = this.getContent();
// Clear HTML (and even iframe)
this.setHTMLContent("");
content = this.getContent();
content.appendChild(element);
element.show();
if (autoresize)
this.setSize(d.width, d.height);
if (autoposition)
this.setLocation(p[1] - this.heightN, p[0] - this.widthW);
},
setHTMLContent: function(html) {
// It was an url (iframe), recreate a div content instead of iframe content
if (this.options.url) {
this.content.src = null;
this.options.url = null;
var content ="
";
$(this.getId() +"_table_content").innerHTML = content;
this.content = $(this.element.id + "_content");
}
this.getContent().innerHTML = html;
},
urlencode: function (str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
},
setAjaxContent: function(url, options, showCentered, showModal) {
this.showFunction = showCentered ? "showCenter" : "show";
this.showModal = showModal || false;
options = options || {};
// Clear HTML (and even iframe)
this.setHTMLContent("");
this.onComplete = options.onComplete;
if (! this._onCompleteHandler)
this._onCompleteHandler = this._setAjaxContent.bind(this);
options.onComplete = this._onCompleteHandler;
new Ajax.Request(url, options);
options.onComplete = this.onComplete;
},
_setAjaxContent: function(originalRequest) {
Element.update(this.getContent(), originalRequest.responseText);
if (this.onComplete)
this.onComplete(originalRequest);
this.onComplete = null;
this[this.showFunction](this.showModal)
},
setURL: function(url) {
// Not an url content, change div to iframe
if (this.options.url)
this.content.src = null;
this.options.url = url;
var content= "";
$(this.getId() +"_table_content").innerHTML = content;
this.content = $(this.element.id + "_content");
},
getURL: function() {
return this.options.url ? this.options.url : null;
},
refresh: function() {
if (this.options.url)
$(this.element.getAttribute('id') + '_content').src = this.options.url;
},
// Stores position/size in a cookie, by default named with window id
setCookie: function(name, expires, path, domain, secure) {
name = name || this.element.id;
this.cookie = [name, expires, path, domain, secure];
// Get cookie
var value = WindowUtilities.getCookie(name)
// If exists
if (value) {
var values = value.split(',');
var x = values[0].split(':');
var y = values[1].split(':');
var w = parseFloat(values[2]), h = parseFloat(values[3]);
var mini = values[4];
var maxi = values[5];
this.setSize(w, h);
if (mini == "true")
this.doMinimize = true; // Minimize will be done at onload window event
else if (maxi == "true")
this.doMaximize = true; // Maximize will be done at onload window event
this.useLeft = x[0] == "l";
this.useTop = y[0] == "t";
this.element.setStyle(this.useLeft ? {left: x[1]} : {right: x[1]});
this.element.setStyle(this.useTop ? {top: y[1]} : {bottom: y[1]});
}
},
// Gets window ID
getId: function() {
return this.element.id;
},
// Detroys itself when closing
setDestroyOnClose: function() {
this.options.destroyOnClose = true;
},
setConstraint: function(bool, padding) {
this.constraint = bool;
this.constraintPad = Object.extend(this.constraintPad, padding || {});
// Reset location to apply constraint
if (this.useTop && this.useLeft)
this.setLocation(parseFloat(this.element.style.top), parseFloat(this.element.style.left));
},
// initDrag event
_initDrag: function(event) {
// No resize on minimized window
if (Event.element(event) == this.sizer && this.isMinimized())
return;
// No move on maximzed window
if (Event.element(event) != this.sizer && this.isMaximized())
return;
if (window.ie && this.heightN == 0)
this._getWindowBorderSize();
// Get pointer X,Y
this.pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
if (this.options.wiredDrag)
this.currentDrag = this._createWiredElement();
else
this.currentDrag = this.element;
// Resize
if (Event.element(event) == this.sizer) {
this.doResize = true;
this.widthOrg = this.width;
this.heightOrg = this.height;
this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
this.rightOrg = parseFloat(this.element.getStyle('right'));
this._notify("onStartResize");
}
else {
this.doResize = false;
// Check if click on close button,
var closeButton = $(this.getId() + '_close');
if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) {
this.currentDrag = null;
return;
}
this.toFront();
if (! this.options.draggable)
return;
this._notify("onStartMove");
}
// Register global event to capture mouseUp and mouseMove
Event.observe(document, "mouseup", this.eventMouseUp, false);
Event.observe(document, "mousemove", this.eventMouseMove, false);
// Add an invisible div to keep catching mouse event over iframes
WindowUtilities.disableScreen('__invisible__', '__invisible__', this.overlayOpacity);
// Stop selection while dragging
document.body.ondrag = function () { return false; };
document.body.onselectstart = function () { return false; };
this.currentDrag.show();
Event.stop(event);
},
_round: function(val, round) {
return round == 1 ? val : val = Math.floor(val / round) * round;
},
// updateDrag event
_updateDrag: function(event) {
var pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
var dx = pointer[0] - this.pointer[0];
var dy = pointer[1] - this.pointer[1];
// Resize case, update width/height
if (this.doResize) {
var w = this.widthOrg + dx;
var h = this.heightOrg + dy;
dx = this.width - this.widthOrg
dy = this.height - this.heightOrg
// Check if it's a right position, update it to keep upper-left corner at the same position
if (this.useLeft)
w = this._updateWidthConstraint(w)
else
this.currentDrag.setStyle({right: (this.rightOrg -dx) + 'px'});
// Check if it's a bottom position, update it to keep upper-left corner at the same position
if (this.useTop)
h = this._updateHeightConstraint(h)
else
this.currentDrag.setStyle({bottom: (this.bottomOrg -dy) + 'px'});
this.setSize(w , h);
this._notify("onResize");
}
// Move case, update top/left
else {
this.pointer = pointer;
if (this.useLeft) {
var left = parseFloat(this.currentDrag.getStyle('left')) + dx;
var newLeft = this._updateLeftConstraint(left);
// Keep mouse pointer correct
this.pointer[0] += newLeft-left;
this.currentDrag.setStyle({left: newLeft + 'px'});
}
else
this.currentDrag.setStyle({right: parseFloat(this.currentDrag.getStyle('right')) - dx + 'px'});
if (this.useTop) {
var top = parseFloat(this.currentDrag.getStyle('top')) + dy;
var newTop = this._updateTopConstraint(top);
// Keep mouse pointer correct
this.pointer[1] += newTop - top;
this.currentDrag.setStyle({top: newTop + 'px'});
}
else
this.currentDrag.setStyle({bottom: parseFloat(this.currentDrag.getStyle('bottom')) - dy + 'px'});
this._notify("onMove");
}
if (this.iefix)
this._fixIEOverlapping();
this._removeStoreLocation();
Event.stop(event);
},
// endDrag callback
_endDrag: function(event) {
// Remove temporary div over iframes
WindowUtilities.enableScreen('__invisible__');
if (this.doResize)
this._notify("onEndResize");
else
this._notify("onEndMove");
// Release event observing
Event.stopObserving(document, "mouseup", this.eventMouseUp,false);
Event.stopObserving(document, "mousemove", this.eventMouseMove, false);
Event.stop(event);
this._hideWiredElement();
// Store new location/size if need be
this._saveCookie()
// Restore selection
document.body.ondrag = null;
document.body.onselectstart = null;
},
_updateLeftConstraint: function(left) {
if (this.constraint && this.useLeft && this.useTop) {
var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
if (left < this.constraintPad.left)
left = this.constraintPad.left;
if (left + this.width + this.widthE + this.widthW > width - this.constraintPad.right)
left = width - this.constraintPad.right - this.width - this.widthE - this.widthW;
}
return left;
},
_updateTopConstraint: function(top) {
if (this.constraint && this.useLeft && this.useTop) {
var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
var h = this.height + this.heightN + this.heightS;
if (top < this.constraintPad.top)
top = this.constraintPad.top;
if (top + h > height - this.constraintPad.bottom)
top = height - this.constraintPad.bottom - h;
}
return top;
},
_updateWidthConstraint: function(w) {
if (this.constraint && this.useLeft && this.useTop) {
var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
var left = parseFloat(this.element.getStyle("left"));
if (left + w + this.widthE + this.widthW > width - this.constraintPad.right)
w = width - this.constraintPad.right - left - this.widthE - this.widthW;
}
return w;
},
_updateHeightConstraint: function(h) {
if (this.constraint && this.useLeft && this.useTop) {
var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
var top = parseFloat(this.element.getStyle("top"));
if (top + h + this.heightN + this.heightS > height - this.constraintPad.bottom)
h = height - this.constraintPad.bottom - top - this.heightN - this.heightS;
}
return h;
},
// Creates HTML window code
_createWindow: function(id) {
var className = this.options.className;
var win = document.createElement("div");
win.setAttribute('id', id);
win.className = "dialog";
var content;
if (this.options.url)
content= "";
else
content ="
";
parameters.ok = null;
parameters.cancel = null;
return this._openDialog(content, parameters)
},
setInfoMessage: function(message) {
$('modal_dialog_message').update(message);
},
closeInfo: function() {
Windows.close(this.dialogId);
},
_openDialog: function(content, parameters) {
var className = parameters.className;
if (! parameters.height && ! parameters.width) {
parameters.width = WindowUtilities.getPageSize().pageWidth / 2;
}
if (parameters.id)
this.dialogId = parameters.id;
else {
var t = new Date();
this.dialogId = 'modal_dialog_' + t.getTime();
parameters.id = this.dialogId;
}
// compute height or width if need be
if (! parameters.height || ! parameters.width) {
var size = WindowUtilities._computeSize(content, this.dialogId, parameters.width, parameters.height, 5, className)
if (parameters.height)
parameters.width = size + 5
else
parameters.height = size + 5
}
parameters.resizable = parameters.resizable || false;
parameters.effectOptions = parameters.effectOptions ;
parameters.minimizable = false;
parameters.maximizable = false;
parameters.draggable = false;
parameters.closable = false;
var win = new Window(parameters);
win.getContent().innerHTML = content;
win.showCenter(true, parameters.top, parameters.left);
win.setDestroyOnClose();
win.cancelCallback = parameters.onCancel || parameters.cancel;
win.okCallback = parameters.onOk || parameters.ok;
return win;
},
_getAjaxContent: function(originalRequest) {
Dialog.callFunc(originalRequest.responseText, Dialog.parameters)
},
_runAjaxRequest: function(message, parameters, callFunc) {
if (message.options == null)
message.options = {}
Dialog.onCompleteFunc = message.options.onComplete;
Dialog.parameters = parameters;
Dialog.callFunc = callFunc;
message.options.onComplete = Dialog._getAjaxContent;
new Ajax.Request(message.url, message.options);
},
okCallback: function() {
var win = Windows.focusedWindow;
if (!win.okCallback || win.okCallback(win)) {
// Remove onclick on button
$$("#" + win.getId()+" input").each(function(element) {element.onclick=null;})
win.close();
}
},
cancelCallback: function() {
var win = Windows.focusedWindow;
// Remove onclick on button
$$("#" + win.getId()+" input").each(function(element) {element.onclick=null})
win.close();
if (win.cancelCallback)
win.cancelCallback(win);
}
}
/*
Based on Lightbox JS: Fullsize Image Overlays
by Lokesh Dhakar - http://www.huddletogether.com
For more information on this script, visit:
http://huddletogether.com/projects/lightbox/
Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
(basically, do anything you want, just leave my name and link)
*/
// From mootools.net
// window.ie - will be set to true if the current browser is internet explorer (any).
// window.ie6 - will be set to true if the current browser is internet explorer 6.
// window.ie7 - will be set to true if the current browser is internet explorer 7.
// window.khtml - will be set to true if the current browser is Safari/Konqueror.
// window.webkit - will be set to true if the current browser is Safari-WebKit (Safari3)
// window.gecko - will be set to true if the current browser is Mozilla/Gecko.
if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
else if (document.childNodes && !document.all && !navigator.taintEnabled) window.khtml = true;
else if (document.getBoxObjectFor != null) window.gecko = true;
{
var array = navigator.userAgent.match(new RegExp(/AppleWebKit\/([\d\.\+]*)/));
window.webkit = array && array.length == 2 ? parseFloat(array[1]) >= 420 : false;
}
var WindowUtilities = {
getWindowScroll: function() {
var w = window;
var T, L, W, H;
L = window.pageXOffset || document.documentElement.scrollLeft;
T = window.pageYOffset || document.documentElement.scrollTop;
if (window.ie)
W = Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
else if (window.khtml)
W = document.body.scrollWidth;
else
W = document.documentElement.scrollWidth;
if (window.ie)
H = Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
else if (window.khtml)
H = document.body.scrollHeight;
else
H = document.documentElement.scrollHeight;
return { top: T, left: L, width: W, height: H };
},
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
getPageSize: function(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
var pageHeight, pageWidth;
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
},
disableScreen: function(className, overlayId, overlayOpacity, contentId) {
var that = this;
WindowUtilities.initLightbox(overlayId, className, function() {that._disableScreen(className, overlayId, overlayOpacity, contentId)});
},
_disableScreen: function(className, overlayId, overlayOpacity, contentId) {
var objBody = document.body;
// prep objects
var objOverlay = $(overlayId);
var pageSize = WindowUtilities.getPageSize();
// Hide select boxes as they will 'peek' through the image in IE, store old value
if (contentId && window.ie) {
WindowUtilities._hideSelect();
WindowUtilities._showSelect(contentId);
}
// set height of Overlay to take up whole page and show
objOverlay.style.height = (pageSize.pageHeight + 'px');
objOverlay.style.display = 'none';
if (overlayId == "overlay_modal" && Window.hasEffectLib && Windows.overlayShowEffectOptions) {
objOverlay.overlayOpacity = overlayOpacity;
new Effect.Appear(objOverlay, Object.extend({from: 0, to: overlayOpacity}, Windows.overlayShowEffectOptions));
}
else
objOverlay.style.display = "block";
},
enableScreen: function(id) {
id = id || 'overlay_modal';
var objOverlay = $(id);
if (objOverlay) {
// hide lightbox and overlay
if (id == "overlay_modal" && Window.hasEffectLib && Windows.overlayHideEffectOptions)
new Effect.Fade(objOverlay, Object.extend({from: objOverlay.overlayOpacity, to:0}, Windows.overlayHideEffectOptions));
else {
objOverlay.style.display = 'none';
objOverlay.parentNode.removeChild(objOverlay);
}
// make select boxes visible using old value
if (id != "__invisible__")
WindowUtilities._showSelect();
}
},
_hideSelect: function(id) {
if (window.ie) {
id = id == null ? "" : "#" + id + " ";
$$(id + 'select').each(function(element) {
if (! WindowUtilities.isDefined(element.oldVisibility)) {
element.oldVisibility = element.style.visibility ? element.style.visibility : "visible";
element.style.visibility = "hidden";
}
});
}
},
_showSelect: function(id) {
if (window.ie) {
id = id == null ? "" : "#" + id + " ";
$$(id + 'select').each(function(element) {
if (WindowUtilities.isDefined(element.oldVisibility)) {
// Why?? Ask IE
try {
element.style.visibility = element.oldVisibility;
} catch(e) {
element.style.visibility = "visible";
}
element.oldVisibility = null;
}
else {
if (element.style.visibility)
element.style.visibility = "visible";
}
});
}
},
isDefined: function(object) {
return typeof(object) != "undefined" && object != null;
},
// initLightbox()
// Function runs on window load, going through link tags looking for rel="lightbox".
// These links receive onclick events that enable the lightbox display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
initLightbox: function(id, className, doneHandler) {
// Already done, just update zIndex
if ($(id)) {
Element.setStyle(id, {zIndex: Windows.maxZIndex + 1});
Windows.maxZIndex++;
doneHandler();
}
// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
else {
var objBody = document.body;
var objOverlay = document.createElement("div");
objOverlay.setAttribute('id', id);
objOverlay.className = "overlay_" + className
objOverlay.style.display = 'none';
objOverlay.style.position = 'absolute';
objOverlay.style.top = '0';
objOverlay.style.left = '0';
objOverlay.style.zIndex = Windows.maxZIndex + 1;
Windows.maxZIndex++;
objOverlay.style.width = '100%';
objBody.insertBefore(objOverlay, objBody.firstChild);
if (window.khtml && id == "overlay_modal") {
setTimeout(function() {doneHandler()}, 10);
}
else
doneHandler();
}
},
setCookie: function(value, parameters) {
document.cookie= parameters[0] + "=" + escape(value) +
((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") +
((parameters[2]) ? "; path=" + parameters[2] : "") +
((parameters[3]) ? "; domain=" + parameters[3] : "") +
((parameters[4]) ? "; secure" : "");
},
getCookie: function(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
},
_computeSize: function(content, id, width, height, margin, className) {
var objBody = document.body;
var tmpObj = document.createElement("div");
tmpObj.setAttribute('id', id);
tmpObj.className = className + "_content";
if (height)
tmpObj.style.height = height + "px"
else
tmpObj.style.width = width + "px"
tmpObj.style.position = 'absolute';
tmpObj.style.top = '0';
tmpObj.style.left = '0';
tmpObj.style.display = 'none';
tmpObj.innerHTML = content;
objBody.insertBefore(tmpObj, objBody.firstChild);
var size;
if (height)
size = $(id).getDimensions().width + margin;
else
size = $(id).getDimensions().height + margin;
objBody.removeChild(tmpObj);
return size;
}
}