Fixes to the PaintWeb cron task.
[moodle/mihaisucan.git] / lib / overlib / overlib_followscroll.js
blob6f007d82f1f28d5f5898564cd073edd2f51a1bbe
1 //\/////
2 //\  overLIB Follow Scroll Plugin
3 //\  This file requires overLIB 4.10 or later.
4 //\
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.
9 //   $Revision$                      $Date$
10 //\/////
11 //\mini
13 ////////
14 // PRE-INIT
15 // Ignore these lines, configuration is below.
16 ////////
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.');
18 else {
19 registerCommands('followscroll,followscrollrefresh');
22 ////////
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.
26 ////////
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;
31 ////////
32 // END OF CONFIGURATION
33 // Don't change anything below this line, all configuration is above.
34 ////////
42 ////////
43 // INIT
44 ////////
45 // Runtime variables init. Don't change for config!
46 var o3_followscroll=0;
47 var o3_followscrollrefresh=100;
50 ////////
51 // PLUGIN FUNCTIONS
52 ////////
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) {
60         var k=i,v;
61         if (k < ar.length) {
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; }
64         }
65         return -1;
70 // Function to support scroll feature (overloads default)
71 function scroll_placeLayer() {
72         var placeX, placeY, widthFix = 0;
73         
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);
86         
87         // VERTICAL PLACEMENT
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);
99         
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);
102         }
107 ///////
108 // SUPPORT ROUTINES FOR SCROLL FEATURE
109 ///////
111 // Scroller constructor
112 function Scroller(X,Y,refresh) {
113         this.canScroll=0;
114         this.refresh=refresh;
115         this.x=X;
116         this.y=Y;
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;
124         
125         if (over.scroller.timer) {
126                 clearTimeout(over.scroller.timer);
127                 over.scroller.timer=null;
128         }
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');
135         return -1;
137 function getPageScrollX() {
138         if (o3_frame.pageXOffset) return o3_frame.pageXOffset;
139         if (eval(docRoot)) return eval('o3_frame.'+docRoot+'.scrollLeft');
140         return -1;
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);
147         return -1;
149 function getLayerLeft(layer) {
150         if (layer.pageX) return layer.pageX;
151         if (layer.style.left) return parseInt(layer.style.left);
152         return -1;
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;
162         
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);
167 ////////
168 // PLUGIN REGISTRATIONS
169 ////////
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');