absoluteposition.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 viewport positioning class.
  16. *
  17. * @author eae@google.com (Emil A Eklund)
  18. */
  19. goog.provide('goog.positioning.AbsolutePosition');
  20. goog.require('goog.math.Coordinate');
  21. goog.require('goog.positioning');
  22. goog.require('goog.positioning.AbstractPosition');
  23. /**
  24. * Encapsulates a popup position where the popup absolutely positioned by
  25. * setting the left/top style elements directly to the specified values.
  26. * The position is generally relative to the element's offsetParent. Normally,
  27. * this is the document body, but can be another element if the popup element
  28. * is scoped by an element with relative position.
  29. *
  30. * @param {number|!goog.math.Coordinate} arg1 Left position or coordinate.
  31. * @param {number=} opt_arg2 Top position.
  32. * @constructor
  33. * @extends {goog.positioning.AbstractPosition}
  34. */
  35. goog.positioning.AbsolutePosition = function(arg1, opt_arg2) {
  36. /**
  37. * Coordinate to position popup at.
  38. * @type {goog.math.Coordinate}
  39. */
  40. this.coordinate = arg1 instanceof goog.math.Coordinate ?
  41. arg1 :
  42. new goog.math.Coordinate(/** @type {number} */ (arg1), opt_arg2);
  43. };
  44. goog.inherits(
  45. goog.positioning.AbsolutePosition, goog.positioning.AbstractPosition);
  46. /**
  47. * Repositions the popup according to the current state.
  48. *
  49. * @param {Element} movableElement The DOM element to position.
  50. * @param {goog.positioning.Corner} movableCorner The corner of the movable
  51. * element that should be positioned at the specified position.
  52. * @param {goog.math.Box=} opt_margin A margin specified in pixels.
  53. * @param {goog.math.Size=} opt_preferredSize Preferred size of the
  54. * movableElement.
  55. * @override
  56. */
  57. goog.positioning.AbsolutePosition.prototype.reposition = function(
  58. movableElement, movableCorner, opt_margin, opt_preferredSize) {
  59. goog.positioning.positionAtCoordinate(
  60. this.coordinate, movableElement, movableCorner, opt_margin, null, null,
  61. opt_preferredSize);
  62. };