2 //\ overLIB Follow Scroll Plugin
3 //\ This file requires overLIB 4.00 or later.
5 //\ overLIB 4.00 - 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' || olInfo.simpleversion < 400) alert('overLIB 4.00 or later is required for the Follow Scroll Plugin.');
18 registerCommands('followscroll,followscrollrefresh');
22 // DEFAULT CONFIGURATION
23 // You don't have to change anything here if you don't want to. All of this can be
24 // changed on your html page or through an overLIB call.
26 // Default value for scroll is not to scroll (0)
27 if (typeof ol_followscroll=='undefined') var ol_followscroll=0;
28 if (typeof ol_followscrollrefresh=='undefined') var ol_followscrollrefresh=100;
31 // END OF CONFIGURATION
32 // Don't change anything below this line, all configuration is above.
44 // Runtime variables init. Don't change for config!
45 var o3_followscroll=0;
46 var o3_followscrollrefresh=100;
52 function setScrollVariables() {
53 o3_followscroll=ol_followscroll;
54 o3_followscrollrefresh=ol_followscrollrefresh;
57 // Parses Shadow and Scroll commands
58 function parseScrollExtras(pf,i,ar) {
61 if (ar[k]==FOLLOWSCROLL) { eval(pf +'followscroll=('+pf+'followscroll==0) ? 1 : 0'); return k; }
62 if (ar[k]==FOLLOWSCROLLREFRESH) { eval(pf+'followscrollrefresh='+ar[++k]); return k; }
69 // Function to support scroll feature (overloads default)
70 function scroll_placeLayer() {
71 var placeX, placeY, widthFix = 0;
72 var hasAnchor=(typeof o3_anchor != 'undefined' && o3_anchor);
74 // HORIZONTAL PLACEMENT
75 if (eval('o3_frame.'+docRoot) && eval("typeof o3_frame."+docRoot+".clientWidth=='number'") && eval('o3_frame.'+docRoot+'.clientWidth')) {
76 iwidth = eval('o3_frame.'+docRoot+'.clientWidth');
77 } else if (typeof(o3_frame.innerWidth) == 'number') {
78 widthFix = Math.ceil(1.2*(o3_frame.outerWidth - o3_frame.innerWidth));
79 iwidth = o3_frame.innerWidth;
83 placeX = rmrkPosition[0];
84 placeY = rmrkPosition[1];
86 // Horizontal scroll offset
87 winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
88 var parsedWidth = parseInt(o3_width);
90 if (o3_fixx > -1 || o3_relx != null) {
92 placeX=(o3_relx != null ? ( o3_relx < 0 ? winoffset +o3_relx+ iwidth - parsedWidth - widthFix : winoffset+o3_relx) : o3_fixx);
94 // If HAUTO, decide what to use.
96 if ((o3_x - winoffset) > (iwidth / 2)) {
104 if (o3_hpos == CENTER) { // Center
105 placeX = o3_x+o3_offsetx-(parsedWidth/2);
107 if (placeX < winoffset) placeX = winoffset;
110 if (o3_hpos == RIGHT) { // Right
111 placeX = o3_x+o3_offsetx;
113 if ((placeX+parsedWidth) > (winoffset+iwidth - widthFix)) {
114 placeX = iwidth+winoffset - parsedWidth - widthFix;
115 if (placeX < 0) placeX = 0;
118 if (o3_hpos == LEFT) { // Left
119 placeX = o3_x-o3_offsetx-parsedWidth;
120 if (placeX < winoffset) placeX = winoffset;
125 var snapping = placeX % o3_snapx;
127 if (o3_hpos == LEFT) {
128 placeX = placeX - (o3_snapx+snapping);
131 placeX = placeX+(o3_snapx - snapping);
134 if (placeX < winoffset) placeX = winoffset;
138 // VERTICAL PLACEMENT
139 if (eval('o3_frame.'+docRoot) && eval("typeof o3_frame."+docRoot+".clientHeight=='number'") && eval('o3_frame.'+docRoot+'.clientHeight')) {
140 iheight = eval('o3_frame.'+docRoot+'.clientHeight');
141 } else if (typeof(o3_frame.innerHeight)=='number') {
142 iheight = o3_frame.innerHeight;
145 // Vertical scroll offset
146 scrolloffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
147 var parsedHeight=(o3_aboveheight ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight));
149 if (o3_fixy > -1 || o3_rely != null) {
151 placeY=(o3_rely != null ? (o3_rely < 0 ? scrolloffset+o3_rely+iheight - parsedHeight : scrolloffset+o3_rely) : o3_fixy);
153 // If VAUTO, decide what to use.
155 if ((o3_y - scrolloffset) > (iheight/2)) {
163 if (o3_vpos == ABOVE) {
164 if (o3_aboveheight == 0) o3_aboveheight = parsedHeight;
166 placeY = o3_y - (o3_aboveheight+o3_offsety);
167 if (placeY < scrolloffset) placeY = scrolloffset;
170 placeY = o3_y+o3_offsety;
175 var snapping = placeY % o3_snapy;
177 if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
178 placeY = placeY - (o3_snapy+snapping);
180 placeY = placeY+(o3_snapy - snapping);
183 if (placeY < scrolloffset) placeY = scrolloffset;
188 // Actually move the object.
189 repositionTo(over,placeX,placeY);
191 if (o3_followscroll && o3_sticky && (o3_relx || o3_rely) && (typeof o3_draggable == 'undefined' || !o3_draggable)) {
192 if (typeof over.scroller=='undefined' || over.scroller.canScroll) over.scroller = new Scroller(placeX-winoffset,placeY-scrolloffset,o3_followscrollrefresh);
199 // SUPPORT ROUTINES FOR SCROLL FEATURE
202 // Scroller constructor
203 function Scroller(X,Y,refresh) {
205 this.refresh=refresh;
208 this.timer=setTimeout("repositionOver()",this.refresh);
211 // Removes the timer to stop replacing the layer.
212 function cancelScroll() {
213 if (!o3_followscroll || typeof over.scroller == 'undefined') return;
214 over.scroller.canScroll = 1;
216 if (over.scroller.timer) {
217 clearTimeout(over.scroller.timer);
218 over.scroller.timer=null;
222 // Find out how much we've scrolled.
223 function getPageScrollY() {
224 if (o3_frame.pageYOffset) return o3_frame.pageYOffset;
225 if (eval(docRoot)) return eval('o3_frame.' + docRoot + '.scrollTop');
228 function getPageScrollX() {
229 if (o3_frame.pageXOffset) return o3_frame.pageXOffset;
230 if (eval(docRoot)) return eval('o3_frame.'+docRoot+'.scrollLeft');
234 // Find out where our layer is
235 function getLayerTop(layer) {
236 if (layer.pageY) return layer.pageY;
237 if (layer.style.top) return parseInt(layer.style.top);
240 function getLayerLeft(layer) {
241 if (layer.pageX) return layer.pageX;
242 if (layer.style.left) return parseInt(layer.style.left);
246 // Repositions the layer if needed
247 function repositionOver() {
248 var X, Y, pgLeft, pgTop;
249 pgTop = getPageScrollY();
250 pgLeft = getPageScrollX();
251 X = getLayerLeft(over)-pgLeft;
252 Y = getLayerTop(over)-pgTop;
254 if (X != over.scroller.x || Y != over.scroller.y) repositionTo(over, pgLeft+over.scroller.x, pgTop+over.scroller.y);
255 over.scroller.timer = setTimeout("repositionOver()", over.scroller.refresh);
259 // PLUGIN REGISTRATIONS
261 registerRunTimeFunction(setScrollVariables);
262 registerCmdLineFunction(parseScrollExtras);
263 registerHook("hideObject",cancelScroll,FAFTER);
264 registerHook("placeLayer",scroll_placeLayer,FREPLACE);