menuanchoredposition.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 Anchored viewport positioning class with both adjust and
  16. * resize options for the popup.
  17. *
  18. * @author eae@google.com (Emil A Eklund)
  19. */
  20. goog.provide('goog.positioning.MenuAnchoredPosition');
  21. goog.require('goog.positioning.AnchoredViewportPosition');
  22. goog.require('goog.positioning.Overflow');
  23. /**
  24. * Encapsulates a popup position where the popup is anchored at a corner of
  25. * an element. The positioning behavior changes based on the values of
  26. * opt_adjust and opt_resize.
  27. *
  28. * When using this positioning object it's recommended that the movable element
  29. * be absolutely positioned.
  30. *
  31. * @param {Element} anchorElement Element the movable element should be
  32. * anchored against.
  33. * @param {goog.positioning.Corner} corner Corner of anchored element the
  34. * movable element should be positioned at.
  35. * @param {boolean=} opt_adjust Whether the positioning should be adjusted until
  36. * the element fits inside the viewport even if that means that the anchored
  37. * corners are ignored.
  38. * @param {boolean=} opt_resize Whether the positioning should be adjusted until
  39. * the element fits inside the viewport on the X axis and its height is
  40. * resized so if fits in the viewport. This take precedence over opt_adjust.
  41. * @constructor
  42. * @extends {goog.positioning.AnchoredViewportPosition}
  43. */
  44. goog.positioning.MenuAnchoredPosition = function(
  45. anchorElement, corner, opt_adjust, opt_resize) {
  46. goog.positioning.AnchoredViewportPosition.call(
  47. this, anchorElement, corner, opt_adjust || opt_resize);
  48. if (opt_adjust || opt_resize) {
  49. var overflowX = goog.positioning.Overflow.ADJUST_X_EXCEPT_OFFSCREEN;
  50. var overflowY = opt_resize ?
  51. goog.positioning.Overflow.RESIZE_HEIGHT :
  52. goog.positioning.Overflow.ADJUST_Y_EXCEPT_OFFSCREEN;
  53. this.setLastResortOverflow(overflowX | overflowY);
  54. }
  55. };
  56. goog.inherits(
  57. goog.positioning.MenuAnchoredPosition,
  58. goog.positioning.AnchoredViewportPosition);