| | 451 | * APIMethod: updateSize |
|---|
| | 452 | * Auto size the popup so that it precisely fits its contents (as |
|---|
| | 453 | * determined by this.contentDiv.innerHTML). Popup size will, of |
|---|
| | 454 | * course, be limited by the available space on the current map |
|---|
| | 455 | */ |
|---|
| | 456 | updateSize: function() { |
|---|
| | 457 | |
|---|
| | 458 | // determine actual render dimensions of the contents by putting its |
|---|
| | 459 | // contents into a fake contentDiv (for the CSS) and then measuring it |
|---|
| | 460 | var preparedHTML = "<div class='" + this.contentDisplayClass+ "'>" + |
|---|
| | 461 | this.contentDiv.innerHTML + |
|---|
| | 462 | "<div>"; |
|---|
| | 463 | var realSize = OpenLayers.Util.getRenderedDimensions( |
|---|
| | 464 | preparedHTML, null, { displayClass: this.displayClass } |
|---|
| | 465 | ); |
|---|
| | 466 | |
|---|
| | 467 | // is the "real" size of the div is safe to display in our map? |
|---|
| | 468 | var safeSize = this.getSafeContentSize(realSize); |
|---|
| | 469 | |
|---|
| | 470 | var newSize = null; |
|---|
| | 471 | if (safeSize.equals(realSize)) { |
|---|
| | 472 | //real size of content is small enough to fit on the map, |
|---|
| | 473 | // so we use real size. |
|---|
| | 474 | newSize = realSize; |
|---|
| | 475 | |
|---|
| | 476 | } else { |
|---|
| | 477 | |
|---|
| | 478 | //make a new OL.Size object with the clipped dimensions |
|---|
| | 479 | // set or null if not clipped. |
|---|
| | 480 | var fixedSize = new OpenLayers.Size(); |
|---|
| | 481 | fixedSize.w = (safeSize.w < realSize.w) ? safeSize.w : null; |
|---|
| | 482 | fixedSize.h = (safeSize.h < realSize.h) ? safeSize.h : null; |
|---|
| | 483 | |
|---|
| | 484 | if (fixedSize.w && fixedSize.h) { |
|---|
| | 485 | //content is too big in both directions, so we will use |
|---|
| | 486 | // max popup size (safeSize), knowing well that it will |
|---|
| | 487 | // overflow both ways. |
|---|
| | 488 | newSize = safeSize; |
|---|
| | 489 | } else { |
|---|
| | 490 | //content is clipped in only one direction, so we need to |
|---|
| | 491 | // run getRenderedDimensions() again with a fixed dimension |
|---|
| | 492 | var clippedSize = OpenLayers.Util.getRenderedDimensions( |
|---|
| | 493 | preparedHTML, fixedSize, |
|---|
| | 494 | { displayClass: this.contentDisplayClass } |
|---|
| | 495 | ); |
|---|
| | 496 | |
|---|
| | 497 | //if the clipped size is still the same as the safeSize, |
|---|
| | 498 | // that means that our content must be fixed in the |
|---|
| | 499 | // offending direction. If overflow is 'auto', this means |
|---|
| | 500 | // we are going to have a scrollbar for sure, so we must |
|---|
| | 501 | // adjust for that. |
|---|
| | 502 | // |
|---|
| | 503 | var currentOverflow = OpenLayers.Element.getStyle( |
|---|
| | 504 | this.contentDiv, "overflow" |
|---|
| | 505 | ); |
|---|
| | 506 | if ( (currentOverflow != "hidden") && |
|---|
| | 507 | (clippedSize.equals(safeSize)) ) { |
|---|
| | 508 | var scrollBar = OpenLayers.Util.getScrollbarWidth(); |
|---|
| | 509 | if (fixedSize.w) { |
|---|
| | 510 | clippedSize.h += scrollBar; |
|---|
| | 511 | } else { |
|---|
| | 512 | clippedSize.w += scrollBar; |
|---|
| | 513 | } |
|---|
| | 514 | } |
|---|
| | 515 | |
|---|
| | 516 | newSize = this.getSafeContentSize(clippedSize); |
|---|
| | 517 | } |
|---|
| | 518 | } |
|---|
| | 519 | this.setSize(newSize); |
|---|
| | 520 | }, |
|---|
| | 521 | |
|---|
| | 522 | /** |
|---|
| 519 | | if (this.autoSize) { |
|---|
| 520 | | //fake the contentDiv for the CSS context |
|---|
| 521 | | preparedHTML = "<div class='" + this.contentDisplayClass+ "'>" + this.contentHTML + "<div>"; |
|---|
| 522 | | |
|---|
| 523 | | // determine actual render dimensions of the contents |
|---|
| 524 | | var realSize = |
|---|
| 525 | | OpenLayers.Util.getRenderedDimensions(preparedHTML, null, |
|---|
| 526 | | { displayClass: this.displayClass }); |
|---|
| 527 | | |
|---|
| 528 | | // is the "real" size of the div is safe to display in our map? |
|---|
| 529 | | var safeSize = this.getSafeContentSize(realSize); |
|---|
| 530 | | |
|---|
| 531 | | var newSize = null; |
|---|
| 532 | | |
|---|
| 533 | | if (safeSize.equals(realSize)) { |
|---|
| 534 | | //real size of content is small enough to fit on the map, |
|---|
| 535 | | // so we use real size. |
|---|
| 536 | | newSize = realSize; |
|---|
| 537 | | |
|---|
| 538 | | } else { |
|---|
| 539 | | |
|---|
| 540 | | //make a new OL.Size object with the clipped dimensions |
|---|
| 541 | | // set or null if not clipped. |
|---|
| 542 | | var fixedSize = new OpenLayers.Size(); |
|---|
| 543 | | fixedSize.w = (safeSize.w < realSize.w) ? safeSize.w : null; |
|---|
| 544 | | fixedSize.h = (safeSize.h < realSize.h) ? safeSize.h : null; |
|---|
| 545 | | |
|---|
| 546 | | if (fixedSize.w && fixedSize.h) { |
|---|
| 547 | | //content is too big in both directions, so we will use |
|---|
| 548 | | // max popup size (safeSize), knowing well that it will |
|---|
| 549 | | // overflow both ways. |
|---|
| 550 | | newSize = safeSize; |
|---|
| 551 | | } else { |
|---|
| 552 | | //content is clipped in only one direction, so we need to |
|---|
| 553 | | // run getRenderedDimensions() again with a fixed dimension |
|---|
| 554 | | var clippedSize = OpenLayers.Util.getRenderedDimensions( |
|---|
| 555 | | preparedHTML, fixedSize, |
|---|
| 556 | | { displayClass: this.contentDisplayClass } |
|---|
| 557 | | ); |
|---|
| 558 | | |
|---|
| 559 | | //if the clipped size is still the same as the safeSize, |
|---|
| 560 | | // that means that our content must be fixed in the |
|---|
| 561 | | // offending direction. If overflow is 'auto', this means |
|---|
| 562 | | // we are going to have a scrollbar for sure, so we must |
|---|
| 563 | | // adjust for that. |
|---|
| 564 | | // |
|---|
| 565 | | var currentOverflow = OpenLayers.Element.getStyle( |
|---|
| 566 | | this.contentDiv, "overflow" |
|---|
| 567 | | ); |
|---|
| 568 | | if ( (currentOverflow != "hidden") && |
|---|
| 569 | | (clippedSize.equals(safeSize)) ) { |
|---|
| 570 | | var scrollBar = OpenLayers.Util.getScrollbarWidth(); |
|---|
| 571 | | if (fixedSize.w) { |
|---|
| 572 | | clippedSize.h += scrollBar; |
|---|
| 573 | | } else { |
|---|
| 574 | | clippedSize.w += scrollBar; |
|---|
| 575 | | } |
|---|
| 576 | | } |
|---|
| 577 | | |
|---|
| 578 | | newSize = this.getSafeContentSize(clippedSize); |
|---|
| 579 | | } |
|---|
| 580 | | } |
|---|
| 581 | | this.setSize(newSize); |
|---|
| 582 | | } |
|---|
| 583 | | |
|---|
| 584 | | if (this.contentDiv != null) { |
|---|
| | 590 | if ((this.contentDiv != null) && |
|---|
| | 591 | (this.contentHTML != null) && |
|---|
| | 592 | (this.contentHTML != this.contentDiv.innerHTML)) { |
|---|