scrollbutton_wev8.js
3.38 KB
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
//<script>
/*
* ScrollButton
*
* This script was designed for use with DHTML Menu 4
*
* This script was created by Erik Arvidsson
* (http://webfx.eae.net/contact.html#erik)
* for WebFX (http://webfx.eae.net)
* Copyright 2002
*
* For usage see license at http://webfx.eae.net/license.html
*
* Version: 1.02
* Created: 2002-05-28
* Updated: ??? Memory management updates
* 2003-09-23 Changed to using onunload instead onbeforeunload
*
*/
////////////////////////////////////////////////////////////////////////////////////
// scroolButtonCache
//
var scrollButtonCache = {
_count: 0,
_idPrefix: "-scroll-button-cache-",
getId: function () {
return this._idPrefix + this._count++;
},
remove: function ( o ) {
delete this[ o.id ];
}
};
function ScrollButton( oEl, oScrollContainer, nDir ) {
this.htmlElement = oEl;
this.scrollContainer = oScrollContainer;
this.dir = nDir;
this.id = scrollButtonCache.getId();
scrollButtonCache[ this.id ] = this;
this.makeEventListeners();
this.attachEvents();
}
ScrollButton.scrollIntervalPause = 100;
ScrollButton.scrollAmount = 18;
ScrollButton.prototype.startScroll = function () {
this._interval = window.setInterval(
"ScrollButton.eventListeners.oninterval(\"" + this.id + "\")",
ScrollButton.scrollIntervalPause );
};
ScrollButton.prototype.endScroll = function () {
if ( this._interval != null ) {
window.clearInterval( this._interval );
delete this._interval;
}
};
ScrollButton.prototype.makeEventListeners = function () {
if ( this.eventListeners != null )
return;
this.eventListeners = {
onmouseover: new Function( "ScrollButton.eventListeners.onmouseover(\"" + this.id + "\")" ),
onmouseout: new Function( "ScrollButton.eventListeners.onmouseout(\"" + this.id + "\")" ),
onunload: new Function( "ScrollButton.eventListeners.onunload(\"" + this.id + "\")" )
};
};
ScrollButton.prototype.attachEvents = function () {
if ( this.eventListeners == null )
return;
this.htmlElement.attachEvent( "onmouseover", this.eventListeners.onmouseover );
this.htmlElement.attachEvent( "onmouseout", this.eventListeners.onmouseout );
window.attachEvent( "onunload", this.eventListeners.onunload );
};
ScrollButton.prototype.detachEvents = function () {
if ( this.eventListeners == null )
return;
this.htmlElement.detachEvent( "onmouseover", this.eventListeners.onmouseover );
this.htmlElement.detachEvent( "onmouseout", this.eventListeners.onmouseout );
window.detachEvent( "onunload", this.eventListeners.onunload );
};
ScrollButton.prototype.destroy = function () {
this.endScroll();
this.detachEvents();
this.htmlElement = null;
this.scrollContainer = null;
this.eventListeners = null;
scrollButtonCache.remove( this );
};
ScrollButton.eventListeners = {
onmouseover: function ( id ) {
scrollButtonCache[id].startScroll();
},
onmouseout: function ( id ) {
scrollButtonCache[id].endScroll();
},
oninterval: function ( id ) {
var oThis = scrollButtonCache[id];
switch ( oThis.dir ) {
case 8:
oThis.scrollContainer.scrollTop -= ScrollButton.scrollAmount;
break;
case 2:
oThis.scrollContainer.scrollTop += ScrollButton.scrollAmount;
break;
case 4:
oThis.scrollContainer.scrollLeft -= ScrollButton.scrollAmount;
break;
case 6:
oThis.scrollContainer.scrollLeft += ScrollButton.scrollAmount;
break;
}
},
onunload: function ( id ) {
scrollButtonCache[id].destroy();
}
};