OLD | NEW |
| (Empty) |
1 /* | |
2 Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 */ | |
6 | |
7 /** | |
8 * @fileoverview Collection of functions which operate on DOM. | |
9 */ | |
10 | |
11 var domUtils = window['domUtils'] || {}; | |
12 | |
13 /** | |
14 * Returns pageX and pageY of the given element. | |
15 * | |
16 * @param {Element} element An element of which the top-left position is to be | |
17 * returned in the coordinate system of the document page. | |
18 * @return {Object} A point object which has {@code x} and {@code y} fields. | |
19 */ | |
20 domUtils.pageXY = function(element) { | |
21 var x = 0, y = 0; | |
22 for (; element; element = element.offsetParent) { | |
23 x += element.offsetLeft; | |
24 y += element.offsetTop; | |
25 } | |
26 return {'x': x, 'y': y}; | |
27 }; | |
28 | |
29 /** | |
30 * Returns pageX and pageY of the given event. | |
31 * | |
32 * @param {Event} event An event of which the position is to be returned in | |
33 * the coordinate system of the document page. | |
34 * @return {Object} A point object which has {@code x} and {@code y} fields. | |
35 */ | |
36 domUtils.pageXYOfEvent = function(event) { | |
37 return (event.pageX != null && event.pageY != null) ? | |
38 {'x': event.pageX, 'y': event.pageY} : | |
39 {'x': event.clientX + document.body.scrollLeft + | |
40 document.documentElement.scrollLeft, | |
41 'y': event.clientY + document.body.scrollTop + | |
42 document.documentElement.scrollTop}; | |
43 }; | |
OLD | NEW |