var infoBulle = new Class({ // 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; // 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; } // Return if id not specified if (!id)return; if ($(id)){ //alert("Window " + id + " is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor"); $(id).remove(); } this.map = gMap; this.options = this.setOptions(this.getDefaultOptions(), arguments[optionIndex]); 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 (this.hasEffectLib) { if (this.options.showEffect == Fx_.Appear) this.options.showEffectOptions.to = this.options.opacity; if (this.options.hideEffect == Fx_.Fade) this.options.hideEffectOptions.from = this.options.opacity; } if (this.options.hideEffect == Element.hide) this.options.hideEffect = function(){ this.element.hide(); if (this.options.destroyOnClose) this.destroy(); }.bind(this) if (this.options.parent != document.body) this.options.parent = $(this.options.parent); this.element = this._createInfo(id); this.eventOnLoad = this._getWindowBorderSize.bindAsEventListener(this); this.content = $(this.element.id + "_content"); this.wp = $(this.element.id + "_infowp"); this.atop = $(this.element.id + "_infoanorth"); this.aright = $(this.element.id + "_infoaeast"); this.abottom = $(this.element.id + "_infoasouth"); this.aleft = $(this.element.id + "_infoawest"); Event.observe(window, "load", this.eventOnLoad); this.setOpacity(this.options.opacity); if (this.options.zIndex) this.setZIndex(this.options.zIndex) this._getWindowBorderSize(); this.width = this.options.width; this.height = this.options.height; if (this.width && this.height) this.setSize(this.options.width, this.options.height); this.visible = false; Infos2.register(this); }, setOptions: function(defaults, options){ return Object.extend(defaults, options || {}); }, getDefaultOptions: function(){ return { className: "infoBulle", closable: true, showEffect: (this.hasEffectLib ? Fx_.Appear : Element.show), hideEffect: (this.hasEffectLib ? Fx_.Fade : Element.hide), showEffectOptions: {}, hideEffectOptions: {}, effectOptions: null, parent: this.map._map, urlRequest: null, onload: Class.empty, width: 300, height: 200, opacity: 1, zIndex: 9000 } }, _getWindowBorderSize: function(event) { // Hack to get real window border size!! var div = this._createHiddenDiv(this.options.className + "_n"); this.heightN = div.offsetHeight; div.parentNode.removeChild(div); var div = this._createHiddenDiv(this.options.className + "_s"); this.heightS = div.offsetHeight; div.parentNode.removeChild(div); var div = this._createHiddenDiv(this.options.className + "_b"); this.heightS += div.offsetHeight; var div = this._createHiddenDiv(this.options.className + "_b2"); this.heightS += div.offsetHeight; var div = this._createHiddenDiv(this.options.className + "_e"); this.widthE = div.offsetWidth; div.parentNode.removeChild(div); var div = this._createHiddenDiv(this.options.className + "_w"); this.widthW = div.offsetWidth; div.parentNode.removeChild(div); var div = document.createElement("div"); div.className = "overlay_" + this.options.className ; document.body.appendChild(div); //alert("no timeout:\nopacity: " + div.getStyle("opacity") + "\nwidth: " + document.defaultView.getComputedStyle(div, null).width); var that = this; // Workaround for Safari!! setTimeout(function() {that.overlayOpacity = ($(div).getStyle("opacity")); div.parentNode.removeChild(div);}, 10); // Safari size fix if (window.khtml && !window.webkit) this.setSize(this.width, this.height); }, _createHiddenDiv: function(className) { var objBody = document.body; var win = document.createElement("div"); win.setAttribute('id', this.element.id+ "_tmp"); win.className = className; win.style.display = 'none'; win.innerHTML = ''; objBody.insertBefore(win, objBody.firstChild); return win; }, // Creates HTML window code _createInfo: function(id) { var className = this.options.className; var el = new Element('div'); el.setProperty('id', id); el.toggleClass(className); var content; if (this.options.url) content= ""; else content ="
 
"; var closeDiv = this.options.closable ? "
 
" : ""; var blank = "../themes/default/blank.gif"; this.innerW = closeDiv; this.innerW += "
"; this.innerW += "
"; this.innerW += "
"; this.innerW += "
"; this.innerW += "
"; this.innerW += "
" + content + "
"; this.innerW += "
"; el.setHTML(this.innerW); el.hide(); this.options.parent.insertBefore(el, this.options.parent.firstChild); $(id + "_contentContainer").addEvent("load",this.options.onload); $(id +"_contentContainer").onmousedown = function(evt){Event.stop(evt);}.bindAsEventListener(this); $(id +"_close").onmousedown = function(evt,id){Infos2.close(id, evt); Event.stop(evt);}.bindAsEventListener(this,id); this.down = this.ptDown.bindAsEventListener(this); el.addEvent('mousedown',this.down); return el; }, ptDown: function(event){ event = new Event(event); ptTmp = new Point(); ptTmp.set(event.client.x - this.map.left, event.client.y - this.map.top); this.called(ptTmp,this.urlRequest); }, // Displays window modal state or not show: function() { this.element.makeDraggable(); if (this.options.showEffect != Element.show && this.options.showEffectOptions) this.options.showEffect(this.element, this.options.showEffectOptions); else this.element.show(); this.visible = true; }, setOpacity: function(opacity) { if (Element.setOpacity) Element.setOpacity(this.element, opacity); }, setZIndex: function(zindex) { this.element.setStyle('zIndex', zindex); Infos2.updateZindex(zindex, this); }, close: function() { // Asks closeCallback if exists if (this.visible) { this.hide(); } }, // Hides window hide: function() { this.visible = false; // To avoid bug on scrolling bar this.oldStyle = this.getContent().getStyle('overflow') || "auto"; this.getContent().setStyle('overflow',"hidden"); this.options.hideEffect(this.element, this.options.hideEffectOptions); }, // Gets window content getContent: function () { return this.content; }, // Gets window ID getId: function() { return this.element.id; }, // Sets window location setLocation: function(top, left) { var e = this.element; e.setStyle('top', top + 'px'); e.setStyle('left', left + 'px'); }, getLocation: function() { var location = {}; if (this.useTop) location = Object.extend(location, {top: this.element.getStyle("top")}); else location = Object.extend(location, {bottom: this.element.getStyle("bottom")}); if (this.useLeft) location = Object.extend(location, {left: this.element.getStyle("left")}); else location = Object.extend(location, {right: this.element.getStyle("right")}); return location; }, // Gets window size getSize: function() { return {width: this.width, height: this.height}; }, // Sets window size setSize: function(width, height, useEffect) { if((width*2) >= this.options.parent.offsetWidth)width = ((this.options.parent.offsetWidth/2) - 50); if((height*2) >= this.options.parent.offsetHeight)height = ((this.options.parent.offsetHeight/2) - 50); width = parseFloat(width); height = parseFloat(height); if (this.hasEffectLib && Fx_.ResizeWindow && useEffect) { new Fx_.ResizeWindow(this, null, null, width, height, {duration: 800}); } else { this.width = width; this.height = height; var e = this.element; e.setStyle('width', width + this.widthW + this.widthE + "px") e.setStyle('height', height + this.heightN + this.heightS + "px") // Update content size if (this.element) { var content = $(this.element.id + '_contentContainer'); content.setStyle('height', height + 'px'); //content.setStyle('width', width + 'px'); content.setStyle('width', (width-8) + 'px'); var close = $(this.element.id + '_close'); close.setStyle('left', (width+20) + 'px'); } } }, called: function(pt,url){ if($type(pt) != 'object')return; var aPosition; // la position de la fleche if(pt.y < parseInt(this.height+40)){ if(pt.x > parseInt(this.options.parent.offsetWidth - (this.width+50))){ // droit this.atop.hide(); this.aright.show(); this.abottom.hide(); this.aleft.hide(); aPosition = 2; }else{ // ambony this.atop.show(); this.aright.hide(); this.abottom.hide(); this.aleft.hide(); aPosition = 1; } } else if(pt.y > parseInt(this.options.parent.offsetHeight - this.height)){ if(pt.x > parseInt(this.options.parent.offsetWidth - (this.width+50))){ // ambany this.atop.hide(); this.aright.hide(); this.abottom.show(); this.aleft.hide(); aPosition = 3; }else{ // gauche this.atop.hide(); this.aright.hide(); this.abottom.hide(); this.aleft.show(); aPosition = 4; } } else{ if(pt.x > parseInt(this.options.parent.offsetWidth - (this.width+50))){ // ambany this.atop.hide(); this.aright.hide(); this.abottom.show(); this.aleft.hide(); aPosition = 3; }else{ // gauche this.atop.hide(); this.aright.hide(); this.abottom.hide(); this.aleft.show(); aPosition = 4; } } this.show(); switch(aPosition){ case 1: // fleche ambony var top = pt.y - 14; var left = pt.x - 43; break; case 2: // fleche droite var top = pt.y - 43; var left = pt.x - (this.width + 84); break; case 3: // fleche ambany var top = pt.y - (this.height + 112); var left = pt.x - (this.width + 53); break; case 4: // fleche gauche var top = pt.y - (this.height + 80); var left = pt.x - 13; break; } this.setLocation(top,left); this.urlRequest = url; var param = "ptInfoX="+pt.x+"&ptInfoY="+pt.y; this.setAjaxContent(url,{ method:'post', postBody:param }); }, 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; options.evalScripts = true; new Ajax(url,options).request(); options.onComplete = this.onComplete; }, _setAjaxContent: function(originalRequest) { originalRequest = originalRequest.replace(/\t|\n|\r|\b/g,''); var resp = ($type(originalRequest) == 'string')? originalRequest: originalRequest.responseText; /*var script, regexp = /]*>([\s\S]*?)<\/script>/gi; while ((script = regexp.exec(resp))) eval(script[1]);*/ this.getContent().update(resp); if (this.onComplete) this.onComplete(originalRequest); this.onComplete = null; this[this.showFunction](this.showModal) }, 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() +"_contentContainer").innerHTML = content; this.content = $(this.element.id + "_content"); } this.getContent().innerHTML = html; } }); // Windows containers, register all page windows var Infos2 = { windows: [], modalWindows: [], observers: [], focusedWindow: null, maxZIndex: 0, overlayShowEffectOptions: {duration: 0.5}, overlayHideEffectOptions: {duration: 0.5}, addObserver: function(observer) { this.removeObserver(observer); this.observers.push(observer); }, removeObserver: function(observer) { this.observers = this.observers.reject( function(o) { return o==observer }); }, // onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBeforeShow onShow onHide onMinimize onMaximize onClose notify: function(eventName, win) { this.observers.each( function(o) {if(o[eventName]) o[eventName](eventName, win);}); }, // Gets window from its id getWindow: function(id) { return this.windows.detect(function(d) { return d.getId() ==id }); }, // Gets the last focused window getFocusedWindow: function() { return this.focusedWindow; }, updateFocusedWindow: function() { this.focusedWindow = this.windows.length >=2 ? this.windows[this.windows.length-2] : null; }, // Registers a new window (called by Windows constructor) register: function(win) { this.windows.push(win); }, // Add a modal window in the stack addModalWindow: function(win) { // Disable screen if first modal window if (this.modalWindows.length == 0) InfoUtilities.disableScreen(win.options.className, 'overlay_modal', win.overlayOpacity, win.getId()); else { // Move overlay over all windows if (this.keepMultiModalWindow) { $('overlay_modal').style.zIndex = Infos.maxZIndex + 1; Infos.maxZIndex += 1; InfoUtilities._hideSelect(this.modalWindows.last().getId()); } // Hide current modal window else this.modalWindows.last().element.hide(); // Fucking IE select issue InfoUtilities._showSelect(win.getId()); } this.modalWindows.push(win); }, removeModalWindow: function(win) { this.modalWindows.pop(); // No more modal windows if (this.modalWindows.length == 0) InfoUtilities.enableScreen(); else { if (this.keepMultiModalWindow) { this.modalWindows.last().toFront(); InfoUtilities._showSelect(this.modalWindows.last().getId()); } else this.modalWindows.last().element.show(); } }, // Registers a new window (called by Windows constructor) register: function(win) { this.windows.push(win); }, // Unregisters a window (called by Windows destructor) unregister: function(win) { this.windows = this.windows.reject(function(d) { return d==win }); }, // Closes all windows closeAll: function() { this.windows.each( function(w) {Infos.close(w.getId())} ); }, closeAllModalWindows: function() { InfoUtilities.enableScreen(); this.modalWindows.each( function(win) {if (win) win.close()}); }, // Closes a window with its id close: function(id, event) { var win = this.getWindow(id); if (win) win.close(); if (event) Event.stop(event); }, unsetOverflow: function(except) { this.windows.each(function(d) { d.oldOverflow = d.getContent().getStyle("overflow") || "auto" ; d.getContent().setStyle('overflow', "hidden") }); if (except && except.oldOverflow) except.getContent().setStyle('overflow', except.oldOverflow); }, resetOverflow: function() { this.windows.each(function(d) { if (d.oldOverflow) d.getContent().setStyle('overflow', d.oldOverflow) }); }, updateZindex: function(zindex, win) { if(zindex > this.maxZIndex) this.maxZIndex = zindex; this.focusedWindow = win; } };