2
* Copyright 2008 Stefan Buller <hikingpete@cain.afraid.org>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) version 3, or any
8
* later version accepted by the membership of KDE e.V. (or its
9
* successor approved by the membership of KDE e.V.), which shall
10
* act as a proxy defined in Section 6 of version 3 of the license.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
21
function AppleScrollArea(content) {
22
for (var i = 0; i < arguments.length; i++) {
23
this.addScrollbar(arguments[i]);
26
var handler=function(e) {
29
that.horizontalScrollTo(that.content.scrollLeft -
30
that.singlepressScrollPixels);
33
that.verticalScrollTo(that.content.scrollTop -
34
that.singlepressScrollPixels);
37
that.horizontalScrollTo(that.content.scrollLeft +
38
that.singlepressScrollPixels);
41
that.verticalScrollTo(that.content.scrollTop +
42
that.singlepressScrollPixels);
45
//the event may contiue to propagate
51
content.addEventListener('keydown',handler,false);
53
//Apple mandated properties that must be reacted to.
54
this.scrollsVertically = false;
55
this.scrollsHorizontally = false;
56
this.singlepressScrollPixels = 10; //Somebody change this. Please.
58
//Apple mandated properties that are `read only'.
59
this.viewHeight = content.clientHeight;
60
this.viewToContentHeightRatio = content.clientHeight / content.scrollHeight;
61
this.viewWidth = content.clientWidth;
62
this.viewToContentWidthRatio = content.clientWidth / content.scrollWidth;
63
//I'm worried that the scrollHeight/Width could change on me. If that turns
64
//out to be a problem, then getters would be the way to go.
68
this.content = content;
71
AppleScrollArea.prototype.addScrollbar = function(scrollbar) {
72
this.scrollbars.push(scrollbar);
73
scrollbar.setScrollArea(this);
76
AppleScrollArea.prototype.removeScrollbar = function(scrollbar) {
77
this.scrollbars.filter(function(element){return (element === scrollbar);});
78
scrollbar.setScrollArea(null); //Just a guess. This might not be right.
81
AppleScrollArea.prototype.remove = function() {
82
//Remove the div, or remove the effects of AppleScrollArea?
83
//Perhaps this can all be replaced with a simple removeChild()
84
content.scrollTop = 0;
85
content.scrollLeft = 0;
86
for (var i = 0; i < this.scrollbars.length; i++) {
87
this.scrollbars[i].remove();
88
delete this.scrollbars[i];
93
AppleScrollArea.prototype.reveal = function(element) {
98
while (el !== this.content) {
99
distX += (+el.offsetTop);
100
distY += (+el.offsetLeft);
103
throw "Target element not in ScrollArea.";
107
this.verticalScrollTo(distY);
108
this.horizontalScrollTo(distX);
111
AppleScrollArea.prototype.focus = function() {
112
this.content.focus();
115
AppleScrollArea.prototype.blur = function() {
119
AppleScrollArea.prototype.verticalScrollTo = function(position) {
120
this.scrollTop = position;
123
AppleScrollArea.prototype.horizontalScrollTo = function(position) {
124
this.scrollLeft = position;