2 //\ overLIB Follow Scroll Plugin
3 //\ This file requires overLIB 4.10 or later.
5 //\ overLIB 4.10 - You may not remove or change this notice.
6 //\ Copyright Erik Bosrup 1998-2004. All rights reserved.
7 //\ Contributors are listed on the homepage.
8 //\ See http://www.bosrup.com/web/overlib/ for details.
15 // Ignore these lines, configuration is below.
17 if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Follow Scroll Plugin.');
19 registerCommands('followscroll,followscrollrefresh');
23 // DEFAULT CONFIGURATION
24 // You don't have to change anything here if you don't want to. All of this can be
25 // changed on your html page or through an overLIB call.
27 // Default value for scroll is not to scroll (0)
28 if (typeof ol_followscroll=='undefined') var ol_followscroll=0;
29 if (typeof ol_followscrollrefresh=='undefined') var ol_followscrollrefresh=100;
32 // END OF CONFIGURATION
33 // Don't change anything below this line, all configuration is above.
45 // Runtime variables init. Don't change for config!
46 var o3_followscroll=0;
47 var o3_followscrollrefresh=100;
53 function setScrollVariables() {
54 o3_followscroll=ol_followscroll;
55 o3_followscrollrefresh=ol_followscrollrefresh;
58 // Parses Shadow and Scroll commands
59 function parseScrollExtras(pf,i,ar) {
62 if (ar[k]==FOLLOWSCROLL) { eval(pf +'followscroll=('+pf+'followscroll==0) ? 1 : 0'); return k; }
63 if (ar[k]==FOLLOWSCROLLREFRESH) { eval(pf+'followscrollrefresh='+ar[++k]); return k; }
70 // Function to support scroll feature (overloads default)
71 function scroll_placeLayer() {
72 var placeX, placeY, widthFix = 0;
74 // HORIZONTAL PLACEMENT
75 if (o3_frame.innerWidth) {
76 widthFix=Math.ceil(1.2*(o3_frame.outerWidth - o3_frame.innerWidth));
77 widthFix = (widthFix > 50) ? 20 : widthFix;
78 iwidth=o3_frame.innerWidth;
79 } else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientWidth=='number'")&&eval('o3_frame.'+docRoot+'.clientWidth'))
80 iwidth=eval('o3_frame.'+docRoot+'.clientWidth');
82 // Horizontal scroll offset
83 winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
85 placeX = runHook('horizontalPlacement',FCHAIN,iwidth,winoffset,widthFix);
88 if (o3_frame.innerHeight) iheight=o3_frame.innerHeight;
89 else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientHeight=='number'")&&eval('o3_frame.'+docRoot+'.clientHeight'))
90 iheight=eval('o3_frame.'+docRoot+'.clientHeight');
92 // Vertical scroll offset
93 scrolloffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
95 placeY = runHook('verticalPlacement',FCHAIN,iheight,scrolloffset);
97 // Actually move the object.
98 repositionTo(over,placeX,placeY);
100 if (o3_followscroll && o3_sticky && (o3_relx || o3_rely) && (typeof o3_draggable == 'undefined' || !o3_draggable)) {
101 if (typeof over.scroller=='undefined' || over.scroller.canScroll) over.scroller = new Scroller(placeX-winoffset,placeY-scrolloffset,o3_followscrollrefresh);
108 // SUPPORT ROUTINES FOR SCROLL FEATURE
111 // Scroller constructor
112 function Scroller(X,Y,refresh) {
114 this.refresh=refresh;
117 this.timer=setTimeout("repositionOver()",this.refresh);
120 // Removes the timer to stop replacing the layer.
121 function cancelScroll() {
122 if (!o3_followscroll || typeof over.scroller == 'undefined') return;
123 over.scroller.canScroll = 1;
125 if (over.scroller.timer) {
126 clearTimeout(over.scroller.timer);
127 over.scroller.timer=null;
131 // Find out how much we've scrolled.
132 function getPageScrollY() {
133 if (o3_frame.pageYOffset) return o3_frame.pageYOffset;
134 if (eval(docRoot)) return eval('o3_frame.' + docRoot + '.scrollTop');
137 function getPageScrollX() {
138 if (o3_frame.pageXOffset) return o3_frame.pageXOffset;
139 if (eval(docRoot)) return eval('o3_frame.'+docRoot+'.scrollLeft');
143 // Find out where our layer is
144 function getLayerTop(layer) {
145 if (layer.pageY) return layer.pageY;
146 if (layer.style.top) return parseInt(layer.style.top);
149 function getLayerLeft(layer) {
150 if (layer.pageX) return layer.pageX;
151 if (layer.style.left) return parseInt(layer.style.left);
155 // Repositions the layer if needed
156 function repositionOver() {
157 var X, Y, pgLeft, pgTop;
158 pgTop = getPageScrollY();
159 pgLeft = getPageScrollX();
160 X = getLayerLeft(over)-pgLeft;
161 Y = getLayerTop(over)-pgTop;
163 if (X != over.scroller.x || Y != over.scroller.y) repositionTo(over, pgLeft+over.scroller.x, pgTop+over.scroller.y);
164 over.scroller.timer = setTimeout("repositionOver()", over.scroller.refresh);
168 // PLUGIN REGISTRATIONS
170 registerRunTimeFunction(setScrollVariables);
171 registerCmdLineFunction(parseScrollExtras);
172 registerHook("hideObject",cancelScroll,FAFTER);
173 registerHook("placeLayer",scroll_placeLayer,FREPLACE);
174 if (olInfo.meets(4.10)) registerNoParameterCommands('followscroll');