| 57 | | * Property: frames |
|---|
| 58 | | * {Object} Hash which directly corresponds to the 'positionBlocks' hash, |
|---|
| 59 | | * but which contains the specific DOM instances for this popup. |
|---|
| 60 | | * |
|---|
| 61 | | * The frames hash will contain up to four 'position' hashes (one for |
|---|
| 62 | | * each of "tl", "tr", "bl", "br"). Each positon has will have its |
|---|
| 63 | | * own div, and a 'blocks' property, which is an array of the |
|---|
| 64 | | * individual frame divs. |
|---|
| 65 | | */ |
|---|
| 66 | | frames: null, |
|---|
| | 57 | * Property: blocks |
|---|
| | 58 | * {Array[Object]} Array of objects, each of which is one "block" of the |
|---|
| | 59 | * popup. Each block has a 'div' and an 'image' property, both of |
|---|
| | 60 | * which are DOMElements, and the latter of which is appended to the |
|---|
| | 61 | * former. These are reused as the popup goes changing positions for |
|---|
| | 62 | * great economy and elegance. |
|---|
| | 63 | */ |
|---|
| | 64 | blocks: null, |
|---|
| 133 | | |
|---|
| 134 | | var possiblePositions = ['tl', 'tr', 'bl', 'br']; |
|---|
| 135 | | for(var i = 0; i < possiblePositions.length; i++) { |
|---|
| 136 | | var position = this.frames[possiblePositions[i]]; |
|---|
| 137 | | if (position != null) { |
|---|
| 138 | | for(var j = 0; j < position.blocks.length; j++) { |
|---|
| 139 | | var block = position.blocks[j]; |
|---|
| 140 | | |
|---|
| 141 | | if (block.image) { |
|---|
| 142 | | block.div.removeChild(block.image); |
|---|
| 143 | | } |
|---|
| 144 | | block.image = null; |
|---|
| 145 | | |
|---|
| 146 | | if (block.div) { |
|---|
| 147 | | position.div.removeChild(block.div); |
|---|
| 148 | | } |
|---|
| 149 | | block.div = null; |
|---|
| 150 | | } |
|---|
| 151 | | if (position.div) { |
|---|
| 152 | | this.groupDiv.removeChild(position.div); |
|---|
| 153 | | } |
|---|
| 154 | | position.div = null; |
|---|
| 155 | | delete this.frames[possiblePositions[i]]; |
|---|
| | 129 | this.positionBlocks = null; |
|---|
| | 130 | |
|---|
| | 131 | //remove our blocks |
|---|
| | 132 | for(var i = 0; i < this.blocks.length; i++) { |
|---|
| | 133 | var block = this.blocks[j]; |
|---|
| | 134 | |
|---|
| | 135 | if (block.image) { |
|---|
| | 136 | this.groupDiv.removeChild(block.image); |
|---|
| 256 | | * Method: createFrame |
|---|
| 257 | | * |
|---|
| 258 | | * Parameters: |
|---|
| 259 | | * pos - {String} |
|---|
| 260 | | * |
|---|
| 261 | | * Returns: |
|---|
| 262 | | * {Object} Frame entry, with blocks array |
|---|
| 263 | | */ |
|---|
| 264 | | createFrame: function(pos) { |
|---|
| 265 | | var frame = { |
|---|
| 266 | | 'blocks': [] |
|---|
| 267 | | }; |
|---|
| 268 | | |
|---|
| 269 | | frame.div = OpenLayers.Util.createDiv(pos + "-popup", |
|---|
| 270 | | null, null, null, 'relative' |
|---|
| 271 | | ); |
|---|
| 272 | | frame.div.style.height = '100%'; |
|---|
| 273 | | frame.div.style.width = '100%'; |
|---|
| 274 | | this.groupDiv.appendChild(frame.div); |
|---|
| 275 | | |
|---|
| 276 | | var position = this.positionBlocks[pos]; |
|---|
| | 243 | * Method: createBlocks |
|---|
| | 244 | */ |
|---|
| | 245 | createBlocks: function() { |
|---|
| | 246 | this.blocks = []; |
|---|
| | 247 | |
|---|
| | 248 | var position = this.positionBlocks[this.relativePosition]; |
|---|
| 308 | | * the corresponding popups in their appropropriate places. |
|---|
| 309 | | */ |
|---|
| 310 | | updateFrames: function() { |
|---|
| 311 | | |
|---|
| 312 | | for (var pos in this.positionBlocks) { |
|---|
| 313 | | var position = this.positionBlocks[pos]; |
|---|
| 314 | | var frame = this.frames[pos]; |
|---|
| 315 | | |
|---|
| 316 | | if (pos != this.relativePosition) { |
|---|
| 317 | | if (frame) { |
|---|
| 318 | | OpenLayers.Element.hide(frame.div); |
|---|
| 319 | | } |
|---|
| 320 | | } else { |
|---|
| 321 | | if (!frame) { |
|---|
| 322 | | frame = this.frames[pos] = this.createFrame(pos); |
|---|
| 323 | | } |
|---|
| 324 | | OpenLayers.Element.show(frame.div); |
|---|
| 325 | | |
|---|
| 326 | | for (var i = 0; i < position.blocks.length; i++) { |
|---|
| 327 | | |
|---|
| 328 | | var block = position.blocks[i]; |
|---|
| 329 | | var fBlock = frame.blocks[i]; |
|---|
| 330 | | |
|---|
| 331 | | // adjust sizes |
|---|
| 332 | | var l = block.anchor.left; |
|---|
| 333 | | var b = block.anchor.bottom; |
|---|
| 334 | | var r = block.anchor.right; |
|---|
| 335 | | var t = block.anchor.top; |
|---|
| 336 | | |
|---|
| 337 | | //note that we use the isNaN() test here because if the |
|---|
| 338 | | // size object is initialized with a "auto" parameter, the |
|---|
| 339 | | // size constructor calls parseFloat() on the string, |
|---|
| 340 | | // which will turn it into NaN |
|---|
| 341 | | // |
|---|
| 342 | | var w = (isNaN(block.size.w)) ? this.size.w - (r + l) |
|---|
| 343 | | : block.size.w; |
|---|
| 344 | | |
|---|
| 345 | | var h = (isNaN(block.size.h)) ? this.size.h - (b + t) |
|---|
| 346 | | : block.size.h; |
|---|
| 347 | | |
|---|
| 348 | | fBlock.div.style.width = w + 'px'; |
|---|
| 349 | | fBlock.div.style.height = h + 'px'; |
|---|
| 350 | | |
|---|
| 351 | | fBlock.div.style.left = (l != null) ? l + 'px' : ''; |
|---|
| 352 | | fBlock.div.style.bottom = (b != null) ? b + 'px' : ''; |
|---|
| 353 | | fBlock.div.style.right = (r != null) ? r + 'px' : ''; |
|---|
| 354 | | fBlock.div.style.top = (t != null) ? t + 'px' : ''; |
|---|
| 355 | | |
|---|
| 356 | | fBlock.image.style.left = block.position.x + 'px'; |
|---|
| 357 | | fBlock.image.style.top = block.position.y + 'px'; |
|---|
| 358 | | } |
|---|
| 359 | | |
|---|
| 360 | | } |
|---|
| | 278 | * the popup's blocks in their appropropriate places. |
|---|
| | 279 | */ |
|---|
| | 280 | updateBlocks: function() { |
|---|
| | 281 | |
|---|
| | 282 | if (!this.blocks) { |
|---|
| | 283 | this.createBlocks(); |
|---|
| | 284 | } |
|---|
| | 285 | |
|---|
| | 286 | var position = this.positionBlocks[this.relativePosition]; |
|---|
| | 287 | for (var i = 0; i < position.blocks.length; i++) { |
|---|
| | 288 | |
|---|
| | 289 | var positionBlock = position.blocks[i]; |
|---|
| | 290 | var block = this.blocks[i]; |
|---|
| | 291 | |
|---|
| | 292 | // adjust sizes |
|---|
| | 293 | var l = positionBlock.anchor.left; |
|---|
| | 294 | var b = positionBlock.anchor.bottom; |
|---|
| | 295 | var r = positionBlock.anchor.right; |
|---|
| | 296 | var t = positionBlock.anchor.top; |
|---|
| | 297 | |
|---|
| | 298 | //note that we use the isNaN() test here because if the |
|---|
| | 299 | // size object is initialized with a "auto" parameter, the |
|---|
| | 300 | // size constructor calls parseFloat() on the string, |
|---|
| | 301 | // which will turn it into NaN |
|---|
| | 302 | // |
|---|
| | 303 | var w = (isNaN(positionBlock.size.w)) ? this.size.w - (r + l) |
|---|
| | 304 | : positionBlock.size.w; |
|---|
| | 305 | |
|---|
| | 306 | var h = (isNaN(positionBlock.size.h)) ? this.size.h - (b + t) |
|---|
| | 307 | : positionBlock.size.h; |
|---|
| | 308 | |
|---|
| | 309 | block.div.style.width = w + 'px'; |
|---|
| | 310 | block.div.style.height = h + 'px'; |
|---|
| | 311 | |
|---|
| | 312 | block.div.style.left = (l != null) ? l + 'px' : ''; |
|---|
| | 313 | block.div.style.bottom = (b != null) ? b + 'px' : ''; |
|---|
| | 314 | block.div.style.right = (r != null) ? r + 'px' : ''; |
|---|
| | 315 | block.div.style.top = (t != null) ? t + 'px' : ''; |
|---|
| | 316 | |
|---|
| | 317 | block.image.style.left = positionBlock.position.x + 'px'; |
|---|
| | 318 | block.image.style.top = positionBlock.position.y + 'px'; |
|---|