2 * $Id: mclayer.js 18 2006-06-29 14:11:23Z spocke $
\r
4 * Moxiecode floating layer script.
\r
7 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
\r
10 function MCLayer(id) {
\r
12 this.settings = new Array();
\r
13 this.blockerElement = null;
\r
14 this.isMSIE = navigator.appName == "Microsoft Internet Explorer";
\r
15 this.events = false;
\r
16 this.autoHideCallback = null;
\r
19 MCLayer.prototype = {
\r
20 moveRelativeTo : function(re, p, a) {
\r
21 var rep = this.getAbsPosition(re);
\r
22 var w = parseInt(re.offsetWidth);
\r
23 var h = parseInt(re.offsetHeight);
\r
31 x = rep.absLeft + w;
\r
45 moveBy : function(dx, dy) {
\r
46 var e = this.getElement();
\r
47 var x = parseInt(e.style.left);
\r
48 var y = parseInt(e.style.top);
\r
50 e.style.left = (x + dx) + "px";
\r
51 e.style.top = (y + dy) + "px";
\r
53 this.updateBlocker();
\r
56 moveTo : function(x, y) {
\r
57 var e = this.getElement();
\r
59 e.style.left = x + "px";
\r
60 e.style.top = y + "px";
\r
62 this.updateBlocker();
\r
66 MCLayer.visibleLayer = this;
\r
68 this.getElement().style.display = 'block';
\r
69 this.updateBlocker();
\r
73 this.getElement().style.display = 'none';
\r
74 this.updateBlocker();
\r
77 setAutoHide : function(s, cb) {
\r
78 this.autoHideCallback = cb;
\r
79 this.registerEventHandlers();
\r
82 getElement : function() {
\r
83 return document.getElementById(this.id);
\r
86 updateBlocker : function() {
\r
90 var e = this.getElement();
\r
91 var b = this.getBlocker();
\r
92 var x = this.parseInt(e.style.left);
\r
93 var y = this.parseInt(e.style.top);
\r
94 var w = this.parseInt(e.offsetWidth);
\r
95 var h = this.parseInt(e.offsetHeight);
\r
97 b.style.left = x + 'px';
\r
98 b.style.top = y + 'px';
\r
99 b.style.width = w + 'px';
\r
100 b.style.height = h + 'px';
\r
101 b.style.display = e.style.display;
\r
104 getBlocker : function() {
\r
105 if (!this.blockerElement) {
\r
106 var d = document, b = d.createElement("iframe");
\r
108 b.style.cssText = 'display: none; left: 0px; position: absolute; top: 0';
\r
109 b.src = 'javascript:false;';
\r
110 b.frameBorder = '0';
\r
111 b.scrolling = 'no';
\r
113 d.body.appendChild(b);
\r
114 this.blockerElement = b;
\r
117 return this.blockerElement;
\r
120 getAbsPosition : function(n) {
\r
121 var p = {absLeft : 0, absTop : 0};
\r
124 p.absLeft += n.offsetLeft;
\r
125 p.absTop += n.offsetTop;
\r
126 n = n.offsetParent;
\r
132 registerEventHandlers : function() {
\r
133 if (!this.events) {
\r
136 this.addEvent(d, 'mousedown', MCLayer.prototype.onMouseDown);
\r
138 this.events = true;
\r
142 addEvent : function(o, n, h) {
\r
144 o.attachEvent("on" + n, h);
\r
146 o.addEventListener(n, h, false);
\r
149 onMouseDown : function(e) {
\r
150 e = typeof(e) == "undefined" ? window.event : e;
\r
151 var b = document.body;
\r
152 var l = MCLayer.visibleLayer;
\r
155 var mx = l.isMSIE ? e.clientX + b.scrollLeft : e.pageX;
\r
156 var my = l.isMSIE ? e.clientY + b.scrollTop : e.pageY;
\r
157 var el = l.getElement();
\r
158 var x = parseInt(el.style.left);
\r
159 var y = parseInt(el.style.top);
\r
160 var w = parseInt(el.offsetWidth);
\r
161 var h = parseInt(el.offsetHeight);
\r
163 if (!(mx > x && mx < x + w && my > y && my < y + h)) {
\r
164 MCLayer.visibleLayer = null;
\r
166 if (l.autoHideCallback && l.autoHideCallback(l, e, mx, my))
\r
174 addCSSClass : function(e, c) {
\r
175 this.removeCSSClass(e, c);
\r
176 var a = this.explode(' ', e.className);
\r
178 e.className = a.join(' ');
\r
181 removeCSSClass : function(e, c) {
\r
182 var a = this.explode(' ', e.className), i;
\r
184 for (i=0; i<a.length; i++) {
\r
189 e.className = a.join(' ');
\r
192 explode : function(d, s) {
\r
193 var ar = s.split(d);
\r
194 var oar = new Array();
\r
196 for (var i = 0; i<ar.length; i++) {
\r
198 oar[oar.length] = ar[i];
\r
204 parseInt : function(s) {
\r
205 if (s == null || s == '')
\r
208 return parseInt(s);
\r