Debian Codegraph @

closure-library/closure/goog/positioning/viewportposition.js

raw
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.ViewportPosition');
22
23 goog.require('goog.math.Coordinate');
24 goog.require('goog.positioning');
25 goog.require('goog.positioning.AbstractPosition');
26 goog.require('goog.positioning.Corner');
27 goog.require('goog.style');
28
29
30
31 /**
32 * Encapsulates a popup position where the popup is positioned according to
33 * coordinates relative to the element's viewport (page). This calculates the
34 * correct position to use even if the element is relatively positioned to some
35 * other element.
36 *
37 * @param {number|goog.math.Coordinate} arg1 Left position or coordinate.
38 * @param {number=} opt_arg2 Top position.
39 * @constructor
40 * @extends {goog.positioning.AbstractPosition}
41 */
42 goog.positioning.ViewportPosition = function(arg1, opt_arg2) {
43 this.coordinate = arg1 instanceof goog.math.Coordinate ?
44 arg1 :
45 new goog.math.Coordinate(/** @type {number} */ (arg1), opt_arg2);
46 };
47 goog.inherits(
48 goog.positioning.ViewportPosition, goog.positioning.AbstractPosition);
49
50
51 /**
52 * Repositions the popup according to the current state
53 *
54 * @param {Element} element The DOM element of the popup.
55 * @param {goog.positioning.Corner} popupCorner The corner of the popup
56 * element that that should be positioned adjacent to the anchorElement.
57 * @param {goog.math.Box=} opt_margin A margin specified in pixels.
58 * @param {goog.math.Size=} opt_preferredSize Preferred size of the element.
59 * @override
60 */
61 goog.positioning.ViewportPosition.prototype.reposition = function(
62 element, popupCorner, opt_margin, opt_preferredSize) {
63 goog.positioning.positionAtAnchor(
64 goog.style.getClientViewportElement(element),
65 goog.positioning.Corner.TOP_LEFT, element, popupCorner, this.coordinate,
66 opt_margin, null, opt_preferredSize);
67 };