6 * Moxiecode floating layer script.
9 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
12 function MCLayer(id) {
14 this.settings = new Array();
15 this.blockerElement = null;
16 this.isMSIE = navigator.appName == "Microsoft Internet Explorer";
18 this.autoHideCallback = null;
22 moveRelativeTo : function(re, p, a) {
23 var rep = this.getAbsPosition(re);
24 var w = parseInt(re.offsetWidth);
25 var h = parseInt(re.offsetHeight);
47 moveBy : function(dx, dy) {
48 var e = this.getElement();
49 var x = parseInt(e.style.left);
50 var y = parseInt(e.style.top);
52 e.style.left = (x + dx) + "px";
53 e.style.top = (y + dy) + "px";
58 moveTo : function(x, y) {
59 var e = this.getElement();
61 e.style.left = x + "px";
62 e.style.top = y + "px";
68 MCLayer.visibleLayer = this;
70 this.getElement().style.display = 'block';
75 this.getElement().style.display = 'none';
79 setAutoHide : function(s, cb) {
80 this.autoHideCallback = cb;
81 this.registerEventHandlers();
84 getElement : function() {
85 return document.getElementById(this.id);
88 updateBlocker : function() {
92 var e = this.getElement();
93 var b = this.getBlocker();
94 var x = this.parseInt(e.style.left);
95 var y = this.parseInt(e.style.top);
96 var w = this.parseInt(e.offsetWidth);
97 var h = this.parseInt(e.offsetHeight);
99 b.style.left = x + 'px';
100 b.style.top = y + 'px';
101 b.style.width = w + 'px';
102 b.style.height = h + 'px';
103 b.style.display = e.style.display;
106 getBlocker : function() {
107 if (!this.blockerElement) {
108 var d = document, b = d.createElement("iframe");
110 b.style.cssText = 'display: none; left: 0px; position: absolute; top: 0';
111 b.src = 'javascript:false;';
115 d.body.appendChild(b);
116 this.blockerElement = b;
119 return this.blockerElement;
122 getAbsPosition : function(n) {
123 var p = {absLeft : 0, absTop : 0};
126 p.absLeft += n.offsetLeft;
127 p.absTop += n.offsetTop;
134 registerEventHandlers : function() {
138 this.addEvent(d, 'mousedown', MCLayer.prototype.onMouseDown);
144 addEvent : function(o, n, h) {
146 o.attachEvent("on" + n, h);
148 o.addEventListener(n, h, false);
151 onMouseDown : function(e) {
152 e = typeof(e) == "undefined" ? window.event : e;
153 var b = document.body;
154 var l = MCLayer.visibleLayer;
157 var mx = l.isMSIE ? e.clientX + b.scrollLeft : e.pageX;
158 var my = l.isMSIE ? e.clientY + b.scrollTop : e.pageY;
159 var el = l.getElement();
160 var x = parseInt(el.style.left);
161 var y = parseInt(el.style.top);
162 var w = parseInt(el.offsetWidth);
163 var h = parseInt(el.offsetHeight);
165 if (!(mx > x && mx < x + w && my > y && my < y + h)) {
166 MCLayer.visibleLayer = null;
168 if (l.autoHideCallback && l.autoHideCallback(l, e, mx, my))
176 addCSSClass : function(e, c) {
177 this.removeCSSClass(e, c);
178 var a = this.explode(' ', e.className);
180 e.className = a.join(' ');
183 removeCSSClass : function(e, c) {
184 var a = this.explode(' ', e.className), i;
186 for (i=0; i<a.length; i++) {
191 e.className = a.join(' ');
194 explode : function(d, s) {
196 var oar = new Array();
198 for (var i = 0; i<ar.length; i++) {
200 oar[oar.length] = ar[i];
206 parseInt : function(s) {
207 if (s == null || s == '')