| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,330 @@ |
| 1 |
+/** |
|
| 2 |
+ * $Id$ |
|
| 3 |
+ * |
|
| 4 |
+ * @author Moxiecode |
|
| 5 |
+ * @copyright Copyright � 2004-2007, Moxiecode Systems AB, All rights reserved. |
|
| 6 |
+ */ |
|
| 7 |
+ |
|
| 8 |
+/** |
|
| 9 |
+ * Constructor for the TinyMCE Layer. This class enables you to construct |
|
| 10 |
+ * floating layers that is visible on top of select input fields, flashes and iframes. |
|
| 11 |
+ * |
|
| 12 |
+ * @param {string} id Unique ID name for the layer.
|
|
| 13 |
+ * @param {boolean} bm Block mode, defaults to true.
|
|
| 14 |
+ * @constructor |
|
| 15 |
+ * @member TinyMCE_Layer |
|
| 16 |
+ */ |
|
| 17 |
+function TinyMCE_Layer(id, bm) {
|
|
| 18 |
+ this.id = id; |
|
| 19 |
+ this.blockerElement = null; |
|
| 20 |
+ this.events = false; |
|
| 21 |
+ this.element = null; |
|
| 22 |
+ this.blockMode = typeof(bm) != 'undefined' ? bm : true; |
|
| 23 |
+ this.doc = document; |
|
| 24 |
+}; |
|
| 25 |
+ |
|
| 26 |
+/**#@+ |
|
| 27 |
+ * @member TinyMCE_Layer |
|
| 28 |
+ */ |
|
| 29 |
+TinyMCE_Layer.prototype = {
|
|
| 30 |
+ /**#@+ |
|
| 31 |
+ * @method |
|
| 32 |
+ */ |
|
| 33 |
+ |
|
| 34 |
+ /** |
|
| 35 |
+ * Moves the layer relative to the specified HTML element. |
|
| 36 |
+ * |
|
| 37 |
+ * @param {HTMLElement} re Element to move the layer relative to.
|
|
| 38 |
+ * @param {string} p Position of the layer tl = top left, tr = top right, bl = bottom left, br = bottom right.
|
|
| 39 |
+ */ |
|
| 40 |
+ moveRelativeTo : function(re, p) {
|
|
| 41 |
+ var rep = this.getAbsPosition(re), e = this.getElement(), x, y; |
|
| 42 |
+ var w = parseInt(re.offsetWidth), h = parseInt(re.offsetHeight); |
|
| 43 |
+ var ew = parseInt(e.offsetWidth), eh = parseInt(e.offsetHeight); |
|
| 44 |
+ |
|
| 45 |
+ switch (p) {
|
|
| 46 |
+ case "tl": |
|
| 47 |
+ x = rep.absLeft; |
|
| 48 |
+ y = rep.absTop; |
|
| 49 |
+ break; |
|
| 50 |
+ |
|
| 51 |
+ case "tr": |
|
| 52 |
+ x = rep.absLeft + w; |
|
| 53 |
+ y = rep.absTop; |
|
| 54 |
+ break; |
|
| 55 |
+ |
|
| 56 |
+ case "bl": |
|
| 57 |
+ x = rep.absLeft; |
|
| 58 |
+ y = rep.absTop + h; |
|
| 59 |
+ break; |
|
| 60 |
+ |
|
| 61 |
+ case "br": |
|
| 62 |
+ x = rep.absLeft + w; |
|
| 63 |
+ y = rep.absTop + h; |
|
| 64 |
+ break; |
|
| 65 |
+ |
|
| 66 |
+ case "cc": |
|
| 67 |
+ x = rep.absLeft + (w / 2) - (ew / 2); |
|
| 68 |
+ y = rep.absTop + (h / 2) - (eh / 2); |
|
| 69 |
+ break; |
|
| 70 |
+ } |
|
| 71 |
+ |
|
| 72 |
+ this.moveTo(x, y); |
|
| 73 |
+ }, |
|
| 74 |
+ |
|
| 75 |
+ /** |
|
| 76 |
+ * Moves the layer relative in pixels. |
|
| 77 |
+ * |
|
| 78 |
+ * @param {int} x Horizontal relative position in pixels.
|
|
| 79 |
+ * @param {int} y Vertical relative position in pixels.
|
|
| 80 |
+ */ |
|
| 81 |
+ moveBy : function(x, y) {
|
|
| 82 |
+ var e = this.getElement(); |
|
| 83 |
+ this.moveTo(parseInt(e.style.left) + x, parseInt(e.style.top) + y); |
|
| 84 |
+ }, |
|
| 85 |
+ |
|
| 86 |
+ /** |
|
| 87 |
+ * Moves the layer absolute in pixels. |
|
| 88 |
+ * |
|
| 89 |
+ * @param {int} x Horizontal absolute position in pixels.
|
|
| 90 |
+ * @param {int} y Vertical absolute position in pixels.
|
|
| 91 |
+ */ |
|
| 92 |
+ moveTo : function(x, y) {
|
|
| 93 |
+ var e = this.getElement(); |
|
| 94 |
+ |
|
| 95 |
+ e.style.left = x + "px"; |
|
| 96 |
+ e.style.top = y + "px"; |
|
| 97 |
+ |
|
| 98 |
+ this.updateBlocker(); |
|
| 99 |
+ }, |
|
| 100 |
+ |
|
| 101 |
+ /** |
|
| 102 |
+ * Resizes the layer by the specified relative width and height. |
|
| 103 |
+ * |
|
| 104 |
+ * @param {int} w Relative width value.
|
|
| 105 |
+ * @param {int} h Relative height value.
|
|
| 106 |
+ */ |
|
| 107 |
+ resizeBy : function(w, h) {
|
|
| 108 |
+ var e = this.getElement(); |
|
| 109 |
+ this.resizeTo(parseInt(e.style.width) + w, parseInt(e.style.height) + h); |
|
| 110 |
+ }, |
|
| 111 |
+ |
|
| 112 |
+ /** |
|
| 113 |
+ * Resizes the layer to the specified width and height. |
|
| 114 |
+ * |
|
| 115 |
+ * @param {int} w Width value.
|
|
| 116 |
+ * @param {int} h Height value.
|
|
| 117 |
+ */ |
|
| 118 |
+ resizeTo : function(w, h) {
|
|
| 119 |
+ var e = this.getElement(); |
|
| 120 |
+ |
|
| 121 |
+ if (w != null) |
|
| 122 |
+ e.style.width = w + "px"; |
|
| 123 |
+ |
|
| 124 |
+ if (h != null) |
|
| 125 |
+ e.style.height = h + "px"; |
|
| 126 |
+ |
|
| 127 |
+ this.updateBlocker(); |
|
| 128 |
+ }, |
|
| 129 |
+ |
|
| 130 |
+ /** |
|
| 131 |
+ * Shows the layer. |
|
| 132 |
+ */ |
|
| 133 |
+ show : function() {
|
|
| 134 |
+ var el = this.getElement(); |
|
| 135 |
+ |
|
| 136 |
+ if (el) {
|
|
| 137 |
+ el.style.display = 'block'; |
|
| 138 |
+ this.updateBlocker(); |
|
| 139 |
+ } |
|
| 140 |
+ }, |
|
| 141 |
+ |
|
| 142 |
+ /** |
|
| 143 |
+ * Hides the layer. |
|
| 144 |
+ */ |
|
| 145 |
+ hide : function() {
|
|
| 146 |
+ var el = this.getElement(); |
|
| 147 |
+ |
|
| 148 |
+ if (el) {
|
|
| 149 |
+ el.style.display = 'none'; |
|
| 150 |
+ this.updateBlocker(); |
|
| 151 |
+ } |
|
| 152 |
+ }, |
|
| 153 |
+ |
|
| 154 |
+ /** |
|
| 155 |
+ * Returns true/false if the layer is visible or not. |
|
| 156 |
+ * |
|
| 157 |
+ * @return true/false if it's visible or not. |
|
| 158 |
+ * @type boolean |
|
| 159 |
+ */ |
|
| 160 |
+ isVisible : function() {
|
|
| 161 |
+ return this.getElement().style.display == 'block'; |
|
| 162 |
+ }, |
|
| 163 |
+ |
|
| 164 |
+ /** |
|
| 165 |
+ * Returns the DOM element that the layer is binded to. |
|
| 166 |
+ * |
|
| 167 |
+ * @return DOM HTML element. |
|
| 168 |
+ * @type HTMLElement |
|
| 169 |
+ */ |
|
| 170 |
+ getElement : function() {
|
|
| 171 |
+ if (!this.element) |
|
| 172 |
+ this.element = this.doc.getElementById(this.id); |
|
| 173 |
+ |
|
| 174 |
+ return this.element; |
|
| 175 |
+ }, |
|
| 176 |
+ |
|
| 177 |
+ /** |
|
| 178 |
+ * Sets the block mode. If you set this property to true a control box blocker iframe |
|
| 179 |
+ * will be added to the document since MSIE has a issue where select boxes are visible |
|
| 180 |
+ * through layers. |
|
| 181 |
+ * |
|
| 182 |
+ * @param {boolean} s Block mode state, true is the default value.
|
|
| 183 |
+ */ |
|
| 184 |
+ setBlockMode : function(s) {
|
|
| 185 |
+ this.blockMode = s; |
|
| 186 |
+ }, |
|
| 187 |
+ |
|
| 188 |
+ /** |
|
| 189 |
+ * Updates the select/iframe/flash blocker this will also block the caret in Firefox. |
|
| 190 |
+ */ |
|
| 191 |
+ updateBlocker : function() {
|
|
| 192 |
+ var e, b, x, y, w, h; |
|
| 193 |
+ |
|
| 194 |
+ b = this.getBlocker(); |
|
| 195 |
+ if (b) {
|
|
| 196 |
+ if (this.blockMode) {
|
|
| 197 |
+ e = this.getElement(); |
|
| 198 |
+ x = this.parseInt(e.style.left); |
|
| 199 |
+ y = this.parseInt(e.style.top); |
|
| 200 |
+ w = this.parseInt(e.offsetWidth); |
|
| 201 |
+ h = this.parseInt(e.offsetHeight); |
|
| 202 |
+ |
|
| 203 |
+ b.style.left = x + 'px'; |
|
| 204 |
+ b.style.top = y + 'px'; |
|
| 205 |
+ b.style.width = w + 'px'; |
|
| 206 |
+ b.style.height = h + 'px'; |
|
| 207 |
+ b.style.display = e.style.display; |
|
| 208 |
+ } else |
|
| 209 |
+ b.style.display = 'none'; |
|
| 210 |
+ } |
|
| 211 |
+ }, |
|
| 212 |
+ |
|
| 213 |
+ /** |
|
| 214 |
+ * Returns the blocker DOM element, this is a invisible iframe. |
|
| 215 |
+ * |
|
| 216 |
+ * @return DOM HTML element. |
|
| 217 |
+ * @type HTMLElement |
|
| 218 |
+ */ |
|
| 219 |
+ getBlocker : function() {
|
|
| 220 |
+ var d, b; |
|
| 221 |
+ |
|
| 222 |
+ if (!this.blockerElement && this.blockMode) {
|
|
| 223 |
+ d = this.doc; |
|
| 224 |
+ b = d.getElementById(this.id + "_blocker"); |
|
| 225 |
+ |
|
| 226 |
+ if (!b) {
|
|
| 227 |
+ b = d.createElement("iframe");
|
|
| 228 |
+ |
|
| 229 |
+ b.setAttribute('id', this.id + "_blocker");
|
|
| 230 |
+ b.style.cssText = 'display: none; position: absolute; left: 0; top: 0'; |
|
| 231 |
+ b.src = 'javascript:false;'; |
|
| 232 |
+ b.frameBorder = '0'; |
|
| 233 |
+ b.scrolling = 'no'; |
|
| 234 |
+ |
|
| 235 |
+ d.body.appendChild(b); |
|
| 236 |
+ } |
|
| 237 |
+ |
|
| 238 |
+ this.blockerElement = b; |
|
| 239 |
+ } |
|
| 240 |
+ |
|
| 241 |
+ return this.blockerElement; |
|
| 242 |
+ }, |
|
| 243 |
+ |
|
| 244 |
+ /** |
|
| 245 |
+ * Returns the absolute x, y cordinate of the specified node. |
|
| 246 |
+ * |
|
| 247 |
+ * @param {DOMElement} n DOM node to retrive x, y of.
|
|
| 248 |
+ * @return Object containing absLeft and absTop properties. |
|
| 249 |
+ * @type Object |
|
| 250 |
+ */ |
|
| 251 |
+ getAbsPosition : function(n) {
|
|
| 252 |
+ var p = {absLeft : 0, absTop : 0};
|
|
| 253 |
+ |
|
| 254 |
+ while (n) {
|
|
| 255 |
+ p.absLeft += n.offsetLeft; |
|
| 256 |
+ p.absTop += n.offsetTop; |
|
| 257 |
+ n = n.offsetParent; |
|
| 258 |
+ } |
|
| 259 |
+ |
|
| 260 |
+ return p; |
|
| 261 |
+ }, |
|
| 262 |
+ |
|
| 263 |
+ /** |
|
| 264 |
+ * Creates a element for the layer based on the id and specified name. |
|
| 265 |
+ * |
|
| 266 |
+ * @param {string} n Element tag name, like div.
|
|
| 267 |
+ * @param {string} c Optional class name to set as class attribute value.
|
|
| 268 |
+ * @param {HTMLElement} p Optional parent element reference, defaults to body.
|
|
| 269 |
+ * @param {string} h Optional HTML code to insert into element.
|
|
| 270 |
+ * @return HTML DOM element that got created. |
|
| 271 |
+ * @type HTMLElement |
|
| 272 |
+ */ |
|
| 273 |
+ create : function(n, c, p, h) {
|
|
| 274 |
+ var d = this.doc, e = d.createElement(n); |
|
| 275 |
+ |
|
| 276 |
+ e.setAttribute('id', this.id);
|
|
| 277 |
+ |
|
| 278 |
+ if (c) |
|
| 279 |
+ e.className = c; |
|
| 280 |
+ |
|
| 281 |
+ if (!p) |
|
| 282 |
+ p = d.body; |
|
| 283 |
+ |
|
| 284 |
+ if (h) |
|
| 285 |
+ e.innerHTML = h; |
|
| 286 |
+ |
|
| 287 |
+ p.appendChild(e); |
|
| 288 |
+ |
|
| 289 |
+ return this.element = e; |
|
| 290 |
+ }, |
|
| 291 |
+ |
|
| 292 |
+ /** |
|
| 293 |
+ * Returns true/false if a element exists for the layer. |
|
| 294 |
+ * |
|
| 295 |
+ * @return true/false if a element exists for the layer. |
|
| 296 |
+ * @type boolean |
|
| 297 |
+ */ |
|
| 298 |
+ exists : function() {
|
|
| 299 |
+ return this.doc.getElementById(this.id) != null; |
|
| 300 |
+ }, |
|
| 301 |
+ |
|
| 302 |
+ /** |
|
| 303 |
+ * Parses a int value this method will return 0 if the string is empty. |
|
| 304 |
+ * |
|
| 305 |
+ * @param {string} s String to parse value of.
|
|
| 306 |
+ * @return Parsed number. |
|
| 307 |
+ * @type int |
|
| 308 |
+ */ |
|
| 309 |
+ parseInt : function(s) {
|
|
| 310 |
+ if (s == null || s == '') |
|
| 311 |
+ return 0; |
|
| 312 |
+ |
|
| 313 |
+ return parseInt(s); |
|
| 314 |
+ }, |
|
| 315 |
+ |
|
| 316 |
+ /** |
|
| 317 |
+ * Removes the element for the layer from DOM and also the blocker iframe. |
|
| 318 |
+ */ |
|
| 319 |
+ remove : function() {
|
|
| 320 |
+ var e = this.getElement(), b = this.getBlocker(); |
|
| 321 |
+ |
|
| 322 |
+ if (e) |
|
| 323 |
+ e.parentNode.removeChild(e); |
|
| 324 |
+ |
|
| 325 |
+ if (b) |
|
| 326 |
+ b.parentNode.removeChild(b); |
|
| 327 |
+ } |
|
| 328 |
+ |
|
| 329 |
+ /**#@-*/ |
|
| 330 |
+}; |