Cleanup on ancient JS file that's awful anyway
[lhc/web/wiklou.git] / skins / common / sticky.js
1 // Make a layer that stays in the same place on screen when scrolling the browser window.
2 // Version 1.2
3 // See http://www.mark.ac/help for browser support.
4
5 var mySticky;
6 var theLayer;
7
8 // Setup variables for sliding.
9 // lastY and staticYOffset should match your CSS top definition.
10
11 lastY = 10;
12 YOffset = 0;
13 staticYOffset = 10;
14 refreshMS = 25;
15
16 // Setup function that runs when the page loads.
17 function setup( eID ) {
18 bw = new checkBrowser;
19 if ( bw.ns4 || bw.opera ) { MM_reloadPage( true ); }
20 var noFix = bw.ie4 || bw.ns4 || ( bw.macie50 ) ? true : false;
21 if ( window.attachEvent ) { fix_bind() }
22 else if ( noFix ) {
23 if ( bw.ns6 ) { document.getElementById( eID ).style.position = "absolute"; }
24 if ( bw.macie50 ) { document.getElementById( eID ).style.position = "absolute"; document.getElementById( eID ).style.backgroundColor = "#ccffcc"; }
25 if ( bw.ns6 && YOffset == 0 ) { YOffset = -15 }
26 mySticky = new makeLayerObj( eID );
27 layerSlide( eID ) }
28 else {
29 mySticky = new makeLayerObj( eID );
30 mySticky.css.position = "fixed"; }
31
32 if ( !mySticky ) { mySticky = new makeLayerObj( eID ); }
33 // mySticky.css.visibility = "visible";
34 }
35
36 hookEvent( 'load', function() { setup( 'quickbar' ); } );
37
38
39 // -------------------------
40 // emulate css 'position: fixed' in IE5+ Win
41 // code by aclover@1value.com
42 fix_elements = new Array();
43
44 function fix_event() {
45 var i;
46 for ( i = 0; i < fix_elements.length; i++ ) {
47 fix_elements[i].style.left = parseInt( fix_elements[i].fix_left ) + document.getElementsByTagName( 'html' )[0].scrollLeft + document.getElementsByTagName( 'body' )[0].scrollLeft + 'px';
48 fix_elements[i].style.top = parseInt( fix_elements[i].fix_top ) + document.getElementsByTagName( 'html' )[0].scrollTop + document.getElementsByTagName( 'body' )[0].scrollTop + 'px';
49 }
50 }
51
52 function fix_bind() {
53 var i;
54 for ( i = 0; i < document.all.length; i++ ) {
55 if ( document.all[i].currentStyle.position == 'fixed' ) {
56 document.all[i].fix_left = document.all[i].currentStyle.left;
57 document.all[i].fix_top = document.all[i].currentStyle.top;
58 document.all[i].style.position = 'absolute';
59 fix_elements[fix_elements.length] = document.all[i];
60 window.attachEvent( 'onscroll', fix_event );
61 window.attachEvent( 'onresize', fix_event );
62 }
63 }
64 }
65 // -------------------------
66
67
68 // -------------------------
69 // DHTML menu sliding. Requires checkBrowser()
70 // Based on source at http://www.simplythebest.net/
71 function layerSlide( layerID ) {
72 if ( bw.dhtml ) {
73 if ( !mySticky ) { mySticky = new makeLayerObj( layerID ); }
74 if ( bw.ns ) { winY = window.pageYOffset; }
75 else if ( bw.ie ) { winY = document.body.scrollTop; }
76 if ( bw.ie || bw.ns ) {
77 if ( winY != lastY && winY > YOffset - staticYOffset ) { smooth = .3 * ( winY - lastY - YOffset + staticYOffset ); }
78 else if ( YOffset - staticYOffset + lastY > YOffset - staticYOffset ) { smooth = .3 * ( winY - lastY - ( YOffset - ( YOffset - winY ) ) ); }
79 else { smooth = 0 }
80 if ( smooth > 0 ) { smooth = Math.ceil( smooth ); }
81 else { smooth = Math.floor( smooth ); }
82 if ( bw.ie ) { mySticky.css.pixelTop += smooth; }
83 else if ( bw.ns ) { mySticky.css.top = parseInt( mySticky.css.top ) + smooth; }
84 lastY = lastY + smooth;
85 top.window.status = new Date()
86 setTimeout( 'layerSlide( "' + layerID + '")', refreshMS ) } } }
87 // -------------------------
88
89 // Netscape 4.x browser resize fix
90 function MM_reloadPage( init ) {
91 if ( init == true ) with ( navigator ) { if ( ( appName == "Netscape" ) && ( parseInt( appVersion ) == 4 ) ) {
92 document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; top.onresize = MM_reloadPage; } }
93 else if ( innerWidth != document.MM_pgW || innerHeight != document.MM_pgH ) { location.reload(); } }
94
95 // Create browser-independent layer and browser objects
96 function makeLayerObj( eID ) {
97 if ( document.getElementById ) { this.css = document.getElementById( eID ).style }
98 else if ( document.layers ) { this.css = document.layers[eID]; }
99 else if ( document.all ) { this.css = document.all[eID].style; }
100 return this;
101 }
102
103 function checkBrowser() {
104 this.ver = navigator.appVersion;
105 this.name = navigator.appName;
106 this.mac = ( navigator.platform.toLowerCase().indexOf( 'mac' ) > -1 );
107 this.opera = ( navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1 );
108 this.dom = document.getElementById;
109 this.ns = ( this.name == 'Netscape' );
110 this.ie4 = ( document.all && !this.dom );
111 this.ie = ( this.name == 'Microsoft Internet Explorer' && !this.opera );
112 this.ie5 = ( this.ie && ( navigator.userAgent.indexOf( "MSIE 5" ) != -1 ) );
113 this.macie50 = ( this.mac && this.ie5 && ( navigator.userAgent.indexOf( "MSIE 5.0" ) != -1 ) );
114 this.ns4 = ( this.ns && parseInt( this.ver ) == 4 );
115 this.ns6 = ( ( this.name == "Netscape" ) && ( parseInt( this.ver ) == 5 ) );
116 this.standards = document.getElementById;
117 this.dhtml = this.standards || this.ie4 || this.ns4;
118 }
119
120 function showMe( eID ) {
121 myFloater = new makeLayerObj( eID );
122 myFloater.css.visibility = "visible";
123 }
124
125 function hideMe( eID ) {
126 myFloater = new makeLayerObj( eID );
127 myFloater.css.visibility = "hidden";
128 }