]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/js/overlib_followscroll.js
commit changes
[bacula/bacula] / gui / bacula-web / js / overlib_followscroll.js
1 //\/////
2 //\  overLIB Follow Scroll Plugin
3 //\  This file requires overLIB 4.00 or later.
4 //\
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.
9 //   $Revision$                      $Date$
10 //\/////
11
12
13 ////////
14 // PRE-INIT
15 // Ignore these lines, configuration is below.
16 ////////
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');
19
20
21 ////////
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.
25 ////////
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;
29
30 ////////
31 // END OF CONFIGURATION
32 // Don't change anything below this line, all configuration is above.
33 ////////
34
35
36
37
38
39
40
41 ////////
42 // INIT
43 ////////
44 // Runtime variables init. Don't change for config!
45 var o3_followscroll=0;
46 var o3_followscrollrefresh=100;
47
48
49 ////////
50 // PLUGIN FUNCTIONS
51 ////////
52 function setScrollVariables() {
53         o3_followscroll=ol_followscroll;
54         o3_followscrollrefresh=ol_followscrollrefresh;
55 }
56
57 // Parses Shadow and Scroll commands
58 function parseScrollExtras(pf,i,ar) {
59         var k=i,v;
60         if (k < ar.length) {
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; }
63         }
64         return -1;
65 }
66
67
68
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);
73         
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;
80         }
81
82         if (hasAnchor) {
83                 placeX = rmrkPosition[0];
84                 placeY = rmrkPosition[1];
85         } else {        
86                 // Horizontal scroll offset
87                 winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
88                 var parsedWidth = parseInt(o3_width);
89         
90                 if (o3_fixx > -1 || o3_relx != null) {
91                         // Fixed position
92                         placeX=(o3_relx != null ? ( o3_relx < 0 ? winoffset +o3_relx+ iwidth - parsedWidth - widthFix : winoffset+o3_relx) : o3_fixx);
93                 } else {  
94                         // If HAUTO, decide what to use.
95                         if (o3_hauto == 1) {
96                                 if ((o3_x - winoffset) > (iwidth / 2)) {
97                                         o3_hpos = LEFT;
98                                 } else {
99                                         o3_hpos = RIGHT;
100                                 }
101                         }               
102         
103                         // From mouse
104                         if (o3_hpos == CENTER) { // Center
105                                 placeX = o3_x+o3_offsetx-(parsedWidth/2);
106         
107                                 if (placeX < winoffset) placeX = winoffset;
108                         }
109         
110                         if (o3_hpos == RIGHT) { // Right
111                                 placeX = o3_x+o3_offsetx;
112         
113                                 if ((placeX+parsedWidth) > (winoffset+iwidth - widthFix)) {
114                                         placeX = iwidth+winoffset - parsedWidth - widthFix;
115                                         if (placeX < 0) placeX = 0;
116                                 }
117                         }
118                         if (o3_hpos == LEFT) { // Left
119                                 placeX = o3_x-o3_offsetx-parsedWidth;
120                                 if (placeX < winoffset) placeX = winoffset;
121                         }       
122         
123                         // Snapping!
124                         if (o3_snapx > 1) {
125                                 var snapping = placeX % o3_snapx;
126         
127                                 if (o3_hpos == LEFT) {
128                                         placeX = placeX - (o3_snapx+snapping);
129                                 } else {
130                                         // CENTER and RIGHT
131                                         placeX = placeX+(o3_snapx - snapping);
132                                 }
133         
134                                 if (placeX < winoffset) placeX = winoffset;
135                         }
136                 }       
137         
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;
143                 }
144         
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));
148         
149                 if (o3_fixy > -1 || o3_rely != null) {
150                         // Fixed position
151                         placeY=(o3_rely != null ? (o3_rely < 0 ? scrolloffset+o3_rely+iheight - parsedHeight : scrolloffset+o3_rely) : o3_fixy);
152                 } else {
153                         // If VAUTO, decide what to use.
154                         if (o3_vauto == 1) {  
155                                 if ((o3_y - scrolloffset) > (iheight/2)) {
156                                         o3_vpos = ABOVE;
157                                 } else {
158                                         o3_vpos = BELOW;
159                                 }
160                         }
161         
162                         // From mouse
163                         if (o3_vpos == ABOVE) {
164                                 if (o3_aboveheight == 0) o3_aboveheight = parsedHeight; 
165         
166                                 placeY = o3_y - (o3_aboveheight+o3_offsety);
167                                 if (placeY < scrolloffset) placeY = scrolloffset;
168                         } else {
169                                 // BELOW
170                                 placeY = o3_y+o3_offsety;
171                         } 
172         
173                         // Snapping!
174                         if (o3_snapy > 1) {
175                                 var snapping = placeY % o3_snapy;                       
176         
177                                 if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
178                                         placeY = placeY - (o3_snapy+snapping);
179                                 } else {
180                                         placeY = placeY+(o3_snapy - snapping);
181                                 }                       
182         
183                                 if (placeY < scrolloffset) placeY = scrolloffset;
184                         }
185                 }
186         }
187
188         // Actually move the object.
189         repositionTo(over,placeX,placeY);
190         
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);
193         }
194 }
195
196
197
198 ///////
199 // SUPPORT ROUTINES FOR SCROLL FEATURE
200 ///////
201
202 // Scroller constructor
203 function Scroller(X,Y,refresh) {
204         this.canScroll=0;
205         this.refresh=refresh;
206         this.x=X;
207         this.y=Y;
208         this.timer=setTimeout("repositionOver()",this.refresh);
209 }
210
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;
215         
216         if (over.scroller.timer) {
217                 clearTimeout(over.scroller.timer);
218                 over.scroller.timer=null;
219         }
220 }
221
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');
226         return -1;
227 }
228 function getPageScrollX() {
229         if (o3_frame.pageXOffset) return o3_frame.pageXOffset;
230         if (eval(docRoot)) return eval('o3_frame.'+docRoot+'.scrollLeft');
231         return -1;
232 }
233
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);
238         return -1;
239 }
240 function getLayerLeft(layer) {
241         if (layer.pageX) return layer.pageX;
242         if (layer.style.left) return parseInt(layer.style.left);
243         return -1;
244 }
245
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;
253         
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);
256 }
257
258 ////////
259 // PLUGIN REGISTRATIONS
260 ////////
261 registerRunTimeFunction(setScrollVariables);
262 registerCmdLineFunction(parseScrollExtras);
263 registerHook("hideObject",cancelScroll,FAFTER);
264 registerHook("placeLayer",scroll_placeLayer,FREPLACE);
265 //end