1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2007 1&1 Internet AG, Germany, http://www.1and1.org
License:
LGPL: http://www.gnu.org/licenses/lgpl.html
EPL: http://www.eclipse.org/org/documents/epl-v10.php
See the LICENSE file in the project's top-level directory for details.
Authors:
* Sebastian Werner (wpbasti)
* Andreas Ecker (ecker)
************************************************************************ */
/* ************************************************************************
#module(ui_core)
#require(qx.html.Style)
************************************************************************ */
/**
* Functions to scroll DOM elements into the visible area of the parent element
*/
qx.OO.defineClass("qx.html.ScrollIntoView");
// Internet Explorer has invented scrollIntoView, but does not behave the same like in Mozilla (which would be better)
// Mozilla has a native well working method scrollIntoView
// Safari does not support scrollIntoView (but it can be found in Webkit since May 2005)
// Opera does not support scrollIntoView
/** the documents body tag name */
qx.dom.BODY_TAG_NAME = "body";
/**
* Scroll the parent DOM element so that the element's so that the x coordinate is inside
* the visible area of the parent.
*
* @param vElement {Element} DOM node to be scrolled into view
* @param vAlignLeft {Boolean} whether the element should be left aligned
*/
qx.html.ScrollIntoView.scrollX = function(vElement, vAlignLeft)
{
var vParentWidth, vParentScrollLeft, vWidth, vHasScroll;
var vParent = vElement.parentNode;
var vOffset = vElement.offsetLeft;
var vWidth = vElement.offsetWidth;
while(vParent)
{
switch(qx.html.Style.getStyleProperty(vParent, "overflow"))
{
case "scroll":
case "auto":
case "-moz-scrollbars-horizontal":
vHasScroll = true;
break;
default:
switch(qx.html.Style.getStyleProperty(vParent, "overflowX"))
{
case "scroll":
case "auto":
vHasScroll = true;
break;
default:
vHasScroll = false;
}
}
if (vHasScroll)
{
vParentWidth = vParent.clientWidth;
vParentScrollLeft = vParent.scrollLeft;
if (vAlignLeft)
{
vParent.scrollLeft = vOffset;
}
else if (vAlignLeft == false)
{
vParent.scrollLeft = vOffset + vWidth - vParentWidth;
}
else if (vWidth > vParentWidth || vOffset < vParentScrollLeft)
{
vParent.scrollLeft = vOffset;
}
else if ((vOffset + vWidth) > (vParentScrollLeft + vParentWidth))
{
vParent.scrollLeft = vOffset + vWidth - vParentWidth;
}
vOffset = vParent.offsetLeft;
vWidth = vParent.offsetWidth;
}
else
{
vOffset += vParent.offsetLeft;
}
if (vParent.tagName.toLowerCase() == qx.dom.BODY_TAG_NAME) {
break;
}
vParent = vParent.parentNode;
}
return true;
}
/**
* Scroll the parent DOM element so that the element's so that the y coordinate is inside
* the visible area of the parent.
*
* @param vElement {Element} DOM node to be scrolled into view
* @param vAlignTop {Boolean} whether the element should be top aligned
*/
qx.html.ScrollIntoView.scrollY = function(vElement, vAlignTop)
{
var vParentHeight, vParentScrollTop, vHeight, vHasScroll;
var vParent = vElement.parentNode;
var vOffset = vElement.offsetTop;
var vHeight = vElement.offsetHeight;
while(vParent)
{
switch(qx.html.Style.getStyleProperty(vParent, "overflow"))
{
case "scroll":
case "auto":
case "-moz-scrollbars-vertical":
vHasScroll = true;
break;
default:
switch(qx.html.Style.getStyleProperty(vParent, "overflowY"))
{
case "scroll":
case "auto":
vHasScroll = true;
break;
default:
vHasScroll = false;
}
}
if (vHasScroll)
{
vParentHeight = vParent.clientHeight;
vParentScrollTop = vParent.scrollTop;
if (vAlignTop)
{
vParent.scrollTop = vOffset;
}
else if (vAlignTop == false)
{
vParent.scrollTop = vOffset + vHeight - vParentHeight;
}
else if (vHeight > vParentHeight || vOffset < vParentScrollTop)
{
vParent.scrollTop = vOffset;
}
else if ((vOffset + vHeight) > (vParentScrollTop + vParentHeight))
{
vParent.scrollTop = vOffset + vHeight - vParentHeight;
}
vOffset = vParent.offsetTop;
vHeight = vParent.offsetHeight;
}
else
{
vOffset += vParent.offsetTop;
}
if (vParent.tagName.toLowerCase() == qx.dom.BODY_TAG_NAME) {
break;
}
vParent = vParent.parentNode;
}
return true;
}
|