anchoredposition.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2006 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Client positioning class.
  16. *
  17. * @author eae@google.com (Emil A Eklund)
  18. */
  19. goog.provide('goog.positioning.AnchoredPosition');
  20. goog.require('goog.positioning');
  21. goog.require('goog.positioning.AbstractPosition');
  22. /**
  23. * Encapsulates a popup position where the popup is anchored at a corner of
  24. * an element.
  25. *
  26. * When using AnchoredPosition, it is recommended that the popup element
  27. * specified in the Popup constructor or Popup.setElement be absolutely
  28. * positioned.
  29. *
  30. * @param {Element} anchorElement Element the movable element should be
  31. * anchored against.
  32. * @param {goog.positioning.Corner} corner Corner of anchored element the
  33. * movable element should be positioned at.
  34. * @param {number=} opt_overflow Overflow handling mode. Defaults to IGNORE if
  35. * not specified. Bitmap, {@see goog.positioning.Overflow}.
  36. * @constructor
  37. * @extends {goog.positioning.AbstractPosition}
  38. */
  39. goog.positioning.AnchoredPosition = function(
  40. anchorElement, corner, opt_overflow) {
  41. /**
  42. * Element the movable element should be anchored against.
  43. * @type {Element}
  44. */
  45. this.element = anchorElement;
  46. /**
  47. * Corner of anchored element the movable element should be positioned at.
  48. * @type {goog.positioning.Corner}
  49. */
  50. this.corner = corner;
  51. /**
  52. * Overflow handling mode. Defaults to IGNORE if not specified.
  53. * Bitmap, {@see goog.positioning.Overflow}.
  54. * @type {number|undefined}
  55. * @private
  56. */
  57. this.overflow_ = opt_overflow;
  58. };
  59. goog.inherits(
  60. goog.positioning.AnchoredPosition, goog.positioning.AbstractPosition);
  61. /**
  62. * Repositions the movable element.
  63. *
  64. * @param {Element} movableElement Element to position.
  65. * @param {goog.positioning.Corner} movableCorner Corner of the movable element
  66. * that should be positioned adjacent to the anchored element.
  67. * @param {goog.math.Box=} opt_margin A margin specifin pixels.
  68. * @param {goog.math.Size=} opt_preferredSize PreferredSize of the
  69. * movableElement (unused in this class).
  70. * @override
  71. */
  72. goog.positioning.AnchoredPosition.prototype.reposition = function(
  73. movableElement, movableCorner, opt_margin, opt_preferredSize) {
  74. goog.positioning.positionAtAnchor(
  75. this.element, this.corner, movableElement, movableCorner, undefined,
  76. opt_margin, this.overflow_);
  77. };