Path: blob/trunk/third_party/closure/goog/positioning/viewportposition.js
2868 views
// Copyright 2006 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Client positioning class.16*17* @author [email protected] (Emil A Eklund)18*/1920goog.provide('goog.positioning.ViewportPosition');2122goog.require('goog.math.Coordinate');23goog.require('goog.positioning');24goog.require('goog.positioning.AbstractPosition');25goog.require('goog.positioning.Corner');26goog.require('goog.style');27282930/**31* Encapsulates a popup position where the popup is positioned according to32* coordinates relative to the element's viewport (page). This calculates the33* correct position to use even if the element is relatively positioned to some34* other element.35*36* @param {number|goog.math.Coordinate} arg1 Left position or coordinate.37* @param {number=} opt_arg2 Top position.38* @constructor39* @extends {goog.positioning.AbstractPosition}40*/41goog.positioning.ViewportPosition = function(arg1, opt_arg2) {42this.coordinate = arg1 instanceof goog.math.Coordinate ?43arg1 :44new goog.math.Coordinate(/** @type {number} */ (arg1), opt_arg2);45};46goog.inherits(47goog.positioning.ViewportPosition, goog.positioning.AbstractPosition);484950/**51* Repositions the popup according to the current state52*53* @param {Element} element The DOM element of the popup.54* @param {goog.positioning.Corner} popupCorner The corner of the popup55* element that that should be positioned adjacent to the anchorElement.56* @param {goog.math.Box=} opt_margin A margin specified in pixels.57* @param {goog.math.Size=} opt_preferredSize Preferred size of the element.58* @override59*/60goog.positioning.ViewportPosition.prototype.reposition = function(61element, popupCorner, opt_margin, opt_preferredSize) {62goog.positioning.positionAtAnchor(63goog.style.getClientViewportElement(element),64goog.positioning.Corner.TOP_LEFT, element, popupCorner, this.coordinate,65opt_margin, null, opt_preferredSize);66};676869