| 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 |
/** |
| 16 |
* @fileoverview Client positioning class. |
| 17 |
* |
| 18 |
* @author [email protected] (Emil A Eklund) |
| 19 |
*/ |
| 20 |
|
| 21 |
goog.provide('goog.positioning.AnchoredPosition'); |
| 22 |
|
| 23 |
goog.require('goog.positioning'); |
| 24 |
goog.require('goog.positioning.AbstractPosition'); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* Encapsulates a popup position where the popup is anchored at a corner of |
| 30 |
* an element. |
| 31 |
* |
| 32 |
* When using AnchoredPosition, it is recommended that the popup element |
| 33 |
* specified in the Popup constructor or Popup.setElement be absolutely |
| 34 |
* positioned. |
| 35 |
* |
| 36 |
* @param {Element} anchorElement Element the movable element should be |
| 37 |
* anchored against. |
| 38 |
* @param {goog.positioning.Corner} corner Corner of anchored element the |
| 39 |
* movable element should be positioned at. |
| 40 |
* @param {number=} opt_overflow Overflow handling mode. Defaults to IGNORE if |
| 41 |
* not specified. Bitmap, {@see goog.positioning.Overflow}. |
| 42 |
* @constructor |
| 43 |
* @extends {goog.positioning.AbstractPosition} |
| 44 |
*/ |
| 45 |
goog.positioning.AnchoredPosition = function( |
| 46 |
anchorElement, corner, opt_overflow) { |
| 47 |
/** |
| 48 |
* Element the movable element should be anchored against. |
| 49 |
* @type {Element} |
| 50 |
*/ |
| 51 |
this.element = anchorElement; |
| 52 |
|
| 53 |
/** |
| 54 |
* Corner of anchored element the movable element should be positioned at. |
| 55 |
* @type {goog.positioning.Corner} |
| 56 |
*/ |
| 57 |
this.corner = corner; |
| 58 |
|
| 59 |
/** |
| 60 |
* Overflow handling mode. Defaults to IGNORE if not specified. |
| 61 |
* Bitmap, {@see goog.positioning.Overflow}. |
| 62 |
* @type {number|undefined} |
| 63 |
* @private |
| 64 |
*/ |
| 65 |
this.overflow_ = opt_overflow; |
| 66 |
}; |
| 67 |
goog.inherits( |
| 68 |
goog.positioning.AnchoredPosition, goog.positioning.AbstractPosition); |
| 69 |
|
| 70 |
|
| 71 |
/** |
| 72 |
* Repositions the movable element. |
| 73 |
* |
| 74 |
* @param {Element} movableElement Element to position. |
| 75 |
* @param {goog.positioning.Corner} movableCorner Corner of the movable element |
| 76 |
* that should be positioned adjacent to the anchored element. |
| 77 |
* @param {goog.math.Box=} opt_margin A margin specifin pixels. |
| 78 |
* @param {goog.math.Size=} opt_preferredSize PreferredSize of the |
| 79 |
* movableElement (unused in this class). |
| 80 |
* @override |
| 81 |
*/ |
| 82 |
goog.positioning.AnchoredPosition.prototype.reposition = function( |
| 83 |
movableElement, movableCorner, opt_margin, opt_preferredSize) { |
| 84 |
goog.positioning.positionAtAnchor( |
| 85 |
this.element, this.corner, movableElement, movableCorner, undefined, |
| 86 |
opt_margin, this.overflow_); |
| 87 |
}; |