applied my changes - initial import
[boxroom-stian.git] / public / javascripts / tiny_mce / utils / mclayer.js
blobdeac8b74d22e93445eb1aeec1780ed78aa6ec608
1 /**\r
2  * $Id: mclayer.js 18 2006-06-29 14:11:23Z spocke $\r
3  *\r
4  * Moxiecode floating layer script.\r
5  *\r
6  * @author Moxiecode\r
7  * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.\r
8  */\r
9 \r
10 function MCLayer(id) {\r
11         this.id = 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
17 }\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
24                 var x, y;\r
26                 switch (p) {\r
27                         case "tl":\r
28                                 break;\r
30                         case "tr":\r
31                                 x = rep.absLeft + w;\r
32                                 y = rep.absTop;\r
33                                 break;\r
35                         case "bl":\r
36                                 break;\r
38                         case "br":\r
39                                 break;\r
40                 }\r
42                 this.moveTo(x, y);\r
43         },\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
54         },\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
63         },\r
65         show : function() {\r
66                 MCLayer.visibleLayer = this;\r
68                 this.getElement().style.display = 'block';\r
69                 this.updateBlocker();\r
70         },\r
72         hide : function() {\r
73                 this.getElement().style.display = 'none';\r
74                 this.updateBlocker();\r
75         },\r
77         setAutoHide : function(s, cb) {\r
78                 this.autoHideCallback = cb;\r
79                 this.registerEventHandlers();\r
80         },\r
82         getElement : function() {\r
83                 return document.getElementById(this.id);\r
84         },\r
86         updateBlocker : function() {\r
87                 if (!this.isMSIE)\r
88                         return;\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
102         },\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
115                 }\r
117                 return this.blockerElement;\r
118         },\r
120         getAbsPosition : function(n) {\r
121                 var p = {absLeft : 0, absTop : 0};\r
123                 while (n) {\r
124                         p.absLeft += n.offsetLeft;\r
125                         p.absTop += n.offsetTop;\r
126                         n = n.offsetParent;\r
127                 }\r
129                 return p;\r
130         },\r
132         registerEventHandlers : function() {\r
133                 if (!this.events) {\r
134                         var d = document;\r
136                         this.addEvent(d, 'mousedown', MCLayer.prototype.onMouseDown);\r
138                         this.events = true;\r
139                 }\r
140         },\r
142         addEvent : function(o, n, h) {\r
143                 if (o.attachEvent)\r
144                         o.attachEvent("on" + n, h);\r
145                 else\r
146                         o.addEventListener(n, h, false);\r
147         },\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
154                 if (l) {\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
167                                         return true;\r
169                                 l.hide();\r
170                         }\r
171                 }\r
172         },\r
174         addCSSClass : function(e, c) {\r
175                 this.removeCSSClass(e, c);\r
176                 var a = this.explode(' ', e.className);\r
177                 a[a.length] = c;\r
178                 e.className = a.join(' ');\r
179         },\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
185                         if (a[i] == c)\r
186                                 a[i] = '';\r
187                 }\r
189                 e.className = a.join(' ');\r
190         },\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
197                         if (ar[i] != "")\r
198                                 oar[oar.length] = ar[i];\r
199                 }\r
201                 return oar;\r
202         },\r
204         parseInt : function(s) {\r
205                 if (s == null || s == '')\r
206                         return 0;\r
208                 return parseInt(s);\r
209         }\r